function logFailedMail($user, $correspondence) { $message = "Correspondence email failed to be delivered - "; $message .= $correspondence; $message .= " - sent to "; $message .= formatUserName($user); logInfoEvent($message); }
function getUserName($ID, $link = 0) { global $DB, $CFG_GLPI; $user = ""; if ($link == 2) { $user = array("name" => "", "link" => "", "comment" => ""); } if ($ID) { $query = "SELECT *\n FROM `glpi_users`\n WHERE `id` = '{$ID}'"; $result = $DB->query($query); if ($link == 2) { $user = array("name" => "", "comment" => "", "link" => ""); } if ($DB->numrows($result) == 1) { $data = $DB->fetch_assoc($result); $username = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], $link); if ($link == 2) { $user["name"] = $username; $user["link"] = $CFG_GLPI["root_doc"] . "/front/user.form.php?id=" . $ID; $user['comment'] = ''; $comments = array(); $comments[] = array('name' => __('Name'), 'value' => $username); $comments[] = array('name' => __('Login'), 'value' => $data["name"]); $email = UserEmail::getDefaultForUser($ID); if (!empty($email)) { $comments[] = array('name' => __('Email'), 'value' => $email); } if (!empty($data["phone"])) { $comments[] = array('name' => __('Phone'), 'value' => $data["phone"]); } if (!empty($data["mobile"])) { $comments[] = array('name' => __('Mobile phone'), 'value' => $data["mobile"]); } if ($data["locations_id"] > 0) { $comments[] = array('name' => __('Location'), 'value' => Dropdown::getDropdownName("glpi_locations", $data["locations_id"])); } if ($data["usertitles_id"] > 0) { $comments[] = array('name' => _x('person', 'Title'), 'value' => Dropdown::getDropdownName("glpi_usertitles", $data["usertitles_id"])); } if ($data["usercategories_id"] > 0) { $comments[] = array('name' => __('Category'), 'value' => Dropdown::getDropdownName("glpi_usercategories", $data["usercategories_id"])); } if (count($comments)) { foreach ($comments as $data) { // Do not use SPAN here $user['comment'] .= sprintf(__('%1$s: %2$s') . "<br>", "<strong>" . $data['name'] . "</strong>", $data['value']); } } } else { $user = $username; } } } return $user; }
static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item) { global $DB, $CFG_GLPI; $ID = $item->getField('id'); $type = get_class($item); if (!Session::haveRight("reservation_central", "r")) { return; } $user = new User(); $ri = new ReservationItem(); $pdf->setColumnsSize(100); if ($ri->getFromDBbyItem($type, $ID)) { $now = $_SESSION["glpi_currenttime"]; $query = "SELECT *\n FROM `glpi_reservationitems`\n INNER JOIN `glpi_reservations`\n ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n WHERE `end` > '" . $now . "'\n AND `glpi_reservationitems`.`items_id` = '{$ID}'\n ORDER BY `begin`"; $result = $DB->query($query); $pdf->setColumnsSize(100); $pdf->displayTitle("<b>" . __('Current and future reservations') . "</b>"); if (!$DB->numrows($result)) { $pdf->displayLine("<b>" . __('No reservation') . "</b>"); } else { $pdf->setColumnsSize(14, 14, 26, 46); $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>'); while ($data = $DB->fetch_assoc($result)) { if ($user->getFromDB($data["users_id"])) { $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); } else { $name = "(" . $data["users_id"] . ")"; } $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"])); } } $query = "SELECT *\n FROM `glpi_reservationitems`\n INNER JOIN `glpi_reservations`\n ON (`glpi_reservations`.`reservationitems_id` = `glpi_reservationitems`.`id`)\n WHERE `end` <= '" . $now . "'\n AND `glpi_reservationitems`.`items_id` = '{$ID}'\n ORDER BY `begin`\n DESC"; $result = $DB->query($query); $pdf->setColumnsSize(100); $pdf->displayTitle("<b>" . __('Past reservations') . "</b>"); if (!$DB->numrows($result)) { $pdf->displayLine("<b>" . __('No reservation') . "</b>"); } else { $pdf->setColumnsSize(14, 14, 26, 46); $pdf->displayTitle('<i>' . __('Start date'), __('End date'), __('By'), __('Comments') . '</i>'); while ($data = $DB->fetch_assoc($result)) { if ($user->getFromDB($data["users_id"])) { $name = formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); } else { $name = "(" . $data["users_id"] . ")"; } $pdf->displayLine(Html::convDateTime($data["begin"]), Html::convDateTime($data["end"]), $name, str_replace(array("\r", "\n"), " ", $data["comment"])); } } } $pdf->displaySpace(); }
function sendUpdateHuntNotification($hunt) { $to = "3035039213@messaging.sprintpcs.com,help@piuteponds.org"; $from = "From: help@piuteponds.org \r\n"; $user = getCurrentUser(); $userName = formatUserName($user); $subject = "A hunt was updated"; $mesg = "A hunt was updated by " . $userName . ".\r\n"; if (mail($to, $subject, $mesg, $from)) { //echo "MAIL_SUCCESS"; } else { //echo "MAIL_FAIL"; } }
/** * Print a nice HTML head for help page * * @param $title title of the page * @param $url not used anymore. **/ function helpHeader($title, $url = '') { global $CFG_GLPI, $LANG, $HEADER_LOADED, $PLUGIN_HOOKS; // Print a nice HTML-head for help page if ($HEADER_LOADED) { return; } $HEADER_LOADED = true; includeCommonHtmlHeader($title); // Body echo "<body>"; // Main Headline echo "<div id='header'>"; echo "<div id='c_logo' >"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' accesskey='0' title=\"" . $LANG['central'][5] . "\"><span class='invisible'>Logo</span></a></div>"; // Les préférences + lien déconnexion echo "<div id='c_preference' >"; echo "<ul><li id='deconnexion'><a href='" . $CFG_GLPI["root_doc"] . "/logout.php' title=\"" . $LANG['central'][6] . "\">" . $LANG['central'][6] . "</a>"; // check user id : header used for display messages when session logout if (getLoginUserID()) { echo " ("; echo formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"], 0, 20); echo ")"; } echo "</li>\n"; echo "<li><a href='" . (empty($CFG_GLPI["helpdesk_doc_url"]) ? "http://glpi-project.org/help-helpdesk" : $CFG_GLPI["helpdesk_doc_url"]) . "' target='_blank' title=\"" . $LANG['central'][7] . "\"> " . $LANG['central'][7] . "</a></li>"; echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php' title=\"" . $LANG['Menu'][11] . "\">" . $LANG['Menu'][11] . "</a></li>\n"; echo "</ul>"; echo "<div class='sep'></div>"; echo "</div>"; //-- Le moteur de recherche -- echo "<div id='c_recherche'>"; echo "<div class='sep'></div>"; echo "</div>"; //-- Le menu principal -- echo "<div id='c_menu'>"; echo "<ul id='menu'>"; // Build the navigation-elements // Home echo "<li id='menu1'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' title=\"" . $LANG['job'][13] . "\" class='itemP'>" . $LANG['central'][5] . "</a>"; echo "</li>"; // Create ticket if (haveRight("create_ticket", "1")) { echo "<li id='menu2'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1' title=\"" . $LANG['profiles'][5] . "\" class='itemP'>" . $LANG['profiles'][5] . "</a>"; echo "</li>"; } // Suivi ticket if (haveRight("observe_ticket", "1")) { echo "<li id='menu2'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php' title=\"" . $LANG['title'][10] . "\" class='itemP'>" . $LANG['title'][28] . "</a>"; echo "</li>"; } // Reservation if (haveRight("reservation_helpdesk", "1")) { echo "<li id='menu3'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.php' title=\"" . $LANG['Menu'][17] . "\" class='itemP'>" . $LANG['Menu'][17] . "</a>"; echo "</li>"; } // FAQ if (haveRight("faq", "r")) { echo "<li id='menu4' >"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.faq.php' title=\"" . $LANG['knowbase'][1] . "\" class='itemP'>" . $LANG['Menu'][20] . "</a>"; echo "</li>"; } // PLUGINS $plugins = array(); if (isset($PLUGIN_HOOKS["helpdesk_menu_entry"]) && count($PLUGIN_HOOKS["helpdesk_menu_entry"])) { foreach ($PLUGIN_HOOKS["helpdesk_menu_entry"] as $plugin => $active) { if ($active) { $function = "plugin_version_{$plugin}"; if (function_exists($function)) { $plugins[$plugin] = $function(); } } } } if (isset($plugins) && count($plugins) > 0) { $list = array(); foreach ($plugins as $key => $val) { $list[$key] = $val["name"]; } asort($list); echo "<li id='menu5' onmouseover=\"javascript:menuAff('menu5','menu');\">"; echo "<a href='#' title=\"" . $LANG['common'][29] . "\" class='itemP'>" . $LANG['common'][29] . "</a>"; // default none echo "<ul class='ssmenu'>"; // list menu item foreach ($list as $key => $val) { $link = ""; if (is_string($PLUGIN_HOOKS["helpdesk_menu_entry"][$key])) { $link = $PLUGIN_HOOKS["helpdesk_menu_entry"][$key]; } echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/plugins/" . $key . $link . "'>" . $plugins[$key]["name"] . "</a></li>\n"; } echo "</ul></li>"; } echo "</ul>"; echo "<div class='sep'></div>"; echo "</div>"; // End navigation bar // End headline ///Le sous menu contextuel 1 echo "<div id='c_ssmenu1'> </div>"; // Le fil d ariane echo "<div id='c_ssmenu2'>"; echo "<ul>"; echo "<li><a href='#' title=''>" . $LANG['central'][5] . "></a></li>"; echo "<li> </li>"; if (haveRight('validate_ticket', 1)) { $opt = array(); $opt['reset'] = 'reset'; $opt['field'][0] = 55; // validation status $opt['searchtype'][0] = 'equals'; $opt['contains'][0] = 'waiting'; $opt['link'][0] = 'AND'; $opt['field'][1] = 59; // validation aprobator $opt['searchtype'][1] = 'equals'; $opt['contains'][1] = getLoginUserID(); $opt['link'][1] = 'AND'; $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . append_params($opt, '&'); $pic_validate = "<a href='{$url_validate}'><img title=\"" . $LANG['validation'][15] . "\" alt=\"" . $LANG['validation'][15] . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png'></a>"; echo "<li>{$pic_validate}</li>\n"; } echo "<li> </li>"; if (haveRight('create_ticket', 1) && strpos($_SERVER['PHP_SELF'], "ticket")) { echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/menu_add.png' title=\"" . $LANG['buttons'][8] . "\" alt=\"" . $LANG['buttons'][8] . "\"></a></li>"; } echo "<li> </li>"; /// Bookmark load echo "<li>"; echo "<a href='#' onClick=\"var w=window.open('" . $CFG_GLPI["root_doc"] . "/front/popup.php?popup=load_bookmark' ,'glpibookmarks', 'height=400, width=600, top=100," . "left=100, scrollbars=yes' );w.focus();\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/bookmark.png' title=\"" . $LANG['buttons'][52] . " " . $LANG['bookmark'][1] . "\" alt=\"" . $LANG['buttons'][52] . " " . $LANG['bookmark'][1] . "\">"; echo "</a></li>"; // check user id : header used for display messages when session logout if (getLoginUserID()) { showProfileSelecter($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php"); } echo "</ul></div>"; echo "</div>"; // fin header echo "<div id='page' >"; // call function callcron() every 5min callCron(); displayMessageAfterRedirect(); }
along with GLPI; along with Order. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- @package order @author the order plugin team @copyright Copyright (c) 2010-2015 Order plugin team @license GPLv2+ http://www.gnu.org/licenses/gpl.txt @link https://forge.indepnet.net/projects/order @link http://www.glpi-project.org/ @since 2009 ---------------------------------------------------------------------- */ if (strpos($_SERVER['PHP_SELF'], "dropdownSupplier.php")) { include "../../../inc/includes.php"; header("Content-Type: text/html; charset=UTF-8"); Html::header_nocache(); } Session::checkCentralAccess(); // Make a select box if (isset($_POST["suppliers_id"])) { // 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` = '{$_POST['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($_POST['fieldname'], $values); }
/** * Fonction permettant de dessiner le tableau des informations générales. */ function affiche_tableau($total, $items, $deviceType, $disposal = 0) { if ($total != 0) { /* en-tete */ $this->CellLabel(false, $this->largeur_grande_cell, Toolbox::decodeFromUtf8($deviceType)); $this->SetY($this->GetY() + $this->line_height); /* En tete tableau. */ $this->CellEnTeteTableau(false, 45, Toolbox::decodeFromUtf8(__('Name')), 1, 'C', 1); $this->CellEnTeteTableau(false, 35, Toolbox::decodeFromUtf8(__('Inventory number')), 1, 'C', 1); $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('Date of purchase')), 1, 'C', 1); if ($disposal != 1) { $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('User / Group', 'financialreports')), 1, 'C', 1); $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Location')), 1, 'C', 1); } $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Model')), 1, 'C', 1); $this->CellEnTeteTableau(false, 40, Toolbox::decodeFromUtf8(__('Supplier')), 1, 'C', 1); if ($disposal == 1) { $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('HT', 'financialreports')), 1, 'C', 1); $this->CellEnTeteTableau(false, 25, Toolbox::decodeFromUtf8(__('Disposal date', 'financialreports')), 1, 'C', 1); $this->CellEnTeteTableau(false, 55, Toolbox::decodeFromUtf8(__('Comments')), 1, 'C', 1); } else { $this->CellEnTeteTableau(false, 20, Toolbox::decodeFromUtf8(__('HT', 'financialreports')), 1, 'C', 1); } $this->SetY($this->GetY() + $this->line_height); /* ligne. */ $i = 1; foreach ($items as $data) { $i++; $this->SetFondBlanc(); if ($i % 2) { $this->SetFondTresClair(); } $this->CellLigneTableau(false, 45, $data["ITEM_0"]); $this->CellLigneTableau(false, 35, $data["ITEM_2"]); $this->CellLigneTableau(false, 20, Html::convdate($data["ITEM_3"]), 1, 'C', 1); $this->SetTextBleu(); $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8(formatUserName($data["ITEM_4_3"], $data["ITEM_4"], $data["ITEM_4_2"], $data["ITEM_4_4"]))); $this->SetTextNoir(); if ($disposal != 1) { $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_9"])); $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_6"])); } $this->CellLigneTableau(false, 40, Toolbox::decodeFromUtf8($data["ITEM_7"])); if ($disposal == 1) { $this->SetTextRouge(); $this->CellLigneTableau(false, 20, Html::clean(Html::formatNumber($data["ITEM_8"])), 1, 'R', 1); $this->SetTextNoir(); $this->CellLigneTableau(false, 25, Html::convdate($data["ITEM_10"]), 1, 'C', 1); $this->CellLigneTableau(false, 55, Toolbox::decodeFromUtf8($data["ITEM_9"])); } else { $this->SetTextRouge(); $this->CellLigneTableau(false, 20, Html::clean(Html::formatNumber($data["ITEM_8"])), 1, 'R', 1); $this->SetTextNoir(); } $this->SetY($this->GetY() + $this->line_height); } /* pied */ if ($total != -1) { $this->CellEnTeteTableau(true, $this->largeur_grande_cell - 20, Toolbox::decodeFromUtf8(__('Total')), 1, 'R', 1); $this->SetTextRouge(); $this->CellEnTeteTableau(false, 20, Html::clean(Html::formatNumber($total)), 1, 'R', 1); $this->SetTextNoir(); $this->SetY($this->GetY() + $this->line_height); } } }
/** * Display all the linked computers of a defined typology * *@param $typoID = typo ID. * *@return Nothing (displays) **/ public static function showForTypology(PluginTypologyTypology $typo) { global $DB, $CFG_GLPI; $typoID = $typo->fields['id']; if (!$typo->can($typoID, 'r')) { return false; } $canedit = $typo->can($typoID, 'w'); $canview = $typo->can($typoID, 'r'); $rand = mt_rand(); $query = "SELECT DISTINCT `itemtype`\n FROM `glpi_plugin_typology_typologies_items`\n WHERE `plugin_typology_typologies_id` = '{$typoID}'\n ORDER BY `itemtype`"; $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit) { echo "<div class='firstbloc'>"; echo "<form method='post' name='typologies_form{$rand}' id='typologies_form{$rand}' action='" . $CFG_GLPI["root_doc"] . "/plugins/typology/front/typology.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='7'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='4' class='center'>"; echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>"; Dropdown::showAllItems("items_id", 0, 0, $typo->fields['is_recursive'] ? -1 : $typo->fields['entities_id'], PluginTypologyTypology::getTypes()); echo "</td>"; echo "<td colspan='3' class='center' class='tab_bg_2'>"; echo "<input type='submit' name='add_item' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; echo "<th colspan='" . ($canedit ? 7 + $colsup : 6 + $colsup) . "'>"; if ($DB->numrows($result) == 0) { _e('No linked element', 'typology'); } else { _e('Linked elements', 'typology'); } echo "</th></tr><tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "<th>" . __('Responding to typology\'s criteria', 'typology') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } if ($canview) { $column = "name"; $itemtable = getTableForItemType($itemtype); $query = "SELECT `" . $itemtable . "`.*,\n `glpi_plugin_typology_typologies_items`.`id` AS IDP,\n `glpi_plugin_typology_typologies_items`.`is_validated`,\n `glpi_plugin_typology_typologies_items`.`error`,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_typology_typologies_items`, `" . $itemtable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemtable . "`.`entities_id`) " . " WHERE `" . $itemtable . "`.`id` = `glpi_plugin_typology_typologies_items`.`items_id`\n AND `glpi_plugin_typology_typologies_items`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_typology_typologies_items`.`plugin_typology_typologies_id` = '{$typoID}'"; if ($itemtype != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND " . $itemtable . ".is_template='0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemtable . "`.`{$column}` "; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemtype, PluginTypologyTypology::getTypeName(1) . " = " . $typo->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $ID = ""; $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemtype, $data["id"]); if ($itemtype == 'User') { $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); } else { $format = $data["name"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = Toolbox::getItemTypeFormURL($itemtype); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format; if ($itemtype != 'User') { $name .= " " . $ID; } $name .= "</a>"; echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["IDP"]); echo "</td>"; } echo "<input type='hidden' name='plugin_typology_typologies_id' value='{$typoID}'>"; echo "<td class='center'>" . $item->getTypeName() . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { if ($itemtype != 'User') { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } else { echo "<td class='center'>-</td>"; } } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; if ($data["is_validated"] > 0) { $critTypOK = __('Yes'); } else { $critTypOK = "<font color='red'>" . __('No') . " " . __('for the criteria', 'typology') . " "; $i = 0; $critTypOK .= self::displayErrors($data["error"]); $critTypOK .= "</font>"; } echo "<td class ='center'><b>" . $critTypOK . "</b></td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
/** * 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); }
/** * Show the User having a profile, in allowed Entity * * @param $prof Profile object **/ static function showForProfile(Profile $prof) { global $DB, $CFG_GLPI; $ID = $prof->fields['id']; $canedit = Session::haveRightsOr("user", array(CREATE, UPDATE, DELETE, PURGE)); $rand = mt_rand(); if (!$prof->can($ID, READ)) { return false; } $query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`entities_id` AS entity,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_dynamic`,\n `glpi_profiles_users`.`is_recursive`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id`=`glpi_profiles_users`.`entities_id`)\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`profiles_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", 'entities_id', $_SESSION['glpiactiveentities'], true) . "\n ORDER BY `glpi_entities`.`completename`"; $result = $DB->query($query); $nb = $DB->numrows($result); echo "<div class='spaced'>"; if ($canedit && $nb) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $nb, 'container' => 'mass' . __CLASS__ . $rand); Html::showMassiveActions($massiveactionparams); } echo "<table class='tab_cadre_fixe'><tr>"; echo "<th>" . sprintf(__('%1$s: %2$s'), __('Profile'), $prof->fields["name"]) . "</th></tr>\n"; echo "<tr><th colspan='2'>" . sprintf(__('%1$s (%2$s)'), _n('User', 'Users', Session::getPluralNumber()), __('D=Dynamic, R=Recursive')) . "</th></tr>"; echo "</table>\n"; echo "<table class='tab_cadre_fixe'>"; $i = 0; $nb_per_line = 3; $rand = mt_rand(); // Just to avoid IDE warning $canedit_entity = false; if ($nb) { $temp = -1; while ($data = $DB->fetch_assoc($result)) { if ($data["entity"] != $temp) { while ($i % $nb_per_line != 0) { if ($canedit_entity) { echo "<td width='10'> </td>"; } echo "<td class='tab_bg_1'> </td>\n"; $i++; } if ($i != 0) { echo "</table>"; echo "</div>"; echo "</td></tr>\n"; } // New entity $i = 0; $temp = $data["entity"]; $canedit_entity = $canedit && in_array($temp, $_SESSION['glpiactiveentities']); $rand = mt_rand(); echo "<tr class='tab_bg_2'>"; echo "<td>"; echo "<a href=\"javascript:showHideDiv('entity{$temp}{$rand}','imgcat{$temp}', '" . $CFG_GLPI['root_doc'] . "/pics/folder.png','" . $CFG_GLPI['root_doc'] . "/pics/folder-open.png');\">"; echo "<img alt='' name='imgcat{$temp}' src=\"" . $CFG_GLPI['root_doc'] . "/pics/folder.png\"> "; echo "<span class='b'>" . Dropdown::getDropdownName('glpi_entities', $data["entity"]) . "</span>"; echo "</a>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_2'><td>"; echo "<div class='center' id='entity{$temp}{$rand}' style='display:none;'>\n"; echo Html::checkAllAsCheckbox("entity{$temp}{$rand}") . __('All'); echo "<table class='tab_cadre_fixe'>\n"; } if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>\n"; } echo "<tr class='tab_bg_1'>\n"; $i = 0; } if ($canedit_entity) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]); echo "</td>"; } $username = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); if ($data["is_dynamic"] || $data["is_recursive"]) { $username = sprintf(__('%1$s %2$s'), $username, "<span class='b'>("); if ($data["is_dynamic"]) { $username = sprintf(__('%1$s%2$s'), $username, __('D')); } if ($data["is_dynamic"] && $data["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, ", "); } if ($data["is_recursive"]) { $username = sprintf(__('%1$s%2$s'), $username, __('R')); } $username = sprintf(__('%1$s%2$s'), $username, ")</span>"); } echo "<td class='tab_bg_1'>" . $username . "</td>\n"; $i++; } if ($i % $nb_per_line != 0) { while ($i % $nb_per_line != 0) { if ($canedit_entity) { echo "<td width='10'> </td>"; } echo "<td class='tab_bg_1'> </td>"; $i++; } } if ($i != 0) { echo "</table>"; echo "</div>"; echo "</td></tr>\n"; } } else { echo "<tr class='tab_bg_2'><td class='tab_bg_1 center'>" . __('No user found') . "</td></tr>\n"; } echo "</table>"; if ($canedit && $nb) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>\n"; }
function getSender($options = array()) { $mails = new UserEmail(); if (isset($_SESSION['glpiID']) && $_SESSION['glpiID'] > 0 && isset($_SESSION['glpilock_directunlock_notification']) && $_SESSION['glpilock_directunlock_notification'] > 0 && $mails->getFromDBByQuery(" WHERE users_id = " . $_SESSION['glpiID'] . "\n AND is_default = 1 ")) { $ret = array('email' => $mails->fields['email'], 'name' => formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"])); } else { $ret = parent::getSender($options); } return $ret; }
/** * Show items links to a resource * * @since version 0.84 * * @param $resource PluginResourcesResource object * * @return nothing (HTML display) **/ public static function showForResource(PluginResourcesResource $resource, $withtemplate = '') { global $DB, $CFG_GLPI; $instID = $resource->fields['id']; if (!$resource->can($instID, 'r')) { return false; } $rand = mt_rand(); $canedit = $resource->can($instID, 'w'); if (empty($withtemplate)) { $withtemplate = 0; } $types = PluginResourcesResource::getTypes(); $plugin = new Plugin(); if ($plugin->isActivated("badges")) { $types[] = 'PluginBadgesBadge'; } $query = "SELECT DISTINCT `itemtype` \n FROM `glpi_plugin_resources_resources_items` \n WHERE `plugin_resources_resources_id` = '{$instID}' \n ORDER BY `itemtype` \n LIMIT " . count($types); $result = $DB->query($query); $number = $DB->numrows($result); if (Session::isMultiEntitiesMode()) { $colsup = 1; } else { $colsup = 0; } if ($canedit && $withtemplate < 2 && $number < 1) { echo "<div class='firstbloc'>"; echo "<form method='post' name='resource_form{$rand}' id='resource_form{$rand}'\n action='" . Toolbox::getItemTypeFormURL("PluginResourcesResource") . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='" . ($canedit ? 5 + $colsup : 4 + $colsup) . "'>" . __('Add a user') . "</th></tr>"; echo "<tr class='tab_bg_1'><td colspan='" . (3 + $colsup) . "' class='center'>"; echo "<input type='hidden' name='plugin_resources_resources_id' value='{$instID}'>"; echo "<input type='hidden' name='itemtype' value='User'>"; //Dropdown::showAllItems("items_id",0,0,($resource->fields['is_recursive']?-1:$resource->fields['entities_id']),$types); User::dropdown(array('name' => 'items_id', 'entity' => $resource->fields["entities_id"], 'right' => 'all', 'ldap_import' => true)); echo "</td>"; echo "<td colspan='2' class='tab_bg_2'>"; echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number && $withtemplate < 2) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array(); Html::showMassiveActions(__CLASS__, $massiveactionparams); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number && $withtemplate < 2) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; if (Session::isMultiEntitiesMode()) { echo "<th>" . __('Entity') . "</th>"; } echo "<th>" . __('Serial Number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemType = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemType))) { continue; } if ($item->canView()) { $column = "name"; $itemTable = getTableForItemType($itemType); $query = "SELECT `" . $itemTable . "`.*,\n `glpi_plugin_resources_resources_items`.`id` AS items_id,\n `glpi_plugin_resources_resources_items`.`comment` AS comment,\n `glpi_entities`.`id` AS entity " . " FROM `glpi_plugin_resources_resources_items`, `" . $itemTable . "` LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id` = `" . $itemTable . "`.`entities_id`) " . " WHERE `" . $itemTable . "`.`id` = `glpi_plugin_resources_resources_items`.`items_id`\n AND `glpi_plugin_resources_resources_items`.`itemtype` = '{$itemType}'\n AND `glpi_plugin_resources_resources_items`.`plugin_resources_resources_id` = '{$instID}' "; if ($itemType != 'User') { $query .= getEntitiesRestrictRequest(" AND ", $itemTable, '', '', $item->maybeRecursive()); } if ($item->maybeTemplate()) { $query .= " AND `" . $itemTable . "`.`is_template` = '0'"; } $query .= " ORDER BY `glpi_entities`.`completename`, `" . $itemTable . "`.`{$column}`"; if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { Session::initNavigateListItems($itemType, PluginResourcesResource::getTypeName(2) . " = " . $resource->fields['name']); while ($data = $DB->fetch_assoc($result_linked)) { $item->getFromDB($data["id"]); Session::addToNavigateListItems($itemType, $data["id"]); $ID = ""; if ($itemType == 'User') { $format = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); } else { $format = $data["name"]; } if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { $ID = " (" . $data["id"] . ")"; } $link = Toolbox::getItemTypeFormURL($itemType); $name = "<a href=\"" . $link . "?id=" . $data["id"] . "\">" . $format; if ($itemType != 'User') { $name .= " " . $ID; } $name .= "</a>"; echo "<tr class='tab_bg_1'>"; $items_id = $data["items_id"]; if ($canedit && $withtemplate < 2) { echo "<td width='10'>"; Html::showMassiveActionCheckBox(__CLASS__, $data["items_id"]); /*TODO resolve IT or drop IT ? echo "<img src='".$CFG_GLPI["root_doc"]."/pics/expand.gif' onclick=\"plugin_resources_show_item('comment$items_id$rand',this,'".$CFG_GLPI["root_doc"]."/pics/collapse.gif');\">";*/ echo "</td>"; } echo "<td class='center'>" . $item::getTypeName(1) . "</td>"; echo "<td class='center' " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; if (Session::isMultiEntitiesMode()) { if ($itemType != 'User') { echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entity']) . "</td>"; } else { echo "<td class='center'>-</td>"; } } echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; /*TODO resolve IT or drop IT ? echo "<tr class='tab_bg_1'>"; $class = "class='plugin_resources_show'"; if (!isset($data["comment"]) || empty($data["comment"])) { $data["comment"]=''; $class = "class='plugin_resources_hide'"; } echo "<td colspan='6' id='comment$items_id$rand' $class >"; echo "<form method='post' name='updatecomment$items_id$rand' id='updatecomment$items_id$rand' action='".Toolbox::getItemTypeFormURL("PluginResourcesResource")."'>"; echo "<table><tr><td>"; _e('Comments'); echo "<br><textarea cols='150' rows='5' name='comment$items_id' >"; echo $data["comment"]; echo "</textarea><br><br>"; echo "<input type='hidden' name='items_id' value='".$data["items_id"]."'>"; if($canedit && $withtemplate<2) { if (!isset($data["comment"]) || empty($data["comment"])) { echo "<input type='submit' name='updatecomment[".$items_id."]' value=\""._sx('button','Add')."\" class='submit'>"; } else { echo "<input type='submit' name='updatecomment[".$items_id."]' value=\""._sx('button','Update')."\" class='submit'>"; } } echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</td>"; echo "</tr>";*/ } } } } } echo "</table>"; if ($canedit && $number && $withtemplate < 2) { $paramsma['ontop'] = false; Html::showMassiveActions(__CLASS__, $paramsma); Html::closeForm(); } echo "</div>"; }
/** * Show the availability of a user * * @since version 0.83 * * @param $params array of params * must contain : * - begin: begin date to check (default '') * - end: end date to check (default '') * - itemtype : User or Object type (Ticket...) * - foreign key field of the itemtype to define which item to used * optional : * - limitto : limit display to a specific user * * @return Nothing (display function) **/ static function checkAvailability($params = array()) { global $CFG_GLPI, $DB; if (!isset($params['itemtype'])) { return false; } if (!($item = getItemForItemtype($params['itemtype']))) { return false; } if (!isset($params[$item->getForeignKeyField()]) || !$item->getFromDB($params[$item->getForeignKeyField()])) { return false; } // No limit by default if (!isset($params['limitto'])) { $params['limitto'] = 0; } if (isset($params['begin']) && !empty($params['begin'])) { $begin = $params['begin']; } else { $begin = date("Y-m-d"); } if (isset($params['end']) && !empty($params['end'])) { $end = $params['end']; } else { $end = date("Y-m-d"); } if ($end < $begin) { $end = $begin; } $realbegin = $begin . " " . $CFG_GLPI["planning_begin"]; $realend = $end . " " . $CFG_GLPI["planning_end"]; $users = array(); switch ($item->getType()) { case 'User': $users[$item->getID()] = $item->getName(); break; default: if (Toolbox::is_a($item, 'CommonITILObject')) { foreach ($item->getUsers(CommonITILActor::ASSIGN) as $data) { $users[$data['users_id']] = getUserName($data['users_id']); } foreach ($item->getGroups(CommonITILActor::ASSIGN) as $data) { foreach (Group_User::getGroupUsers($data['groups_id']) as $data2) { $users[$data2['id']] = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"]); } } } break; } asort($users); // Use get method to check availability echo "<div class='center'><form method='GET' name='form' action='planning.php'>\n"; echo "<table class='tab_cadre_fixe'>"; $colspan = 5; if (count($users) > 1) { $colspan++; } echo "<tr class='tab_bg_1'><th colspan='{$colspan}'>" . __('Availability') . "</th>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Start') . "</td>\n"; echo "<td>"; Html::showDateField("begin", array('value' => $begin, 'maybeempty' => false)); echo "</td>\n"; echo "<td>" . __('End') . "</td>\n"; echo "<td>"; Html::showDateField("end", array('value' => $end, 'maybeempty' => false)); echo "</td>\n"; if (count($users) > 1) { echo "<td width='40%'>"; $data = array(0 => __('All')); $data += $users; Dropdown::showFromArray('limitto', $data, array('width' => '100%', 'value' => $params['limitto'])); echo "</td>"; } echo "<td class='center'>"; echo "<input type='hidden' name='" . $item->getForeignKeyField() . "' value=\"" . $item->getID() . "\">"; echo "<input type='hidden' name='itemtype' value=\"" . $item->getType() . "\">"; echo "<input type='submit' class='submit' name='checkavailability' value=\"" . _sx('button', 'Search') . "\">"; echo "</td>\n"; echo "</tr>"; echo "</table>"; Html::closeForm(); echo "</div>\n"; if ($params['limitto'] > 0 && isset($users[$params['limitto']])) { $displayuser[$params['limitto']] = $users[$params['limitto']]; } else { $displayuser = $users; } if (count($displayuser)) { foreach ($displayuser as $who => $whoname) { $params = array('who' => $who, 'who_group' => 0, 'begin' => $realbegin, 'end' => $realend); $interv = array(); foreach ($CFG_GLPI['planning_types'] as $itemtype) { $interv = array_merge($interv, $itemtype::populatePlanning($params)); } // Print Headers echo "<br><div class='center'><table class='tab_cadre_fixe'>"; $colnumber = 1; $plan_begin = explode(":", $CFG_GLPI["planning_begin"]); $plan_end = explode(":", $CFG_GLPI["planning_end"]); $begin_hour = intval($plan_begin[0]); $end_hour = intval($plan_end[0]); if ($plan_end[1] != 0) { $end_hour++; } $colsize = floor((100 - 15) / ($end_hour - $begin_hour)); $timeheader = ''; for ($i = $begin_hour; $i < $end_hour; $i++) { $from = ($i < 10 ? '0' : '') . $i; $timeheader .= "<th width='{$colsize}%' colspan='4'>" . $from . ":00</th>"; $colnumber += 4; } // Print Headers echo "<tr class='tab_bg_1'><th colspan='{$colnumber}'>"; echo $whoname; echo "</th></tr>"; echo "<tr class='tab_bg_1'><th width='15%'> </th>"; echo $timeheader; echo "</tr>"; $day_begin = strtotime($realbegin); $day_end = strtotime($realend); for ($time = $day_begin; $time < $day_end; $time += DAY_TIMESTAMP) { $current_day = date('Y-m-d', $time); echo "<tr><th>" . Html::convDate($current_day) . "</th>"; $begin_quarter = $begin_hour * 4; $end_quarter = $end_hour * 4; for ($i = $begin_quarter; $i < $end_quarter; $i++) { $begin_time = date("Y-m-d H:i:s", strtotime($current_day) + $i * HOUR_TIMESTAMP / 4); $end_time = date("Y-m-d H:i:s", strtotime($current_day) + ($i + 1) * HOUR_TIMESTAMP / 4); // Init activity interval $begin_act = $end_time; $end_act = $begin_time; reset($interv); while ($data = current($interv)) { if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) { // In if ($begin_act > $data["begin"]) { $begin_act = $data["begin"]; } if ($end_act < $data["end"]) { $end_act = $data["end"]; } unset($interv[key($interv)]); } else { if ($data["begin"] < $begin_time && $data["end"] > $end_time) { // Through $begin_act = $begin_time; $end_act = $end_time; next($interv); } else { if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) { // Begin if ($begin_act > $data["begin"]) { $begin_act = $data["begin"]; } $end_act = $end_time; next($interv); } else { if ($data["end"] > $begin_time && $data["end"] <= $end_time) { //End $begin_act = $begin_time; if ($end_act < $data["end"]) { $end_act = $data["end"]; } unset($interv[key($interv)]); } else { // Defautl case next($interv); } } } } } if ($begin_act < $end_act) { if ($begin_act <= $begin_time && $end_act >= $end_time) { // Activity in quarter echo "<td class='notavailable'> </td>"; } else { // Not all the quarter if ($begin_act <= $begin_time) { echo "<td class='partialavailableend'> </td>"; } else { echo "<td class='partialavailablebegin'> </td>"; } } } else { // No activity echo "<td class='available'> </td>"; } } echo "</tr>"; } echo "<tr class='tab_bg_1'><td colspan='{$colnumber}'> </td></tr>"; echo "</table></div>"; } } echo "<div><table class='tab_cadre'>"; echo "<tr class='tab_bg_1'>"; echo "<th>" . __('Caption') . "</th>"; echo "<td class='available' colspan=8>" . __('Available') . "</td>"; echo "<td class='notavailable' colspan=8>" . __('Unavailable') . "</td>"; echo "</tr>"; echo "</table></div>"; }
/** * Add new mail with lang to current email array * * @param $data array of data (mail, lang[, id for user]) **/ function addToAddressesList(array $data) { global $CFG_GLPI; // No email set : get default for user if (!isset($data['email']) && isset($data['users_id'])) { $data['email'] = UserEmail::getDefaultForUser($data['users_id']); } $new_mail = trim(Toolbox::strtolower($data['email'])); $new_lang = ''; // Default USER TYPE is ANONYMOUS $notificationoption = array('usertype' => self::ANONYMOUS_USER); if (isset($data['language'])) { $new_lang = trim($data['language']); } $username = ''; if (isset($data['name']) && !empty($data['name'])) { $username = $data['name']; } if (isset($data['users_id']) && $data['users_id'] > 0) { $user = new User(); if (!$user->getFromDB($data['users_id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0 || !is_null($user->getField('begin_date')) && $user->getField('begin_date') > $_SESSION["glpi_currenttime"] || !is_null($user->getField('end_date')) && $user->getField('end_date') < $_SESSION["glpi_currenttime"]) { // unknown, deleted or disabled user return false; } $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true); $prof = Profile_User::getUserProfiles($data['users_id'], $filt); if (!count($prof)) { // No right on the entity of the object return false; } if (empty($username)) { $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true); } // It is a GLPI user : $notificationoption['usertype'] = self::GLPI_USER; if (Auth::isAlternateAuth($user->fields['authtype']) || $user->fields['authtype'] == Auth::NOT_YET_AUTHENTIFIED && Auth::isAlternateAuth(Auth::checkAlternateAuthSystems())) { $notificationoption['usertype'] = self::EXTERNAL_USER; } } // Pass user type as argument ? forced for specific cases if (isset($data['usertype'])) { $notificationoption['usertype'] = $data['usertype']; } $notificationoption = array_merge($this->addAdditionnalUserInfo($data), $notificationoption); if (!empty($new_mail)) { if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) { $param = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username); if (isset($data['users_id']) && $data['users_id']) { $param['users_id'] = $data['users_id']; } $this->target[$new_mail] = $param; } } }
/** * List all users of the current entity, with search criterias * for an authenticated user * * @param $params array of options (user, group, location, login, name) * @param $protocol the commonication protocol used * * @return array of hashtable **/ static function methodListUsers($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('count' => 'bool,optional', 'start' => 'integer,optional', 'limit' => 'integer,optional', 'order' => 'string,optional', 'entity' => 'integer,optional', 'parent' => 'bool,optional', 'user' => 'integer,optional', 'group' => 'integer,optional', 'location' => 'integer,optional', 'login' => 'string,optional', 'name' => 'string,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $orders = array('id' => '`glpi_users`.`id`', 'name' => $_SESSION['glpinames_format'] == User::FIRSTNAME_BEFORE ? '`glpi_users`.`firstname`,`glpi_users`.`realname`' : '`glpi_users`.`realname`,`glpi_users`.`firstname`', 'login' => '`glpi_users`.`name`'); $parent = 1; if (isset($params['parent'])) { $parent = $params['parent'] ? 1 : 0; } if (isset($params['entity'])) { if (!Session::haveAccessToEntity($params['entity'])) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'entity'); } $ent = $params['entity']; } else { $ent = ''; } $query = "LEFT JOIN `glpi_profiles_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n LEFT JOIN `glpi_useremails`\n ON (`glpi_users`.`id` = `glpi_useremails`.`users_id`\n AND `glpi_useremails`.`is_default`)\n WHERE `glpi_users`.`is_deleted` = '0'\n AND `glpi_users`.`is_active` = '1' " . getEntitiesRestrictRequest('AND', "glpi_profiles_users", '', $ent, $parent); if (isset($params['user']) && is_numeric($params['user'])) { $query .= " AND `glpi_users`.`id` = '" . $params['user'] . "'"; } if (isset($params['group']) && is_numeric($params['group'])) { $query .= " AND `glpi_users`.`id` IN (SELECT `users_id`\n FROM `glpi_groups_users`\n WHERE `groups_id` = '" . $params['group'] . "')"; } if (isset($params['location']) && is_numeric($params['location'])) { $query .= " AND `glpi_users`.`locations_id` = '" . $params['location'] . "'"; } if (isset($params['login'])) { $query .= " AND `glpi_users`.`name` LIKE '" . addslashes($params['login']) . "'"; } if (isset($params['name'])) { if ($_SESSION['glpinames_format'] == User::FIRSTNAME_BEFORE) { $query .= " AND CONCAT(`glpi_users`.`firstname`,' ',`glpi_users`.`realname`)"; } else { $query .= " AND CONCAT(`glpi_users`.`realname`,' ',`glpi_users`.`firstname`)"; } $query .= " LIKE '" . addslashes($params['name']) . "'"; } $resp = array(); if (isset($params['count'])) { $query = "SELECT COUNT(DISTINCT `glpi_users`.`id`) AS count\n FROM `glpi_users`\n {$query}"; $resp = $DB->request($query)->next(); } else { $start = 0; $limit = $_SESSION['glpilist_limit']; if (isset($params['limit']) && is_numeric($params['limit'])) { $limit = $params['limit']; } if (isset($params['start']) && is_numeric($params['start'])) { $start = $params['start']; } if (isset($params['order']) && isset($orders[$params['order']])) { $order = $orders[$params['order']]; } else { $order = $orders['id']; } $query = "SELECT DISTINCT(`glpi_users`.`id`) AS id,\n `glpi_users`.`name`, `firstname`,\n `realname`, `email`, `phone`, `glpi_users`.`locations_id`,\n `glpi_locations`.`completename` AS locations_name\n FROM `glpi_users`\n LEFT JOIN `glpi_locations`\n ON (`glpi_users`.`locations_id` = `glpi_locations`.`id`)\n {$query}\n ORDER BY {$order}\n LIMIT {$start},{$limit}"; foreach ($DB->request($query) as $data) { $data['displayname'] = formatUserName(0, $data['name'], $data['realname'], $data['firstname']); $resp[] = $data; } } return $resp; }
/** * Show the User having a profile, in allowed Entity * * @param $prof object **/ static function showForProfile(Profile $prof) { global $DB, $LANG, $CFG_GLPI; $ID = $prof->fields['id']; $canedit = haveRight("user", "w"); if (!$prof->can($ID, 'r')) { return false; } echo "<div class='spaced'>"; echo "<table class='tab_cadre_fixe'><tr>"; echo "<th>" . $LANG['profiles'][22] . " :<span class='small_space'>" . $prof->fields["name"] . "</span></th></tr>\n"; echo "<tr><th colspan='2'>" . $LANG['Menu'][14] . " (D=" . $LANG['profiles'][29] . ", R=" . $LANG['profiles'][28] . ")</th></tr>"; echo "</table>\n"; $query = "SELECT `glpi_users`.*,\n `glpi_profiles_users`.`entities_id` AS entity,\n `glpi_profiles_users`.`id` AS linkID,\n `glpi_profiles_users`.`is_dynamic`,\n `glpi_profiles_users`.`is_recursive`\n FROM `glpi_profiles_users`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id`=`glpi_profiles_users`.`entities_id`)\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n WHERE `glpi_profiles_users`.`profiles_id` = '{$ID}'\n AND `glpi_users`.`is_deleted` = '0' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", 'entities_id', $_SESSION['glpiactiveentities'], true) . "\n ORDER BY `glpi_entities`.`completename`"; echo "<table class='tab_cadre_fixe'>"; $i = 0; $nb_per_line = 3; $rand = mt_rand(); // Just to avoid IDE warning $canedit_entity = false; if ($result = $DB->query($query)) { if ($DB->numrows($result) != 0) { $temp = -1; while ($data = $DB->fetch_array($result)) { if ($data["entity"] != $temp) { while ($i % $nb_per_line != 0) { if ($canedit_entity) { echo "<td width='10'> </td>"; } echo "<td class='tab_bg_1'> </td>\n"; $i++; } if ($i != 0) { echo "</table>"; if ($canedit_entity) { openArrowMassive("profileuser_form" . $rand . "_{$temp}", true); Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities'])); echo " <input type='submit' name='moveentity' value='" . $LANG['buttons'][20] . "' class='submit'> "; closeArrowMassive('delete', $LANG['buttons'][6]); } echo "</div></form></td></tr>\n"; } // New entity $i = 0; $temp = $data["entity"]; $canedit_entity = $canedit && in_array($temp, $_SESSION['glpiactiveentities']); $rand = mt_rand(); echo "<tr class='tab_bg_2'>"; echo "<td class='left'>"; echo "<a href=\"javascript:showHideDiv('entity{$temp}{$rand}','imgcat{$temp}', '" . GLPI_ROOT . "/pics/folder.png','" . GLPI_ROOT . "/pics/folder-open.png');\">"; echo "<img alt='' name='imgcat{$temp}' src=\"" . GLPI_ROOT . "/pics/folder.png\"> "; echo "<strong>" . Dropdown::getDropdownName('glpi_entities', $data["entity"]) . "</strong>"; echo "</a></td></tr>\n"; echo "<tr><td>"; echo "<form name='profileuser_form" . $rand . "_{$temp}' id='profileuser_form" . $rand . "_{$temp}' method='post' action='" . getItemTypeFormURL(__CLASS__) . "'>"; echo "<div class='center' id='entity{$temp}{$rand}' style='display:none;'>\n"; echo "<table class='tab_cadre_fixe'>\n"; } if ($i % $nb_per_line == 0) { if ($i != 0) { echo "</tr>\n"; } echo "<tr class='tab_bg_1'>\n"; $i = 0; } if ($canedit_entity) { echo "<td width='10'>"; $sel = ""; if (isset($_GET["select"]) && $_GET["select"] == "all") { $sel = "checked"; } echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1' {$sel}>"; echo "</td>"; } echo "<td class='tab_bg_1'>" . formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"], 1); if ($data["is_dynamic"] || $data["is_recursive"]) { echo "<strong> ("; if ($data["is_dynamic"]) { echo "D"; } if ($data["is_dynamic"] && $data["is_recursive"]) { echo ", "; } if ($data["is_recursive"]) { echo "R"; } echo ")</strong>"; } echo "</td>\n"; $i++; } if ($i % $nb_per_line != 0) { while ($i % $nb_per_line != 0) { if ($canedit_entity) { echo "<td width='10'> </td>"; } echo "<td class='tab_bg_1'>" . DROPDOWN_EMPTY_VALUE . "</td>"; $i++; } } if ($i != 0) { echo "</table>\n"; if ($canedit_entity) { openArrowMassive("profileuser_form" . $rand . "_{$temp}", true); Dropdown::show('Entity', array('entity' => $_SESSION['glpiactiveentities'])); echo " <input type='submit' name='moveentity' value='" . $LANG['buttons'][20] . "' class='submit'> "; closeArrowMassive('delete', $LANG['buttons'][6]); } echo "</div></form></td></tr>\n"; } } else { echo "<tr><td class='tab_bg_1 center'>" . $LANG['profiles'][33] . "</td></tr>\n"; } } echo "</table></div>\n"; }
/** * 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; $showuserlink = 0; if (Session::haveRight('user', READ)) { $showuserlink = 1; } $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_"; } $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 = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if ($split[$k] > 0) { if ($count_display) { $out .= "<br>"; } $count_display++; if ($itemtype == 'Ticket') { $userdata = getUserName($split[$k], 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); } else { $out .= getUserName($split[$k], $showuserlink); } } } // Manage alternative_email for tickets_users if ($itemtype == 'Ticket' && isset($data[$NAME . $num . '_2'])) { $split = explode("\$\$\$\$", $data[$NAME . $num . '_2']); for ($k = 0; $k < count($split); $k++) { $split2 = explode(" ", $split[$k]); if (count($split2) == 2 && $split2[0] == 0 && !empty($split2[1])) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= "<a href='mailto:" . $split2[1] . "'>" . $split2[1] . "</a>"; } } } return $out; } if ($itemtype != 'User') { $toadd = ''; if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) { $userdata = getUserName($data[$NAME . $num . "_3"], 2); $toadd = Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } if (Session::haveRight('user', READ)) { $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 1); } else { $usernameformat = formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 0); } return sprintf(__('%1$s %2$s'), $usernameformat, $toadd); } break; case "glpi_profiles.interface": return Profile::getInterfaceName($data[$NAME . $num]); case "glpi_profiles.name": if ($itemtype == 'User' && $ID == 20) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_entities', $split2[$k])); $comp = ''; if ($split3[$k]) { $comp = __(READ); if ($split4[$k]) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($split4[$k]) { $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 .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_entities.completename": if ($itemtype == 'User') { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $split4 = explode("\$\$\$\$", $data[$NAME . $num . "_4"]); $added = array(); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = sprintf(__('%1$s - %2$s'), $split[$k], Dropdown::getDropdownName('glpi_profiles', $split2[$k])); $comp = ''; if ($split3[$k]) { $comp = __(READ); if ($split4[$k]) { $comp = sprintf(__('%1$s%2$s'), $comp, ", "); } } if ($split4[$k]) { $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 .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_documenttypes.icon": if (!empty($data[$NAME . $num])) { return "<img class='middle' alt='' src='" . $CFG_GLPI["typedoc_icon_dir"] . "/" . $data[$NAME . $num] . "'>"; } return " "; case "glpi_documents.filename": $doc = new Document(); if ($doc->getFromDB($data['id'])) { return $doc->getDownloadLink(); } return NOT_AVAILABLE; case "glpi_deviceharddrives.specificity": case "glpi_devicememories.specificity": case "glpi_deviceprocessors.specificity": return $data[$NAME . $num]; case "glpi_networkports.mac": $out = ""; if ($itemtype == 'Computer') { $displayed = array(); if (!empty($data[$NAME . $num . "_2"])) { $split = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { $lowstr = Toolbox::strtolower($split[$k]); if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $split[$k]; $displayed[] = $lowstr; } } if (!empty($data[$NAME . $num])) { $out .= "<br>"; } } if (!empty($data[$NAME . $num])) { $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { $lowstr = Toolbox::strtolower($split[$k]); if (strlen(trim($split[$k])) > 0 && !in_array($lowstr, $displayed)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $split[$k]; $displayed[] = $lowstr; } } } return $out; } break; case "glpi_contracts.duration": case "glpi_contracts.notice": case "glpi_contracts.periodicity": case "glpi_contracts.billing": if (!empty($data[$NAME . $num])) { $split = explode('$$$$', $data[$NAME . $num]); $output = ""; foreach ($split as $duration) { $output .= (empty($output) ? '' : '<br>') . sprintf(_n('%d month', '%d months', $duration), $duration); } return $output; } return " "; case "glpi_contracts.renewal": return Contract::getContractRenewalName($data[$NAME . $num]); // case "glpi_infocoms.sink_time" : // if (!empty($data[$NAME.$num])) { // $split = explode("$$$$", $data[$NAME.$num]); // $out = ''; // foreach ($split as $val) { // $out .= (empty($out)?'':'<br>'); // if ($val > 0) { // //TRANS: %d is a number of years // $out .= sprintf(_n('%d year', '%d years', $val), $val); // } // } // return $out; // } // return " "; // // case "glpi_infocoms.warranty_duration" : // if (!empty($data[$NAME.$num])) { // $split = explode("$$$$", $data[$NAME.$num]); // $out = ''; // foreach ($split as $val) { // $out .= (empty($out)?'':'<br>'); // if ($val > 0) { // $out .= sprintf(_n('%d month', '%d months', $val), $val); // } // if ($val < 0) { // $out .= __('Lifelong'); // } // } // return $out; // } // return " "; // case "glpi_infocoms.sink_time" : // if (!empty($data[$NAME.$num])) { // $split = explode("$$$$", $data[$NAME.$num]); // $out = ''; // foreach ($split as $val) { // $out .= (empty($out)?'':'<br>'); // if ($val > 0) { // //TRANS: %d is a number of years // $out .= sprintf(_n('%d year', '%d years', $val), $val); // } // } // return $out; // } // return " "; // // case "glpi_infocoms.warranty_duration" : // if (!empty($data[$NAME.$num])) { // $split = explode("$$$$", $data[$NAME.$num]); // $out = ''; // foreach ($split as $val) { // $out .= (empty($out)?'':'<br>'); // if ($val > 0) { // $out .= sprintf(_n('%d month', '%d months', $val), $val); // } // if ($val < 0) { // $out .= __('Lifelong'); // } // } // return $out; // } // return " "; case "glpi_infocoms.sink_type": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . Infocom::getAmortTypeName($val); } return $out; case "glpi_infocoms.alert": if ($data[$NAME . $num] == pow(2, Alert::END)) { return __s('Warranty expiration date'); } return ""; case "glpi_contracts.alert": switch ($data[$NAME . $num]) { case pow(2, Alert::END): return __('End'); case pow(2, Alert::NOTICE): return __('Notice'); case pow(2, Alert::END) + pow(2, Alert::NOTICE): return __('End + Notice'); } return ""; case "glpi_tickets_tickets.tickets_id_1": $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $displayed = array(); for ($k = 0; $k < count($split); $k++) { $linkid = $split[$k] == $data['id'] ? $split2[$k] : $split[$k]; 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 .= "<br>"; } $displayed[$linkid] = $linkid; $out .= $text; } } return $out; case "glpi_problems.count": if ($data[$NAME . $num] > 0 && Session::haveRight("problem", Problem::READALL)) { if ($itemtype == 'ITILCategory') { $options['field'][0] = 7; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $data['id']; $options['link'][0] = '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[$NAME . $num] . "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_tickets.count": if ($data[$NAME . $num] > 0 && Session::haveRight("ticket", Ticket::READALL)) { if ($itemtype == 'User') { $options['field'][0] = 4; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $data['id']; $options['link'][0] = 'AND'; $options['field'][1] = 22; $options['searchtype'][1] = 'equals'; $options['contains'][1] = $data['id']; $options['link'][1] = 'OR'; $options['field'][2] = 5; $options['searchtype'][2] = 'equals'; $options['contains'][2] = $data['id']; $options['link'][2] = 'OR'; } else { if ($itemtype == 'ITILCategory') { $options['field'][0] = 7; $options['searchtype'][0] = 'equals'; $options['contains'][0] = $data['id']; $options['link'][0] = 'AND'; } else { $options['field'][0] = 12; $options['searchtype'][0] = 'equals'; $options['contains'][0] = 'all'; $options['link'][0] = 'AND'; $options['itemtype2'][0] = $itemtype; $options['field2'][0] = self::getOptionNumber($itemtype, 'name'); $options['searchtype2'][0] = 'equals'; $options['contains2'][0] = $data['id']; $options['link2'][0] = '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[$NAME . $num] . "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_tickets.due_date": // Due date + progress if ($ID == 151) { $out = Html::convDate($data[$NAME . $num]); // No due date in waiting status if ($data[$NAME . $num . '_2'] == CommonITILObject::WAITING) { return ''; } if (empty($data[$NAME . $num])) { return ''; } if ($data[$NAME . $num . '_2'] == Ticket::SOLVED || $data[$NAME . $num . '_2'] == Ticket::CLOSED) { return $data[$NAME . $num]; } $ticket = new Ticket(); $ticket->getFromDB($data['ITEM_0']); $percentage = 0; $totaltime = 0; $currenttime = 0; if ($ticket->fields['slas_id'] != 0) { // Have SLA $sla = new SLA(); $sla->getFromDB($ticket->fields['slas_id']); $currenttime = $sla->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s')); $totaltime = $sla->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]); } else { $calendars_id = Entity::getUsedConfig('calendars_id', $ticket->fields['entities_id']); if ($calendars_id != 0) { // Ticket entity have calendar $calendar = new Calendar(); $calendar->getFromDB($calendars_id); $currenttime = $calendar->getActiveTimeBetween($ticket->fields['date'], date('Y-m-d H:i:s')); $totaltime = $calendar->getActiveTimeBetween($ticket->fields['date'], $data[$NAME . $num]); } else { // No calendar $currenttime = strtotime(date('Y-m-d H:i:s')) - strtotime($ticket->fields['date']); $totaltime = strtotime($data[$NAME . $num]) - strtotime($ticket->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'] == 'hours') { $less_warn_limit = $_SESSION['glpiduedatewarning_less'] * HOUR_TIMESTAMP; $less_warn = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatewarning_unit'] == 'days') { $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'] == 'hours') { $less_crit_limit = $_SESSION['glpiduedatecritical_less'] * HOUR_TIMESTAMP; $less_crit = $totaltime - $currenttime; } else { if ($_SESSION['glpiduedatecritical_unit'] == 'days') { $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;' >"; $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[$NAME . $num . "_2"] == -1) { return __('Unlimited'); } if (empty($data[$NAME . $num])) { return 0; } return $data[$NAME . $num]; case "glpi_auth_tables.name": return Auth::getMethodName($data[$NAME . $num], $data[$NAME . $num . "_2"], 1, $data[$NAME . $num . "_3"] . $data[$NAME . $num . "_4"]); case "glpi_reservationitems.comment": if (empty($data[$NAME . $num])) { 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[$NAME . $num]) . "</a>"; case 'glpi_notifications.mode': return Notification::getMode($data[$NAME . $num]); case 'glpi_notifications.event': $item = NotificationTarget::getInstanceByType($data['itemtype']); if ($item) { $events = $item->getAllEvents(); if (isset($events[$data[$NAME . $num]])) { return $events[$data[$NAME . $num]]; } } return ''; case 'glpi_reminders.state': return Planning::getState($data[$NAME . $num]); case 'glpi_crontasks.description': $tmp = new CronTask(); return $tmp->getDescription($data['id']); case 'glpi_crontasks.state': return CronTask::getStateName($data[$NAME . $num]); case 'glpi_crontasks.mode': return CronTask::getModeName($data[$NAME . $num]); case 'glpi_crontasks.itemtype': if ($plug = isPluginItemType($data[$NAME . $num])) { return $plug['plugin']; } return ''; case 'glpi_changes.status': $status = Change::getStatus($data[$NAME . $num]); return "<img src=\"" . Change::getStatusIconURL($data[$NAME . $num]) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_problems.status': $status = Problem::getStatus($data[$NAME . $num]); return "<img src=\"" . Problem::getStatusIconURL($data[$NAME . $num]) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.status': $status = Ticket::getStatus($data[$NAME . $num]); return "<img src=\"" . Ticket::getStatusIconURL($data[$NAME . $num]) . "\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.items_id': if (!empty($data[$NAME . $num . "_2"]) && ($item = getItemForItemtype($data[$NAME . $num . "_2"]))) { if ($item->getFromDB($data[$NAME . $num])) { return $item->getLink(array('comments' => true)); } } return ' '; case 'glpi_tickets.name': if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; $link = Toolbox::getItemTypeFormURL('Ticket'); foreach ($split as $val) { if (!empty($val)) { $split2 = self::explodeWithID("\$\$", $val); $out .= "<a id='ticket" . $split2[1] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $split2[1]; $out .= "\">"; $name = $split2[0]; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]); } $out .= $name . "</a><br>"; } } return $out; } $link = Toolbox::getItemTypeFormURL('Ticket'); $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"]; // Force solution tab if solved if ($data[$NAME . $num . "_4"] == CommonITILObject::SOLVED) { $out .= "&forcetab=Ticket\$2"; } $out .= "\">"; $name = $data[$NAME . $num]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]); } $out .= $name . "</a>"; $out = sprintf(__('%1$s %2$s'), $out, Html::showToolTip(nl2br($data[$NAME . $num . "_3"]), array('applyto' => 'ticket' . $data[$NAME . $num . "_2"], 'display' => false))); return $out; case 'glpi_ticketvalidations.status': $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { if (!empty($val)) { $split2 = self::explodeWithID("\$\$", $val); $status = TicketValidation::getStatus($split2[0]); $bgcolor = TicketValidation::getStatusColor($split2[0]); $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } } return $out; case 'glpi_ticketsatisfactions.type': return TicketSatisfaction::getTypeInquestName($data[$NAME . $num]); case 'glpi_ticketsatisfactions.satisfaction': return TicketSatisfaction::displaySatisfaction($data[$NAME . $num]); case 'glpi_notimportedemails.reason': return NotImportedEmail::getReason($data[$NAME . $num]); case 'glpi_notimportedemails.messageid': $clean = array('<' => '', '>' => ''); return strtr($data[$NAME . $num], $clean); } //// Default case // Link with plugin tables : need to know left join structure 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']; } /// TODO try to use getvalueToDisplay instead of redefine display system // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": $linkitemtype = getItemTypeForTable($searchopt[$ID]["table"]); if (isset($data[$NAME . $num . "_2"]) && strlen($data[$NAME . $num . "_2"])) { $link = Toolbox::getItemTypeFormURL($linkitemtype); $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"]; if (isset($searchopt[$ID]['forcetab'])) { $out .= "&forcetab=" . $searchopt[$ID]['forcetab']; } $out .= "\">"; $name = Dropdown::getValueWithUnit($data[$NAME . $num], $unit); if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $name = sprintf(__('%1$s (%2$s)'), $name, $data[$NAME . $num . "_2"]); } $out .= $name . "</a>"; return $out; } $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $split2 = self::explodeWithID("\$\$", $split[$k]); if (isset($split2[1]) && $split2[1] > 0) { if ($count_display) { $out .= $separate; } $count_display++; $page = Toolbox::getItemTypeFormURL($linkitemtype); $page .= strpos($page, '?') ? '&id' : '?id'; $name = Dropdown::getValueWithUnit($split2[0], $unit); if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $name = sprintf(__('%1$s (%2$s)'), $name, $split2[1]); } $out .= "<a id='" . $linkitemtype . "_" . $data['id'] . "_" . $split2[1] . "' href='{$page}=" . $split2[1] . "'>" . $name . "</a>"; } } } return $out; case "text": $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; $count_display = 0; foreach ($split as $val) { if (strlen(trim($val)) > 0) { $split2 = self::explodeWithID("\$\$", $val); if ($count_display) { $out .= $separate; } $count_display++; if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) { $text = Html::clean(Toolbox::unclean_cross_side_scripting_deep(nl2br($split2[0]))); } else { $text = nl2br($split2[0]); } 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": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . Html::convDate($val); } return $out; case "datetime": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . Html::convDateTime($val); } 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']; } $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . Html::timestampToString($val, $withseconds, $withdays); } return $out; case "email": $split = explode('$$$$', $data[$NAME . $num]); $out = ''; $count_display = 0; foreach ($split as $val) { $split2 = self::explodeWithID("\$\$", $val); if ($count_display) { $out .= "<br>"; } $count_display++; if (!empty($val)) { $out .= empty($out) ? '' : '<br>'; $out .= "<a href='mailto:{$split2['0']}'>{$split2['0']}</a>"; } } return empty($out) ? " " : $out; case "weblink": $orig_link = trim($data[$NAME . $num]); 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 "number": if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $split2 = self::explodeWithID("\$\$", $split[$k]); if ($count_display) { $out .= "<br>"; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) { $out .= $searchopt[$ID]['toadd'][$split2[0]]; } else { $number = str_replace(' ', ' ', Html::formatNumber($split2[0], false, 0)); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; } if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$data[$NAME . $num]])) { return $searchopt[$ID]['toadd'][$data[$NAME . $num]]; } else { $number = str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num], false, 0)); return Dropdown::getValueWithUnit($number, $unit); } case "decimal": if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $split2 = self::explodeWithID("\$\$", $split[$k]); if ($count_display) { $out .= "<br>"; } $count_display++; if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split2[0]])) { $out .= $searchopt[$ID]['toadd'][$split2[0]]; } else { $number = str_replace(' ', ' ', Html::formatNumber($split2[0])); $out .= Dropdown::getValueWithUnit($number, $unit); } } } return $out; } $number = str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num])); return Dropdown::getValueWithUnit($number, $unit); case "bool": if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $split2 = self::explodeWithID("\$\$", $split[$k]); if ($count_display) { $out .= "<br>"; } $count_display++; $out .= Dropdown::getValueWithUnit(Dropdown::getYesNo($split2[0]), $unit); } } return $out; } return Dropdown::getValueWithUnit(Dropdown::getYesNo($data[$NAME . $num]), $unit); case "right": return Profile::getRightValue($data[$NAME . $num]); case "itemtypename": if ($obj = getItemForItemtype($data[$NAME . $num])) { return $obj->getTypeName(); } return ""; case "language": if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) { return $CFG_GLPI['languages'][$data[$NAME . $num]][0]; } return __('Default value'); } } // Manage items with need group by / group_concat if (isset($searchopt[$ID]['forcegroupby']) && $searchopt[$ID]['forcegroupby']) { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $count_display = 0; $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { if ($count_display) { $out .= $separate; } $withoutid = self::explodeWithID("\$\$", $split[$k]); $count_display++; // Get specific display if available $itemtype = getItemTypeForTable($table); if ($item = getItemForItemtype($itemtype)) { $tmpdata = array($field => $withoutid[0]); $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true)); } if (!empty($specific)) { $out .= $specific; } else { $out .= Dropdown::getValueWithUnit($withoutid[0], $unit); } } } return $out; } // Get specific display if available $itemtype = getItemTypeForTable($table); if ($item = getItemForItemtype($itemtype)) { $tmpdata = array($field => $data[$NAME . $num]); if (isset($searchopt[$ID]['additionalfields']) && count($searchopt[$ID]['additionalfields'])) { foreach ($searchopt[$ID]['additionalfields'] as $key) { $tmpdata[$key] = $data[$NAME . $num . '_' . $key]; } } $specific = $item->getSpecificValueToDisplay($field, $tmpdata, array('html' => true)); if (!empty($specific)) { return $specific; } } // Manage auto CONCAT id $split = self::explodeWithID('$$', $data[$NAME . $num]); $split[0] = trim($split[0]); if (isset($searchopt[$ID]['toadd']) && isset($searchopt[$ID]['toadd'][$split[0]])) { return $searchopt[$ID]['toadd'][$split[0]]; } // Empty is 0 or empty if (empty($split[0]) && isset($searchopt[$ID]['emptylabel'])) { return $searchopt[$ID]['emptylabel']; } return Dropdown::getValueWithUnit($split[0], $unit); }
/** * Show installations of a software * * @param $searchID valeur to the ID to search * @param $crit to search : softwares_id (software) or id (version) * * @return nothing **/ private static function showInstallations($searchID, $crit) { global $DB, $CFG_GLPI, $LANG; if (!haveRight("software", "r") || !$searchID) { return false; } $canedit = haveRight("software", "w"); $canshowcomputer = haveRight("computer", "r"); if (isset($_REQUEST["start"])) { $start = $_REQUEST["start"]; } else { $start = 0; } if (isset($_REQUEST["order"]) && $_REQUEST["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_REQUEST["sort"]) && !empty($_REQUEST["sort"])) { // manage several param like location,compname : order first $tmp = explode(",", $_REQUEST["sort"]); $sort = "`" . implode("` {$order},`", $tmp) . "`"; } else { if ($crit == "softwares_id") { $sort = "`entity` {$order}, `version`, `compname`"; } else { $sort = "`entity` {$order}, `compname`"; } } // Total Number of events if ($crit == "softwares_id") { // Software ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_computers_softwareversions`\n INNER JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwareversions`.`computers_id`\n = `glpi_computers`.`id`)\n WHERE `glpi_softwareversions`.`softwares_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'"; } else { //SoftwareVersion ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_computers_softwareversions`\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwareversions`.`computers_id`\n = `glpi_computers`.`id`)\n WHERE `glpi_computers_softwareversions`.`softwareversions_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'"; } $number = 0; if ($result = $DB->query($query_number)) { $number = $DB->result($result, 0, 0); } echo "<div class='center'>"; if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . $LANG['search'][15] . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager printAjaxPager($LANG['software'][19], $start, $number); $query = "SELECT DISTINCT `glpi_computers_softwareversions`.*,\n `glpi_computers`.`name` AS compname,\n `glpi_computers`.`id` AS cID,\n `glpi_computers`.`serial`,\n `glpi_computers`.`otherserial`,\n `glpi_users`.`name` AS username,\n `glpi_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\n `glpi_softwareversions`.`name` AS version,\n `glpi_softwareversions`.`id` AS vID,\n `glpi_softwareversions`.`softwares_id` AS sID,\n `glpi_softwareversions`.`name` AS vername,\n `glpi_entities`.`completename` AS entity,\n `glpi_locations`.`completename` AS location,\n `glpi_states`.`name` AS state,\n `glpi_groups`.`name` AS groupe\n FROM `glpi_computers_softwareversions`\n INNER JOIN `glpi_softwareversions`\n ON (`glpi_computers_softwareversions`.`softwareversions_id`\n = `glpi_softwareversions`.`id`)\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwareversions`.`computers_id` = `glpi_computers`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n LEFT JOIN `glpi_locations`\n ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n WHERE (`glpi_softwareversions`.`{$crit}` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { $softwares_id = $data['sID']; $soft = new Software(); $showEntity = $soft->getFromDB($softwares_id) && $soft->isRecursive(); $linkUser = haveRight('user', 'r'); $title = $LANG['help'][31] . " = " . $soft->fields["name"]; if ($crit == "id") { $title .= " - " . $data["vername"]; } initNavigateListItems('Computer', $title); $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>"; if ($canedit) { echo "<form name='softinstall" . $rand . "' id='softinstall" . $rand . "' method='post'\n action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwareversion.form.php'>"; echo "<input type='hidden' name='softwares_id' value='{$softwares_id}'>"; echo "<table class='tab_cadre_fixehov'><tr>"; echo "<th> </th>"; } else { echo "<table class='tab_cadre_fixehov'><tr>"; } if ($crit == "softwares_id") { echo "<th>" . ($sort == "`vername`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=vername&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][5] . "</a></th>"; } echo "<th>" . ($sort == "`compname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][16] . "</a></th>"; if ($showEntity) { echo "<th>" . (strstr($sort, "entity") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=entity,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['entity'][0] . "</a></th>"; } echo "<th>" . ($sort == "`serial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=serial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][19] . "</a></th>"; echo "<th>" . ($sort == "`otherserial`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=otherserial&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][20] . "</a></th>"; echo "<th>" . (strstr($sort, "`location`") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=location,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][15] . "</a></th>"; echo "<th>" . (strstr($sort, "state") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=state,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['state'][0] . "</a></th>"; echo "<th>" . (strstr($sort, "groupe") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=groupe,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][35] . "</a></th>"; echo "<th>" . (strstr($sort, "username") ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=username,compname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['common'][34] . "</a></th>"; echo "<th>" . ($sort == "`lname`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort=lname&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>" . $LANG['software'][11] . "</a></th>"; echo "</tr>\n"; do { addToNavigateListItems('Computer', $data["cID"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td><input type='checkbox' name='item[" . $data["id"] . "]' value='1'></td>"; } if ($crit == "softwares_id") { echo "<td><a href='softwareversion.form.php?id=" . $data['vID'] . "'>" . $data['version']; echo "</a></td>"; } $compname = $data['compname']; if (empty($compname) || $_SESSION['glpiis_ids_visible']) { $compname .= " (" . $data['cID'] . ")"; } if ($canshowcomputer) { echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>"; } else { echo "<td>" . $compname . "</td>"; } if ($showEntity) { echo "<td>" . (empty($data['entity']) ? $LANG['entity'][2] : $data['entity']) . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td>" . $data['otherserial'] . "</td>"; echo "<td>" . $data['location'] . "</td>"; echo "<td>" . $data['state'] . "</td>"; echo "<td>" . $data['groupe'] . "</td>"; echo "<td>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>"; $lics = Computer_SoftwareLicense::GetLicenseForInstallation($data['cID'], $data['vID']); echo "<td>"; if (count($lics)) { foreach ($lics as $data) { echo "<a href='softwarelicense.form.php?id=" . $data['id'] . "'>" . $data['name']; echo "</a> - " . $data['serial']; if (!empty($data['type'])) { echo " (" . $data['type'] . ")"; } echo "<br>"; } } echo "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo "</table>\n"; if ($canedit) { openArrowMassive("softinstall" . $rand . "", true); SoftwareVersion::dropdown(array('name' => 'versionID', 'softwares_id' => $softwares_id)); echo " <input type='submit' name='moveinstalls' value='" . $LANG['buttons'][20] . "' class='submit'> "; closeArrowMassive('deleteinstalls', $LANG['buttons'][6]); echo "</form>"; } } else { // Not found echo $LANG['search'][15]; } } // Query echo "</div>\n"; }
/** * Display a reservation * * @param $ID ID a the reservation item * @param $date date to display **/ static function displayReservationsForAnItem($ID, $date) { global $DB; $users_id = Session::getLoginUserID(); $resa = new self(); $user = new User(); list($year, $month, $day) = explode("-", $date); $debut = $date . " 00:00:00"; $fin = $date . " 23:59:59"; $query = "SELECT *\n FROM `glpi_reservations`\n WHERE '" . $debut . "' < `end`\n AND '" . $fin . "' > `begin`\n AND `reservationitems_id` = '{$ID}'\n ORDER BY `begin`"; if ($result = $DB->query($query)) { if ($DB->numrows($result) > 0) { echo "<table width='100%'>"; while ($row = $DB->fetch_assoc($result)) { echo "<tr>"; $user->getFromDB($row["users_id"]); $display = ""; if ($debut > $row['begin']) { $heure_debut = "00:00"; } else { $heure_debut = get_hour_from_sql($row['begin']); } if ($fin < $row['end']) { $heure_fin = "24:00"; } else { $heure_fin = get_hour_from_sql($row['end']); } if (strcmp($heure_debut, "00:00") == 0 && strcmp($heure_fin, "24:00") == 0) { $display = __('Day'); } else { if (strcmp($heure_debut, "00:00") == 0) { $display = sprintf(__('To %s'), $heure_fin); } else { if (strcmp($heure_fin, "24:00") == 0) { $display = sprintf(__('From %s'), $heure_debut); } else { $display = $heure_debut . "-" . $heure_fin; } } } $rand = mt_rand(); $modif = $modif_end = ""; if ($resa->canEdit($row['id'])) { $modif = "<a id='content_" . $ID . $rand . "'\n href='reservation.form.php?id=" . $row['id'] . "'>"; $modif_end = "</a>"; $modif_end .= Html::showToolTip($row["comment"], array('applyto' => "content_" . $ID . $rand, 'display' => false)); } echo "<td class='tab_resa center'>" . $modif . "<span>" . $display . "<br><span class='b'>" . formatUserName($user->fields["id"], $user->fields["name"], $user->fields["realname"], $user->fields["firstname"]); echo "</span></span>"; echo $modif_end; echo "</td></tr>\n"; } echo "</table>\n"; } } }
/** * Print a nice HTML head for help page * * @param $title title of the page * @param $url not used anymore (default '') **/ static function helpHeader($title, $url = '') { global $CFG_GLPI, $HEADER_LOADED, $PLUGIN_HOOKS, $DB; // Print a nice HTML-head for help page if ($HEADER_LOADED) { return; } $HEADER_LOADED = true; self::includeHeader($title); // Body echo "<body>"; echo ' <nav class="navbar navbar-default" id="menuHeader"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="' . $CFG_GLPI["root_doc"] . '/front/central.php"> <img src="' . $CFG_GLPI["root_doc"] . '/pics/fd_logo1.png" style="margin-top:-4px;" /> <span class=\'invisible\'>Logo</span> </a> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav">'; echo "<li id='menu1'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' title=\"" . __s('Home') . "\" class='itemP'>" . __('Home') . "</a>"; echo "</li>"; // Create ticket if (Session::haveRight("ticket", CREATE)) { echo "<li id='menu2'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1' " . "title=\"" . __s('Create a ticket') . "\" class='itemP'>" . __('Create a ticket') . "</a>"; echo "</li>"; } // Suivi ticket if (Session::haveRight("ticket", Ticket::READMY) || Session::haveRight("followup", TicketFollowup::SEEPUBLIC)) { echo "<li id='menu3'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php' title=\"" . __s('Ticket followup') . "\" class='itemP'>" . _n('Ticket', 'Tickets', Session::getPluralNumber()) . "</a>"; echo "</li>"; } // Reservation if (Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { echo "<li id='menu4'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.php' title=\"" . _sn('Reservation', 'Reservations', Session::getPluralNumber()) . "\" class='itemP'>" . _n('Reservation', 'Reservations', Session::getPluralNumber()) . "</a>"; echo "</li>"; } // FAQ if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) { echo "<li id='menu5' >"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.faq.php' title=\"" . __s('FAQ') . "\" class='itemP'>" . __('FAQ') . "</a>"; echo "</li>"; } // PLUGINS $plugins = array(); if (isset($PLUGIN_HOOKS["helpdesk_menu_entry"]) && count($PLUGIN_HOOKS["helpdesk_menu_entry"])) { foreach ($PLUGIN_HOOKS["helpdesk_menu_entry"] as $plugin => $active) { if ($active) { $plugins[$plugin] = Plugin::getInfo($plugin); } } } if (isset($plugins) && count($plugins) > 0) { $list = array(); foreach ($plugins as $key => $val) { $list[$key] = $val["name"]; } asort($list); //echo "<li id='menu5' onmouseover=\"javascript:menuAff('menu5','menu');\">"; echo "<li id='menu5'>"; echo "<a href='#' title=\"" . _sn('Plugin', 'Plugins', Session::getPluralNumber()) . "\" class='itemP'>" . __('Plugins') . "</a>"; // default none echo "<ul class='ssmenu'>"; // list menu item foreach ($list as $key => $val) { $link = ""; if (is_string($PLUGIN_HOOKS["helpdesk_menu_entry"][$key])) { $link = $PLUGIN_HOOKS["helpdesk_menu_entry"][$key]; } echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/plugins/" . $key . $link . "'>" . $plugins[$key]["name"] . "</a></li>\n"; } echo "</ul></li>"; } echo "<div class='sep'></div>"; echo '</ul>'; echo '<ul class="nav navbar-nav navbar-right">'; $sql_photo2 = "SELECT picture\n\t\t\t\t\t\t\t\tFROM glpi_users\n\t\t\t\t\t\t\t\tWHERE id = " . $_SESSION["glpiID"] . " "; $res_photo2 = $DB->query($sql_photo2); $pic2 = $DB->result($res_photo2, 0, 'picture'); $photo_url2 = User::getURLForPicture($pic2); echo '<li class="dropdown">'; echo '<a href="#" style="padding:0px; margin:0px;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><img src="' . $photo_url2 . '" class="avatar" alt="" title="' . formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"], 0, 20) . '" /></a>'; echo "<ul class=\"dropdown-menu\" role=\"menu\">"; echo "<li><a href='" . (empty($CFG_GLPI["central_doc_url"]) ? "http://glpi-project.org/help-central" : $CFG_GLPI["central_doc_url"]) . "' target='_blank' title=\"" . __s('Help') . "\"><i class='fa fa-question-circle'></i> " . __('Help') . "</a></li>"; echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php' title=\"" . __s('My settings') . "\"><i class='fa fa-cog'></i> " . __('My settings') . "</a></li>"; echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php' title=\"" . addslashes(Dropdown::getLanguageName($_SESSION['glpilanguage'])) . "\"><i class='fa fa-flag'></i> " . Dropdown::getLanguageName($_SESSION['glpilanguage']) . "</a></li>"; echo "<li id='deconnexion'><a href='" . $CFG_GLPI["root_doc"] . "/front/logout.php"; // logout witout noAuto login for extauth if (isset($_SESSION['glpiextauth']) && $_SESSION['glpiextauth']) { echo "?noAUTO=1"; } echo "' title=\"" . __s('Logout') . "\"><i class='fa fa-lock'></i> " . __('Logout') . "</a>"; // check user id : header used for display messages when session logout if (Session::getLoginUserID()) { //echo " ("; // echo formatUserName (0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"], 0, 20); // echo ")"; } echo "</li>\n"; echo "</ul>"; echo ' </li>'; echo ' </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> '; echo '<nav class="navbar navbar-default nav2" style="margin-top: -20px;">'; // Display item echo "<div id='c_ssmenu2'>"; echo "<ul>"; echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' title=\"" . __s('Home') . "\">" . __('Home') . "></a></li>"; echo "<li> </li>"; if (Session::haveRightsOr('ticketvalidation', array(TicketValidation::VALIDATEREQUEST, TicketValidation::VALIDATEINCIDENT))) { $opt = array(); $opt['reset'] = 'reset'; $opt['criteria'][0]['field'] = 55; // validation status $opt['criteria'][0]['searchtype'] = 'equals'; $opt['criteria'][0]['value'] = TicketValidation::WAITING; $opt['criteria'][0]['link'] = 'AND'; $opt['criteria'][1]['field'] = 59; // validation aprobator $opt['criteria'][1]['searchtype'] = 'equals'; $opt['criteria'][1]['value'] = Session::getLoginUserID(); $opt['criteria'][1]['link'] = 'AND'; $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($opt, '&'); $pic_validate = "<a href='{$url_validate}'>" . "<img title=\"" . __s('Ticket waiting for your approval') . "\" alt=\"" . __s('Ticket waiting for your approval') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png'></a>"; echo "<li>{$pic_validate}</li>\n"; } echo "<li> </li>"; if (Session::haveRight('ticket', CREATE) && strpos($_SERVER['PHP_SELF'], "ticket")) { echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/menu_add.png' title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"></a></li>"; } echo "<li> </li>"; /// Bookmark load echo "<li>"; Ajax::createIframeModalWindow('loadbookmark', $CFG_GLPI["root_doc"] . "/front/bookmark.php?action=load", array('title' => __('Load a bookmark'), 'reloadonclose' => true)); echo "<a href='#' onClick=\"" . Html::jsGetElementbyID('loadbookmark') . ".dialog('open');\"\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/bookmark.png' title=\"" . __s('Load a bookmark') . "\" alt=\"" . __s('Load a bookmark') . "\">"; echo "</a></li>"; // check user id : header used for display messages when session logout if (Session::getLoginUserID()) { self::showProfileSelecter($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php"); } echo "</ul></div>"; //end c_ssmenu2 Html::scriptStart(); echo self::jsGetElementbyID('show_all_menu') . ".dialog({\n height: 'auto',\n width: 'auto',\n modal: true,\n autoOpen: false\n });"; echo Html::scriptEnd(); echo " "; // echo "</li>"; echo '</nav>'; }
public function generateOrder($params) { global $DB; $ID = $params['id']; $template = $params['template']; $signature = $params['sign']; if ($template) { $config = array('PATH_TO_TMP' => GLPI_DOC_DIR . '/_tmp'); $odf = new Odtphp\Odf(PLUGIN_ORDER_TEMPLATE_DIR . "{$template}", $config); $this->getFromDB($ID); if (file_exists(PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php")) { include_once PLUGIN_ORDER_TEMPLATE_CUSTOM_DIR . "custom.php"; } if (function_exists("plugin_order_getCustomFieldsForODT")) { plugin_order_getCustomFieldsForODT($ID, $template, $odf, $signature); } else { $PluginOrderOrder_Item = new PluginOrderOrder_Item(); $PluginOrderReference_Supplier = new PluginOrderReference_Supplier(); try { $odf->setImage('logo', PLUGIN_ORDER_TEMPLATE_LOGO_DIR . '/logo.jpg'); } catch (\Odtphp\Exceptions\OdfException $e) { } $values = array(); $values['title_order'] = __("Order number", "order"); $values['num_order'] = $this->fields["num_order"]; $values['title_invoice_address'] = __("Invoice address", "order"); $values['comment_order'] = $this->fields["comment"]; $entity = new Entity(); $entity->getFromDB($this->fields["entities_id"]); $town = ''; if ($this->fields["entities_id"] != 0) { $name_entity = $entity->fields["name"]; } else { $name_entity = __("Root entity"); } $values['entity_name'] = $name_entity; if ($entity->getFromDB($this->fields["entities_id"])) { $town = $entity->fields["town"]; $values['entity_address'] = $entity->fields["address"]; $values['entity_postcode'] = $entity->fields["postcode"]; $values['entity_town'] = $entity->fields["town"]; $values['entity_country'] = $entity->fields["country"]; } $supplier = new Supplier(); if ($supplier->getFromDB($this->fields["suppliers_id"])) { $values['supplier_name'] = $supplier->fields["name"]; $values['supplier_address'] = $supplier->fields["address"]; $values['supplier_postcode'] = $supplier->fields["postcode"]; $values['supplier_town'] = $supplier->fields["town"]; $values['supplier_country'] = $supplier->fields["country"]; } $location = new Location(); if ($location->getFromDB($this->fields["locations_id"])) { $values['title_delivery_address'] = __("Delivery address", "order"); $values['comment_delivery_address'] = $location->fields['comment']; } if ($town) { $town = $town . ", "; } $order_date = Html::convDate($this->fields["order_date"]); $username = Html::clean(getUserName(Session::getLoginUserID())); $values['title_date_order'] = $town . __("The", "order") . " "; $values['date_order'] = $order_date; $values['title_sender'] = __("Issuer order", "order"); $values['sender'] = $username; $values['title_budget'] = __("Budget"); $budget = new Budget(); if ($budget->getFromDB($this->fields["budgets_id"])) { $values['budget'] = $budget->fields['name']; } else { $values['budget'] = ''; } $output = ''; $contact = new Contact(); if ($contact->getFromDB($this->fields["contacts_id"])) { $output = formatUserName($contact->fields["id"], "", $contact->fields["name"], $contact->fields["firstname"]); } $values['title_recipient'] = __("Recipient", "order"); $values['recipient'] = Html::clean($output); $values['nb'] = __("Quantity", "order"); $values['title_item'] = __("Designation", "order"); $values['title_ref'] = __("Reference"); $values['HTPrice_item'] = __("Unit price", "order"); $values['TVA_item'] = __("VAT", "order"); $values['title_discount'] = __("Discount rate", "order"); $values['HTPriceTotal_item'] = __("Sum tax free", "order"); $values['ATIPriceTotal_item'] = __("Price ATI", "order"); $listeArticles = array(); $result = $PluginOrderOrder_Item->queryDetail($ID); $num = $DB->numrows($result); while ($data = $DB->fetch_array($result)) { $quantity = $PluginOrderOrder_Item->getTotalQuantityByRefAndDiscount($ID, $data["id"], $data["price_taxfree"], $data["discount"]); $listeArticles[] = array('quantity' => $quantity, 'ref' => utf8_decode($data["name"]), 'taxe' => Dropdown::getDropdownName(getTableForItemType("PluginOrderOrderTax"), $data["plugin_order_ordertaxes_id"]), 'refnumber' => $PluginOrderReference_Supplier->getReferenceCodeByReferenceAndSupplier($data["id"], $this->fields["suppliers_id"]), 'price_taxfree' => $data["price_taxfree"], 'discount' => $data["discount"], false, 0, 'price_discounted' => $data["price_discounted"] * $quantity, 'price_ati' => $data["price_ati"]); } $article = $odf->setSegment('articles'); foreach ($listeArticles as $element) { $article->nbA($element['quantity']); $article->titleArticle($element['ref']); $article->refArticle($element['refnumber']); $article->TVAArticle($element['taxe']); $article->HTPriceArticle(Html::clean(Html::formatNumber($element['price_taxfree']))); if ($element['discount'] != 0) { $article->discount(Html::clean(Html::formatNumber($element['discount'])) . " %"); } else { $article->discount(""); } $article->HTPriceTotalArticle(Html::clean(Html::formatNumber($element['price_discounted']))); $total_TTC_Article = $element['price_discounted'] * (1 + $element['taxe'] / 100); $article->ATIPriceTotalArticle(Html::clean(Html::formatNumber($total_TTC_Article))); $article->merge(); } $odf->mergeSegment($article); $prices = $PluginOrderOrder_Item->getAllPrices($ID); // total price (with postage) $postagewithTVA = $PluginOrderOrder_Item->getPricesATI($this->fields["port_price"], Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])); $total_HT = $prices["priceHT"] + $this->fields["port_price"]; $total_TVA = $prices["priceTVA"] + $postagewithTVA - $this->fields["port_price"]; $total_TTC = $prices["priceTTC"] + $postagewithTVA; if ($signature) { try { $odf->setImage('sign', PLUGIN_ORDER_SIGNATURE_DIR . $signature); } catch (\Odtphp\Exceptions\OdfException $e) { } } else { try { $odf->setImage('sign', '../pics/nothing.gif'); } catch (\Odtphp\Exceptions\OdfException $e) { } } $name = Dropdown::getDropdownName("glpi_plugin_order_orderpayments", $this->fields["plugin_order_orderpayments_id"]); $values['title_totalht'] = __("Price tax free", "order"); $values['totalht'] = Html::clean(Html::formatNumber($prices['priceHT'])); $values['title_port'] = __("Price tax free with postage", "order"); $values['totalht_port_price'] = Html::clean(Html::formatNumber($total_HT)); $values['title_price_port'] = __("Postage", "order"); $values['price_port_tva'] = " (" . Html::clean(Dropdown::getDropdownName("glpi_plugin_order_ordertaxes", $this->fields["plugin_order_ordertaxes_id"])) . "%)"; $values['port_price'] = Html::clean(Html::formatNumber($postagewithTVA)); $values['title_tva'] = __("VAT", "order"); $values['totaltva'] = Html::clean(Html::formatNumber($total_TVA)); $values['title_totalttc'] = __("Price ATI", "order"); $values['totalttc'] = Html::clean(Html::formatNumber($total_TTC)); $values['title_money'] = __("€", "order"); $values['title_sign'] = __("Signature of issuing order", "order"); $values['title_conditions'] = __("Payment conditions", "order"); $values['payment_conditions'] = $name; // Set variables in odt template foreach ($values as $field => $val) { try { $odf->setVars($field, $val, true, 'UTF-8'); } catch (\Odtphp\Exceptions\OdfException $e) { } } } $message = "_"; if (Session::isMultiEntitiesMode()) { $entity = new Entity(); $entity->getFromDB($this->fields['entities_id']); $message .= $entity->getName(); } $message .= "_" . $this->fields['num_order'] . "_"; $message .= Html::convDateTime($_SESSION['glpi_currenttime']); $message = str_replace(" ", "_", $message); $outputfile = str_replace(".odt", $message . ".odt", $template); // We export the file $odf->exportAsAttachedFile($outputfile); } }
/** * * Note : can separe code of view list * @param PluginTagTag $tag * @return boolean */ static function showForTag(PluginTagTag $tag) { global $DB; $instID = $tag->fields['id']; if (!$tag->can($instID, READ)) { return false; } $canedit = $tag->can($instID, UPDATE); $table = getTableForItemType(__CLASS__); $result = $DB->query("SELECT DISTINCT `itemtype`\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $result2 = $DB->query("SELECT `itemtype`, items_id\n FROM `{$table}`\n WHERE `plugin_tag_tags_id` = '{$instID}'"); $number = $DB->numrows($result); $rand = mt_rand(); if ($canedit) { echo "<div class='firstbloc'>"; //can use standart GLPI function $target = Toolbox::getItemTypeFormURL('PluginTagTag'); echo "<form name='tagitem_form{$rand}' id='tagitem_form{$rand}' method='post' action='" . $target . "'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2'><th colspan='2'>" . __('Add an item') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='right'>"; //Note : this function is deprecated (and replace by an other) $itemtypes_to_show = self::getItemtypes($tag->fields['type_menu']); Dropdown::showAllItems("items_id", 0, 0, $tag->fields['is_recursive'] ? -1 : $tag->fields['entities_id'], $itemtypes_to_show, false, true); echo "<style>.select2-container { text-align: left; } </style>"; //minor echo "</td><td class='center'>"; echo "<input type='hidden' name='plugin_tag_tags_id' value='{$instID}'>"; //Note : can use standart GLPI method echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); echo "</div>"; } echo "<div class='spaced'>"; if ($canedit && $number) { Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); Html::showMassiveActions(); } echo "<table class='tab_cadre_fixe'>"; echo "<tr>"; if ($canedit && $number) { echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>"; } echo "<th>" . __('Type') . "</th>"; echo "<th>" . __('Name') . "</th>"; echo "<th>" . __('Entity') . "</th>"; echo "<th>" . __('Serial number') . "</th>"; echo "<th>" . __('Inventory number') . "</th>"; echo "</tr>"; for ($i = 0; $i < $number; $i++) { $itemtype = $DB->result($result, $i, "itemtype"); if (!($item = getItemForItemtype($itemtype))) { continue; } $item_id = $DB->result($result2, $i, "items_id"); if ($item->canView()) { $column = strtolower(substr($itemtype, 0, 6)) == "device" ? "designation" : "name"; // For rules itemtypes (example : ruledictionnaryphonemodel) if (strtolower(substr($itemtype, 0, 4)) == 'rule' || $itemtype == "PluginResourcesRulechecklist") { $itemtable = getTableForItemType('Rule'); } else { $itemtable = getTableForItemType($itemtype); } $obj = new $itemtype(); $obj->getFromDB($item_id); $query = "SELECT `{$itemtable}`.*, `glpi_plugin_tag_tagitems`.`id` AS IDD, "; switch ($itemtype) { case 'KnowbaseItem': $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n " . KnowbaseItem::addVisibilityJoins() . "\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': //Possible to add (in code) condition to visibility : $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; break; default: if (isset($obj->fields['entities_id'])) { $query .= "`glpi_entities`.`id` AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n LEFT JOIN `glpi_entities`\n ON (`glpi_entities`.`id` = `{$itemtable}`.`entities_id`)\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } else { $query .= "-1 AS entity\n FROM `glpi_plugin_tag_tagitems`, `{$itemtable}`\n WHERE `{$itemtable}`.`id` = `glpi_plugin_tag_tagitems`.`items_id`\n AND "; } break; } $query .= "`glpi_plugin_tag_tagitems`.`itemtype` = '{$itemtype}'\n AND `glpi_plugin_tag_tagitems`.`plugin_tag_tags_id` = '{$instID}' "; $query .= getEntitiesRestrictRequest(" AND ", $itemtable, '', '', $item->maybeRecursive()); if ($item->maybeTemplate()) { $query .= " AND `{$itemtable}`.`is_template` = '0'"; } switch ($itemtype) { case 'KnowbaseItem': case 'Profile': case 'RSSFeed': case 'Reminder': case 'Entity': $query .= " ORDER BY `{$itemtable}`.`{$column}`"; break; default: if (isset($obj->fields['entities_id'])) { $query .= " ORDER BY `glpi_entities`.`completename`, `{$itemtable}`.`{$column}`"; } else { $query .= " ORDER BY `{$itemtable}`.`{$column}`"; } break; } if ($result_linked = $DB->query($query)) { if ($DB->numrows($result_linked)) { while ($data = $DB->fetch_assoc($result_linked)) { if ($itemtype == 'Softwarelicense') { $soft = new Software(); $soft->getFromDB($data['softwares_id']); $data["name"] .= ' - ' . $soft->getName(); //This add name of software } elseif ($itemtype == "PluginResourcesResource") { $data["name"] = formatUserName($data["id"], "", $data["name"], $data["firstname"]); } $linkname = $data[$column]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$column])) { $linkname = sprintf(__('%1$s (%2$s)'), $linkname, $data["id"]); } $name = "<a href=\"" . Toolbox::getItemTypeFormURL($itemtype) . "?id=" . $data["id"] . "\">" . $linkname . "</a>"; if ($itemtype == 'PluginProjetProjet' || $itemtype == 'PluginResourcesResource') { $pieces = preg_split('/(?=[A-Z])/', $itemtype); $plugin_name = $pieces[2]; $datas = array("entities_id" => $data["entity"], "ITEM_0" => $data["name"], "ITEM_0_2" => $data["id"], "id" => $data["id"], "META_0" => $data["name"]); //for PluginResourcesResource if (isset($data["is_recursive"])) { $datas["is_recursive"] = $data["is_recursive"]; } Plugin::load(strtolower($plugin_name), true); $function_giveitem = 'plugin_' . strtolower($plugin_name) . '_giveItem'; if (function_exists($function_giveitem)) { // For security $name = call_user_func($function_giveitem, $itemtype, 1, $datas, 0); } } echo "<tr class='tab_bg_1'>"; if ($canedit) { echo "<td width='10'>"; if ($item->canUpdate()) { Html::showMassiveActionCheckBox(__CLASS__, $data["IDD"]); } echo "</td>"; } echo "<td class='center'>"; // Show plugin name (is to delete remove any ambiguity) : $pieces = preg_split('/(?=[A-Z])/', $itemtype); if ($pieces[1] == 'Plugin') { $plugin_name = $pieces[2]; if (function_exists("plugin_version_" . $plugin_name)) { // For security $tab = call_user_func("plugin_version_" . $plugin_name); echo $tab["name"] . " : "; } } echo $item->getTypeName(1) . "</td>"; echo "<td " . (isset($data['is_deleted']) && $data['is_deleted'] ? "class='tab_bg_2_2'" : "") . ">" . $name . "</td>"; echo "<td class='center'>"; $entity = $data['entity']; //for Plugins : if ($data["entity"] == -1) { $item->getFromDB($data['id']); if (isset($item->fields["entities_id"])) { $entity = $item->fields["entities_id"]; } } echo Dropdown::getDropdownName("glpi_entities", $entity); echo "</td>"; echo "<td class='center'>" . (isset($data["serial"]) ? "" . $data["serial"] . "" : "-") . "</td>"; echo "<td class='center'>" . (isset($data["otherserial"]) ? "" . $data["otherserial"] . "" : "-") . "</td>"; echo "</tr>"; } } } } } echo "</table>"; if ($canedit && $number) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "</div>"; }
/** * @see CommonDBTM::getRawName() **/ function getRawName() { if (isset($this->fields["id"]) && $this->fields["id"] > 0) { return formatUserName($this->fields["id"], $this->fields["name"], isset($this->fields["realname"]) ? $this->fields["realname"] : '', isset($this->fields["firstname"]) ? $this->fields["firstname"] : ''); } return ''; }
/** * Print a nice HTML head for help page * * @param $title title of the page * @param $url not used anymore (default '') **/ static function helpHeader($title, $url = '') { global $CFG_GLPI, $HEADER_LOADED, $PLUGIN_HOOKS; // Print a nice HTML-head for help page if ($HEADER_LOADED) { return; } $HEADER_LOADED = true; self::includeHeader($title); // Body $body_class = "layout_" . $_SESSION['glpilayout']; if (strpos($_SERVER['REQUEST_URI'], "form.php") !== false && isset($_GET['id']) && $_GET['id'] > 0) { if (!CommonGLPI::isLayoutExcludedPage()) { $body_class .= " form"; } else { $body_class = ""; } } echo "<body class='{$body_class}'>"; // Main Headline echo "<div id='header'>"; echo "<div id='header_top'>"; echo "<div id='c_logo'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' accesskey='1' title=\"" . __s('Home') . "\"><span class='invisible'>Logo</span></a>"; echo "</div>"; // Les préférences + lien déconnexion echo "<div id='c_preference' >"; echo "<ul>"; echo "<li id='deconnexion'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/logout.php"; /// logout witout noAuto login for extauth if (isset($_SESSION['glpiextauth']) && $_SESSION['glpiextauth']) { echo "?noAUTO=1"; } echo "' title=\"" . __s('Logout') . "\">"; // check user id : header used for display messages when session logout echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/logout.png' title=\"" . __s('Logout') . "\" alt=\"" . __s('Logout') . "\" class='button-icon'>"; echo "</a>"; echo "</li>\n"; echo "<li id='preferences_link'><a href='" . $CFG_GLPI["root_doc"] . "/front/preference.php' title=\"" . __s('My settings') . "\">"; echo "<span id='preferences_icon' title=\"" . __s('My settings') . "\" alt=\"" . __s('My settings') . "\" class='button-icon' /></span>"; // check user id : header used for display messages when session logout if (Session::getLoginUserID()) { echo "<span id='myname'>"; echo formatUserName(0, $_SESSION["glpiname"], $_SESSION["glpirealname"], $_SESSION["glpifirstname"], 0, 20); echo "</span>"; } echo "</a></li>"; echo "<li>"; Ajax::createIframeModalWindow('loadbookmark', $CFG_GLPI["root_doc"] . "/front/bookmark.php?action=load", array('title' => __('Load a bookmark'), 'reloadonclose' => true)); echo "<a href='#' onClick=\"" . Html::jsGetElementbyID('loadbookmark') . ".dialog('open');\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/bookmark.png' title=\"" . __s('Load a bookmark') . "\" alt=\"" . __s('Load a bookmark') . "\" class='button-icon'>"; echo "</a></li>"; echo "<li id='help_link'>" . "<a href='" . (empty($CFG_GLPI["helpdesk_doc_url"]) ? "http://glpi-project.org/help-helpdesk" : $CFG_GLPI["helpdesk_doc_url"]) . "' target='_blank' title=\"" . __s('Help') . "\">" . "<img src='" . $CFG_GLPI["root_doc"] . "/pics/help.png' title=\"" . __s('Help') . "\" alt=\"" . __s('Help') . "\" class='button-icon'>"; "</a></li>"; echo "</ul>"; echo "</div>"; //-- Le moteur de recherche -- echo "<div id='c_recherche'></div>"; echo "</div>"; //-- Le menu principal -- echo "<div id='c_menu'>"; echo "<ul id='menu'>"; // Build the navigation-elements // Home echo "<li id='menu1'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' title=\"" . __s('Home') . "\" class='itemP'>" . __('Home') . "</a>"; echo "</li>"; // Create ticket if (Session::haveRight("ticket", CREATE)) { echo "<li id='menu2'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1' " . "title=\"" . __s('Create a ticket') . "\" class='itemP'>" . __('Create a ticket') . "</a>"; echo "</li>"; } // Suivi ticket if (Session::haveRight("ticket", Ticket::READMY) || Session::haveRight("followup", TicketFollowup::SEEPUBLIC)) { echo "<li id='menu3'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/ticket.php' title=\"" . __s('Ticket followup') . "\" class='itemP'>" . _n('Ticket', 'Tickets', Session::getPluralNumber()) . "</a>"; echo "</li>"; } // Reservation if (Session::haveRight("reservation", ReservationItem::RESERVEANITEM)) { echo "<li id='menu4'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.php' title=\"" . _sn('Reservation', 'Reservations', Session::getPluralNumber()) . "\" class='itemP'>" . _n('Reservation', 'Reservations', Session::getPluralNumber()) . "</a>"; echo "</li>"; } // FAQ if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) { echo "<li id='menu5' >"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.faq.php' title=\"" . __s('FAQ') . "\" class='itemP'>" . __('FAQ') . "</a>"; echo "</li>"; } // PLUGINS $plugins = array(); if (isset($PLUGIN_HOOKS["helpdesk_menu_entry"]) && count($PLUGIN_HOOKS["helpdesk_menu_entry"])) { foreach ($PLUGIN_HOOKS["helpdesk_menu_entry"] as $plugin => $active) { if ($active) { $plugins[$plugin] = Plugin::getInfo($plugin); } } } if (isset($plugins) && count($plugins) > 0) { $list = array(); foreach ($plugins as $key => $val) { $list[$key] = $val["name"]; } asort($list); echo "<li id='menu5' onmouseover=\"javascript:menuAff('menu5','menu');\">"; echo "<a href='#' title=\"" . _sn('Plugin', 'Plugins', Session::getPluralNumber()) . "\" class='itemP'>" . __('Plugins') . "</a>"; // default none echo "<ul class='ssmenu'>"; // list menu item foreach ($list as $key => $val) { $link = ""; if (is_string($PLUGIN_HOOKS["helpdesk_menu_entry"][$key])) { $link = $PLUGIN_HOOKS["helpdesk_menu_entry"][$key]; } echo "<li><a href='" . $CFG_GLPI["root_doc"] . "/plugins/" . $key . $link . "'>" . $plugins[$key]["name"] . "</a></li>\n"; } echo "</ul></li>"; } echo "</ul>"; echo "</div>"; // End navigation bar // End headline // Le fil d ariane echo "<div id='c_ssmenu2'>"; echo "<ul>"; echo "<li class='breadcrumb_item'>" . "<a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php' title=\"" . __s('Home') . "\">" . __('Home') . "</a></li>"; if (TicketValidation::getValidateRights()) { $opt = array(); $opt['reset'] = 'reset'; $opt['criteria'][0]['field'] = 55; // validation status $opt['criteria'][0]['searchtype'] = 'equals'; $opt['criteria'][0]['value'] = TicketValidation::WAITING; $opt['criteria'][0]['link'] = 'AND'; $opt['criteria'][1]['field'] = 59; // validation aprobator $opt['criteria'][1]['searchtype'] = 'equals'; $opt['criteria'][1]['value'] = Session::getLoginUserID(); $opt['criteria'][1]['link'] = 'AND'; $url_validate = $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($opt, '&'); $pic_validate = "<a href='{$url_validate}'>" . "<img title=\"" . __s('Ticket waiting for your approval') . "\" alt=\"" . __s('Ticket waiting for your approval') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/menu_showall.png' class='pointer'></a>"; echo "<li class='icons_block'>{$pic_validate}</li>\n"; } if (Session::haveRight('ticket', CREATE) && strpos($_SERVER['PHP_SELF'], "ticket")) { echo "<li class='icons_block'><a href='" . $CFG_GLPI["root_doc"] . "/front/helpdesk.public.php?create_ticket=1'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/menu_add.png' title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\" class='pointer'></a></li>"; } // check user id : header used for display messages when session logout if (Session::getLoginUserID()) { self::showProfileSelecter($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php"); } echo "</ul></div>"; echo "</div>"; // fin header echo "<div id='page' >"; // call static function callcron() every 5min CronTask::callCron(); self::displayMessageAfterRedirect(); }
/** Get users which have followup assigned to between 2 dates * * @param $date1 date : begin date (default '') * @param $date2 date : end date (default '') * * @return array contains the distinct users which have any followup assigned to. **/ function getUsedTechTaskBetween($date1 = '', $date2 = '') { global $DB; $tasktable = getTableForItemType($this->getType() . 'Task'); $showlink = User::canView(); $query = "SELECT DISTINCT `glpi_users`.`id` AS users_id,\n `glpi_users`.`name` AS name,\n `glpi_users`.`realname` AS realname,\n `glpi_users`.`firstname` AS firstname\n FROM `" . $this->getTable() . "`\n LEFT JOIN `{$tasktable}`\n ON (`" . $this->getTable() . "`.`id` = `{$tasktable}`.`" . $this->getForeignKeyField() . "`)\n LEFT JOIN `glpi_users` ON (`glpi_users`.`id` = `{$tasktable}`.`users_id`)\n LEFT JOIN `glpi_profiles_users`\n ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)\n LEFT JOIN `glpi_profiles`\n ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n LEFT JOIN `glpi_profilerights`\n ON (`glpi_profiles`.`id` = `glpi_profilerights`.`profiles_id`)\n WHERE NOT `" . $this->getTable() . "`.`is_deleted` " . getEntitiesRestrictRequest("AND", $this->getTable()); if (!empty($date1) || !empty($date2)) { $query .= " AND (" . getDateRequest("`" . $this->getTable() . "`.`date`", $date1, $date2) . "\n OR " . getDateRequest("`" . $this->getTable() . "`.`closedate`", $date1, $date2) . ") "; } $query .= " AND `glpi_profilerights`.`name` = 'ticket'\n AND (`glpi_profilerights`.`rights` & " . Ticket::OWN . ")\n AND `{$tasktable}`.`users_id` <> '0'\n AND `{$tasktable}`.`users_id` IS NOT NULL\n ORDER BY realname, firstname, name"; $result = $DB->query($query); $tab = array(); if ($DB->numrows($result) >= 1) { while ($line = $DB->fetch_assoc($result)) { $tmp['id'] = $line["users_id"]; $tmp['link'] = formatUserName($line["users_id"], $line["name"], $line["realname"], $line["firstname"], $showlink); $tab[] = $tmp; } } return $tab; }
/** * @see CommonDBTM::getName() **/ function getName($options = array()) { if (isset($this->fields["id"]) && $this->fields["id"] > 0) { return formatUserName($this->fields["id"], $this->fields["name"], isset($this->fields["realname"]) ? $this->fields["realname"] : '', isset($this->fields["firstname"]) ? $this->fields["firstname"] : ''); } return NOT_AVAILABLE; }
$_GET['page'] = 1; $_GET['page_limit'] = $CFG_GLPI['dropdown_max']; } if ($one_item < 0) { $start = ($_GET['page'] - 1) * $_GET['page_limit']; $result = User::getSqlSearchResult(false, $_GET['right'], $_GET["entity_restrict"], $_GET['value'], $used, $_GET['searchText'], $start, $_GET['page_limit']); } else { $query = "SELECT DISTINCT `glpi_users`.*\n FROM `glpi_users`\n WHERE `glpi_users`.`id` = '{$one_item}';"; $result = $DB->query($query); } $users = array(); // Count real items returned $count = 0; if ($DB->numrows($result)) { while ($data = $DB->fetch_assoc($result)) { $users[$data["id"]] = formatUserName($data["id"], $data["name"], $data["realname"], $data["firstname"]); $logins[$data["id"]] = $data["name"]; } } /* if (!function_exists('dpuser_cmp')) { function dpuser_cmp($a, $b) { return strcasecmp($a, $b); } } // Sort non case sensitive uasort($users, 'dpuser_cmp'); */ $datas = array(); // Display first if empty search
echo "<br><span id='show_list_users'> </span>\n"; break; case 'list_users': if (isset($_POST['users_id_validate']['groups_id'])) { $_POST['users_id_validate'] = array(); } $opt = array('groups_id' => $_POST["groups_id"], 'right' => $_POST['right'], 'entity' => $_POST["entity"]); $data_users = TicketValidation::getGroupUserHaveRights($opt); $users = array(); $param['values'] = array(); $values = array(); if (isset($_POST['users_id_validate']) && is_array($_POST['users_id_validate'])) { $values = $_POST['users_id_validate']; } foreach ($data_users as $data) { $users[$data['id']] = formatUserName($data['id'], $data['name'], $data['realname'], $data['firstname']); if (in_array($data['id'], $values)) { $param['values'][] = $data['id']; } } // Display all users if (isset($_POST['all_users']) && $_POST['all_users']) { $param['values'] = array_keys($users); } $param['multiple'] = true; $param['display'] = true; $param['size'] = count($users); $users = Toolbox::stripslashes_deep($users); $rand = Dropdown::showFromArray(!empty($_POST['name']) ? $_POST['name'] : 'users_id_validate', $users, $param); // Display all/none buttons to select all or no users in group if (!empty($_POST['groups_id'])) {
/** Get recipient of tickets between 2 dates * * @param $date1 date : begin date * @param $date2 date : end date * * @return array contains the distinct recipents which have tickets **/ function getUsedRecipientBetween($date1 = '', $date2 = '') { global $DB; $query = "SELECT DISTINCT `glpi_users`.`id` AS user_id,\n `glpi_users`.`name` AS name,\n `glpi_users`.`realname` AS realname,\n `glpi_users`.`firstname` AS firstname\n FROM `glpi_tickets`\n LEFT JOIN `glpi_users`\n ON (`glpi_users`.`id` = `glpi_tickets`.`users_id_recipient`) " . getEntitiesRestrictRequest("WHERE", "glpi_tickets"); if (!empty($date1) || !empty($date2)) { $query .= " AND (" . getDateRequest("`glpi_tickets`.`date`", $date1, $date2) . "\n OR " . getDateRequest("`glpi_tickets`.`closedate`", $date1, $date2) . ") "; } $query .= " ORDER BY realname, firstname, name"; $result = $DB->query($query); $tab = array(); if ($DB->numrows($result) >= 1) { while ($line = $DB->fetch_assoc($result)) { $tmp['id'] = $line["user_id"]; $tmp['link'] = formatUserName($line["user_id"], $line["name"], $line["realname"], $line["firstname"], 1); $tab[] = $tmp; } } return $tab; }
/** * Show computers linked to a License * * @param $license SoftwareLicense object * * @return nothing **/ static function showForLicense(SoftwareLicense $license) { global $DB, $CFG_GLPI; $searchID = $license->getField('id'); if (!Software::canView() || !$searchID) { return false; } $canedit = Session::haveRightsOr("software", array(CREATE, UPDATE, DELETE, PURGE)); $canshowcomputer = Computer::canView(); if (isset($_GET["start"])) { $start = $_GET["start"]; } else { $start = 0; } if (isset($_GET["order"]) && $_GET["order"] == "DESC") { $order = "DESC"; } else { $order = "ASC"; } if (isset($_GET["sort"]) && !empty($_GET["sort"])) { // manage several param like location,compname : order first $tmp = explode(",", $_GET["sort"]); $sort = "`" . implode("` {$order},`", $tmp) . "`"; } else { $sort = "`entity` {$order}, `compname`"; } //SoftwareLicense ID $query_number = "SELECT COUNT(*) AS cpt\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id`\n = `glpi_computers`.`id`)\n WHERE `glpi_computers_softwarelicenses`.`softwarelicenses_id` = '{$searchID}'" . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'"; $number = 0; if ($result = $DB->query($query_number)) { $number = $DB->result($result, 0, 0); } echo "<div class='center'>"; if ($canedit) { echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/computer_softwarelicense.form.php'>"; echo "<input type='hidden' name='softwarelicenses_id' value='{$searchID}'>"; echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_2 center'>"; echo "<td>"; Computer::dropdown(array('entity' => $license->fields['entities_id'], 'entity_sons' => $license->fields['is_recursive'])); echo "</td>"; echo "<td><input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>"; echo "</td></tr>"; echo "</table>"; Html::closeForm(); } if ($number < 1) { echo "<table class='tab_cadre_fixe'>"; echo "<tr><th>" . __('No item found') . "</th></tr>"; echo "</table></div>\n"; return; } // Display the pager Html::printAjaxPager(__('Affected computers'), $start, $number); $query = "SELECT `glpi_computers_softwarelicenses`.*,\n `glpi_computers`.`name` AS compname,\n `glpi_computers`.`id` AS cID,\n `glpi_computers`.`serial`,\n `glpi_computers`.`otherserial`,\n `glpi_users`.`name` AS username,\n `glpi_users`.`id` AS userid,\n `glpi_users`.`realname` AS userrealname,\n `glpi_users`.`firstname` AS userfirstname,\n `glpi_softwarelicenses`.`name` AS license,\n `glpi_softwarelicenses`.`id` AS vID,\n `glpi_softwarelicenses`.`name` AS vername,\n `glpi_entities`.`completename` AS entity,\n `glpi_locations`.`completename` AS location,\n `glpi_states`.`name` AS state,\n `glpi_groups`.`name` AS groupe,\n `glpi_softwarelicenses`.`name` AS lname,\n `glpi_softwarelicenses`.`id` AS lID,\n `glpi_softwarelicenses`.`softwares_id` AS softid\n FROM `glpi_computers_softwarelicenses`\n INNER JOIN `glpi_softwarelicenses`\n ON (`glpi_computers_softwarelicenses`.`softwarelicenses_id`\n = `glpi_softwarelicenses`.`id`)\n INNER JOIN `glpi_computers`\n ON (`glpi_computers_softwarelicenses`.`computers_id` = `glpi_computers`.`id`)\n LEFT JOIN `glpi_entities` ON (`glpi_computers`.`entities_id` = `glpi_entities`.`id`)\n LEFT JOIN `glpi_locations`\n ON (`glpi_computers`.`locations_id` = `glpi_locations`.`id`)\n LEFT JOIN `glpi_states` ON (`glpi_computers`.`states_id` = `glpi_states`.`id`)\n LEFT JOIN `glpi_groups` ON (`glpi_computers`.`groups_id` = `glpi_groups`.`id`)\n LEFT JOIN `glpi_users` ON (`glpi_computers`.`users_id` = `glpi_users`.`id`)\n WHERE (`glpi_softwarelicenses`.`id` = '{$searchID}') " . getEntitiesRestrictRequest(' AND', 'glpi_computers') . "\n AND `glpi_computers`.`is_deleted` = '0'\n AND `glpi_computers`.`is_template` = '0'\n AND `glpi_computers_softwarelicenses`.`is_deleted` = '0'\n ORDER BY {$sort} {$order}\n LIMIT " . intval($start) . "," . intval($_SESSION['glpilist_limit']); $rand = mt_rand(); if ($result = $DB->query($query)) { if ($data = $DB->fetch_assoc($result)) { if ($canedit) { $rand = mt_rand(); Html::openMassiveActionsForm('mass' . __CLASS__ . $rand); $massiveactionparams = array('num_displayed' => $_SESSION['glpilist_limit'], 'container' => 'mass' . __CLASS__ . $rand, 'specific_actions' => array('purge' => _x('button', 'Delete permanently'))); // show transfer only if multi licenses for this software if (self::countLicenses($data['softid']) > 1) { $massiveactionparams['specific_actions'][__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'move_license'] = _x('button', 'Move'); } // Options to update license $massiveactionparams['extraparams']['options']['move']['used'] = array($searchID); $massiveactionparams['extraparams']['options']['move']['softwares_id'] = $license->fields['softwares_id']; Html::showMassiveActions($massiveactionparams); } $soft = new Software(); $soft->getFromDB($license->fields['softwares_id']); $showEntity = $license->isRecursive(); $linkUser = User::canView(); $text = sprintf(__('%1$s = %2$s'), Software::getTypeName(1), $soft->fields["name"]); $text = sprintf(__('%1$s - %2$s'), $text, $data["vername"]); Session::initNavigateListItems('Computer', $text); $sort_img = "<img src='" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "' alt='' title=''>"; echo "<table class='tab_cadre_fixehov'>"; $columns = array('compname' => __('Name'), 'entity' => __('Entity'), 'serial' => __('Serial number'), 'otherserial' => __('Inventory number'), 'location,compname' => __('Location'), 'state,compname' => __('Status'), 'groupe,compname' => __('Group'), 'username,compname' => __('User')); if (!$showEntity) { unset($columns['entity']); } $sort_img = "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . ($order == "DESC" ? "puce-down.png" : "puce-up.png") . "\" alt='' title=''>"; $header_begin = "<tr>"; $header_top = ''; $header_bottom = ''; $header_end = ''; if ($canedit) { $header_begin .= "<th width='10'>"; $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand); $header_end .= "</th>"; } foreach ($columns as $key => $val) { // Non order column if ($key[0] == '_') { $header_end .= "<th>{$val}</th>"; } else { $header_end .= "<th>" . ($sort == "`{$key}`" ? $sort_img : "") . "<a href='javascript:reloadTab(\"sort={$key}&order=" . ($order == "ASC" ? "DESC" : "ASC") . "&start=0\");'>{$val}</a></th>"; } } $header_end .= "</tr>\n"; echo $header_begin . $header_top . $header_end; do { Session::addToNavigateListItems('Computer', $data["cID"]); echo "<tr class='tab_bg_2'>"; if ($canedit) { echo "<td>" . Html::getMassiveActionCheckBox(__CLASS__, $data["id"]) . "</td>"; } $compname = $data['compname']; if (empty($compname) || $_SESSION['glpiis_ids_visible']) { $compname = sprintf(__('%1$s (%2$s)'), $compname, $data['cID']); } if ($canshowcomputer) { echo "<td><a href='computer.form.php?id=" . $data['cID'] . "'>{$compname}</a></td>"; } else { echo "<td>" . $compname . "</td>"; } if ($showEntity) { echo "<td>" . $data['entity'] . "</td>"; } echo "<td>" . $data['serial'] . "</td>"; echo "<td>" . $data['otherserial'] . "</td>"; echo "<td>" . $data['location'] . "</td>"; echo "<td>" . $data['state'] . "</td>"; echo "<td>" . $data['groupe'] . "</td>"; echo "<td>" . formatUserName($data['userid'], $data['username'], $data['userrealname'], $data['userfirstname'], $linkUser) . "</td>"; echo "</tr>\n"; } while ($data = $DB->fetch_assoc($result)); echo $header_begin . $header_bottom . $header_end; echo "</table>\n"; if ($canedit) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } } else { // Not found _e('No item found'); } } // Query Html::printAjaxPager(__('Affected computers'), $start, $number); echo "</div>\n"; }