/** * Get all data needed for template processing **/ function getDatasForTemplate($event, $options = array()) { global $LANG, $CFG_GLPI; $this->datas['##contract.entity##'] = Dropdown::getDropdownName('glpi_entities', $options['entities_id']); $events = $this->getEvents(); $this->datas['##contract.action##'] = $LANG['mailing'][39] . " - " . $events[$event]; foreach ($options['contracts'] as $id => $contract) { $tmp = array(); $tmp['##contract.name##'] = $contract['name']; $tmp['##contract.number##'] = $contract['num']; if ($contract['contracttypes_id']) { $tmp['##contract.type##'] = Dropdown::getDropdownName('glpi_contracttypes', $contract['contracttypes_id']); } else { $tmp['##contract.type##'] = ""; } $tmp['##contract.time##'] = getWarrantyExpir($contract["begin_date"], $contract["duration"], $contract["notice"]); $tmp['##contract.url##'] = urldecode($CFG_GLPI["url_base"] . "/index.php?redirect=contract_" . $id); $this->datas['contracts'][] = $tmp; } $this->datas['##lang.contract.time##'] = $event == Alert::END ? $LANG['contract'][0] : $LANG['contract'][1]; $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }
echo "<td> " . convDate($data['buy_date']) . " </td>"; if ($data["warranty_duration"]) { echo "<td> " . getWarrantyExpir($data["buy_date"], $data["warranty_duration"]) . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } } else { echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>"; } if ($data['type']) { echo "<td class='b'> " . $data['type'] . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } if ($data['begin_date']) { echo "<td> " . convDate($data['begin_date']) . " </td>"; if ($data["duration"]) { echo "<td> " . getWarrantyExpir($data["begin_date"], $data["duration"]) . " </td>"; } else { echo "<td> " . NOT_AVAILABLE . " </td>"; } } else { echo "<td> " . NOT_AVAILABLE . " </td><td> " . NOT_AVAILABLE . " </td>"; } echo "</tr>\n"; } echo "</table><br><hr><br>"; } } } commonFooter();
/** Display an infocom report * * @param $itemtype item type * @param $begin begin date * @param $end end date **/ function display_infocoms_report($itemtype, $begin, $end) { global $DB, $valeurtot, $valeurnettetot, $valeurnettegraphtot, $valeurgraphtot, $LANG, $CFG_GLPI; $itemtable = getTableForItemType($itemtype); $query = "SELECT `glpi_infocoms`.*,\n `{$itemtable}`.`name` AS name,\n `{$itemtable}`.`ticket_tco`,\n `glpi_entities`.`completename` AS entname,\n `glpi_entities`.`id` AS entID\n FROM `glpi_infocoms`\n INNER JOIN `{$itemtable}` ON (`{$itemtable}`.`id` = `glpi_infocoms`.`items_id`\n AND `glpi_infocoms`.`itemtype` = '{$itemtype}')\n LEFT JOIN `glpi_entities` ON (`{$itemtable}`.`entities_id` = `glpi_entities`.`id`)\n WHERE `{$itemtable}`.`is_template` = '0' " . getEntitiesRestrictRequest("AND", $itemtable); if (!empty($begin)) { $query .= " AND (`glpi_infocoms`.`buy_date` >= '{$begin}'\n OR `glpi_infocoms`.`use_date` >= '{$begin}') "; } if (!empty($end)) { $query .= " AND (`glpi_infocoms`.`buy_date` <= '{$end}'\n OR `glpi_infocoms`.`use_date` <= '{$end}') "; } $query .= " ORDER BY entname ASC, `buy_date`, `use_date`"; $display_entity = isMultiEntitiesMode(); $result = $DB->query($query); if ($DB->numrows($result) > 0) { $item = new $itemtype(); echo "<h2>" . $item->getTypeName() . "</h2>"; echo "<table class='tab_cadre'><tr><th>" . $LANG['common'][16] . "</th>"; if ($display_entity) { echo "<th>" . $LANG['entity'][0] . "</th>"; } echo "<th>" . $LANG['financial'][21] . "</th><th>" . $LANG['financial'][92] . "</th>"; echo "<th>" . $LANG['financial'][91] . "</th><th>" . $LANG['financial'][14] . "</th>"; echo "<th>" . $LANG['financial'][76] . "</th><th>" . $LANG['financial'][80] . "</th></tr>"; $valeursoustot = 0; $valeurnettesoustot = 0; $valeurnettegraph = array(); $valeurgraph = array(); while ($line = $DB->fetch_array($result)) { if (isset($line["is_global"]) && $line["is_global"]) { $line["value"] *= Computer_Item::countForItem($itemtype, $line["items_id"]); } if ($line["value"] > 0) { $valeursoustot += $line["value"]; } $valeurnette = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "n"); $tmp = Infocom::Amort($line["sink_type"], $line["value"], $line["sink_time"], $line["sink_coeff"], $line["buy_date"], $line["use_date"], $CFG_GLPI["date_tax"], "all"); if (is_array($tmp) && count($tmp) > 0) { foreach ($tmp["annee"] as $key => $val) { if ($tmp["vcnetfin"][$key] > 0) { if (!isset($valeurnettegraph[$val])) { $valeurnettegraph[$val] = 0; } $valeurnettegraph[$val] += $tmp["vcnetdeb"][$key]; } } } if (!empty($line["buy_date"])) { $year = substr($line["buy_date"], 0, 4); if ($line["value"] > 0) { if (!isset($valeurgraph[$year])) { $valeurgraph[$year] = 0; } $valeurgraph[$year] += $line["value"]; } } $valeurnettesoustot += str_replace(" ", "", $valeurnette); echo "<tr class='tab_bg_1'><td>" . $line["name"] . "</td>"; if ($display_entity) { if ($line['entID'] == 0) { echo "<td>" . $LANG['entity'][2] . "</td>"; } else { echo "<td>" . $line['entname'] . "</td>"; } } echo "<td class='right'>" . formatNumber($line["value"]) . "</td><td class='right'>" . formatNumber($valeurnette) . "</td><td class='right'>" . Infocom::showTco($line["ticket_tco"], $line["value"]) . "</td><td>" . convDate($line["buy_date"]) . "</td><td>" . convDate($line["use_date"]) . "</td><td>" . getWarrantyExpir($line["buy_date"], $line["warranty_duration"]) . "</td></tr>"; } $valeurtot += $valeursoustot; $valeurnettetot += $valeurnettesoustot; echo "<tr><td colspan='6' class='center'><h3>" . $LANG['common'][33] . " : " . $LANG['financial'][21] . "=" . formatNumber($valeursoustot) . " - " . $LANG['financial'][81] . "=" . formatNumber($valeurnettesoustot) . "</h3></td></tr>"; if (count($valeurnettegraph) > 0) { echo "<tr><td colspan='5' class='center'>"; ksort($valeurnettegraph); $valeurnettegraphdisplay = array_map('round', $valeurnettegraph); foreach ($valeurnettegraph as $key => $val) { if (!isset($valeurnettegraphtot[$key])) { $valeurnettegraphtot[$key] = 0; } $valeurnettegraphtot[$key] += $valeurnettegraph[$key]; } Stat::showGraph(array($LANG['financial'][81] => $valeurnettegraphdisplay), array('title' => $LANG['financial'][81], 'width' => 400)); echo "</td></tr>"; } if (count($valeurgraph) > 0) { echo "<tr><td colspan='5' class='center'>"; ksort($valeurgraph); $valeurgraphdisplay = array_map('round', $valeurgraph); foreach ($valeurgraph as $key => $val) { if (!isset($valeurgraphtot[$key])) { $valeurgraphtot[$key] = 0; } $valeurgraphtot[$key] += $valeurgraph[$key]; } Stat::showGraph(array($LANG['financial'][21] => $valeurgraphdisplay), array('title' => $LANG['financial'][21], 'width' => 400)); echo "</td></tr>"; } echo "</table>"; return true; } return false; }
/** * Print an HTML array with contracts associated to the enterprise * *@return Nothing (display) **/ function showContracts() { global $DB, $CFG_GLPI, $LANG; $ID = $this->fields['id']; if (!haveRight("contract", "r") || !$this->can($ID, 'r')) { return false; } $canedit = $this->can($ID, 'w'); $query = "SELECT `glpi_contracts`.*,\n `glpi_contracts_suppliers`.`id` AS assocID,\n `glpi_entities`.`id` AS entity\n FROM `glpi_contracts_suppliers`, `glpi_contracts`\n LEFT JOIN `glpi_entities` ON (`glpi_entities`.`id`=`glpi_contracts`.`entities_id`)\n WHERE `glpi_contracts_suppliers`.`suppliers_id` = '{$ID}'\n AND `glpi_contracts_suppliers`.`contracts_id`=`glpi_contracts`.`id`" . getEntitiesRestrictRequest(" AND", "glpi_contracts", '', '', true) . "\n ORDER BY `glpi_entities`.`completename`,\n `glpi_contracts`.`name`"; $result = $DB->query($query); $number = $DB->numrows($result); $i = 0; echo "<form method='post' action='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php'>"; echo "<div class='spaced'><table class='tab_cadre_fixe'>"; echo "<tr><th colspan='7'>"; if ($DB->numrows($result) == 0) { echo $LANG['financial'][58]; } else { if ($DB->numrows($result) == 1) { echo $LANG['financial'][63]; } else { echo $LANG['financial'][66]; } } echo "</th></tr>"; echo "<tr><th>" . $LANG['common'][16] . "</th>"; echo "<th>" . $LANG['entity'][0] . "</th>"; echo "<th>" . $LANG['financial'][4] . "</th>"; echo "<th>" . $LANG['financial'][6] . "</th>"; echo "<th>" . $LANG['search'][8] . "</th>"; echo "<th>" . $LANG['financial'][8] . "</th>"; echo "<th> </th>"; echo "</tr>"; $used = array(); while ($data = $DB->fetch_array($result)) { $cID = $data["id"]; $used[$cID] = $cID; $assocID = $data["assocID"]; echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>"; echo "<td class='center'>\n <a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?id={$cID}'>"; echo "<strong>" . $data["name"]; if ($_SESSION["glpiis_ids_visible"] || empty($data["name"])) { echo " (" . $data["id"] . ")"; } echo "</strong></a></td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data["entity"]); echo "</td><td class='center'>" . $data["num"] . "</td>"; echo "<td class='center'>" . Dropdown::getDropdownName("glpi_contracttypes", $data["contracttypes_id"]) . "</td>"; echo "<td class='center'>" . convDate($data["begin_date"]) . "</td>"; echo "<td class='center'>" . $data["duration"] . " " . $LANG['financial'][57]; if ($data["begin_date"] != '' && !empty($data["begin_date"])) { echo " -> " . getWarrantyExpir($data["begin_date"], $data["duration"]); } echo "</td>"; echo "<td class='tab_bg_2 center'>"; if ($canedit) { echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/contract.form.php?deletecontractsupplier=" . "1&id={$assocID}&contracts_id={$cID}'>"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/delete2.png' alt='" . $LANG['buttons'][6] . "'></a>"; } else { echo " "; } echo "</td></tr>"; $i++; } if ($canedit) { if ($this->fields["is_recursive"]) { $nb = countElementsInTableForEntity("glpi_contracts", getSonsOf("glpi_entities", $this->fields["entities_id"])); } else { $nb = countElementsInTableForEntity("glpi_contracts", $this->fields["entities_id"]); } if ($nb > count($used)) { echo "<tr class='tab_bg_1'><td class='center' colspan='5'>"; echo "<input type='hidden' name='suppliers_id' value='{$ID}'>"; Contract::dropdown(array('used' => $used, 'entity' => $this->fields["entities_id"], 'entity_sons' => $this->fields["is_recursive"], 'nochecklimit' => true)); echo "</td><td class='center'>"; echo "<input type='submit' name='addcontractsupplier' value=\"" . $LANG['buttons'][8] . "\"\n class='submit'>"; echo "</td>"; echo "<td> </td></tr>"; } } echo "</table></div></form>"; }
/** * Show Infocom form for an item (not a standard showForm) * * @param $item CommonDBTM object * @param $withtemplate integer: template or basic item **/ static function showForItem(CommonDBTM $item, $withtemplate = '') { global $CFG_GLPI, $LANG; // Show Infocom or blank form if (!haveRight("infocom", "r")) { return false; } if (!$item) { echo "<div class='spaced'>" . $LANG['financial'][85] . "</div>"; } else { $date_tax = $CFG_GLPI["date_tax"]; $dev_ID = $item->getField('id'); $ic = new self(); $option = ""; if ($withtemplate == 2) { $option = " readonly "; } if (!strpos($_SERVER['PHP_SELF'], "infocoms-show") && in_array($item->getType(), array('CartridgeItem', 'ConsumableItem', 'Software'))) { echo "<div class='firstbloc center'>" . $LANG['financial'][84] . "</div>"; } if (!$ic->getFromDBforDevice($item->getType(), $dev_ID)) { $input = array('itemtype' => $item->getType(), 'items_id' => $dev_ID, 'entities_id' => $item->getEntityID()); if ($ic->can(-1, "w", $input) && $withtemplate != 2) { echo "<div class='spaced b'>"; echo "<table class='tab_cadre_fixe'><tr class='tab_bg_1'><th>"; echo $item->getTypeName() . " - " . $item->getName() . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; echo "<a href='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php?itemtype=" . $item->getType() . "&items_id={$dev_ID}&add=add'>" . $LANG['financial'][68]; echo "</a></td></tr></table></div>"; } } else { // getFromDBforDevice $canedit = $ic->can($ic->fields['id'], "w") && $withtemplate != 2; if ($canedit) { echo "<form name='form_ic' method='post' action='" . $CFG_GLPI["root_doc"] . "/front/infocom.form.php'>"; } echo "<div class='spaced'>"; echo "<table class='tab_cadre" . (!strpos($_SERVER['PHP_SELF'], "infocoms-show") ? "_fixe" : "") . "'>"; echo "<tr><th colspan='4'>" . $LANG['financial'][3] . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][26] . " :</td>"; echo "<td>"; if ($withtemplate == 2) { echo Dropdown::getDropdownName("glpi_suppliers", $ic->fields["suppliers_id"]); } else { Dropdown::show('Supplier', array('value' => $ic->fields["suppliers_id"], 'entity' => $item->getEntityID())); } echo "</td>"; if (haveRight("budget", "r")) { echo "<td>" . $LANG['financial'][87] . " :</td><td >"; Dropdown::show('Budget', array('value' => $ic->fields["budgets_id"], 'entity' => $item->getEntityID(), 'comments' => 1)); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; // Can edit calendar ? $editcalendar = $withtemplate != 2; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][18] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "order_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][28] . " :</td><td>"; showDateFormItem("order_date", $ic->fields["order_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][20] . "* :</td>"; echo "<td>"; $objectName = autoName($ic->fields["immo_number"], "immo_number", $withtemplate == 2, 'Infocom', $item->getEntityID()); autocompletionTextField($ic, "immo_number", array('value' => $objectName, 'option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][14] . " :</td><td>"; showDateFormItem("buy_date", $ic->fields["buy_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][82] . " :</td>"; echo "<td>"; autocompletionTextField($ic, "bill", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][27] . " :</td><td>"; showDateFormItem("delivery_date", $ic->fields["delivery_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][19] . " :</td><td>"; autocompletionTextField($ic, "delivery_number", array('option' => $option)); echo "</td>"; echo "<td>" . $LANG['financial'][76] . " :</td><td>"; showDateFormItem("use_date", $ic->fields["use_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][21] . " :</td>"; echo "<td><input type='text' name='value' {$option} value='" . formatNumber($ic->fields["value"], true) . "' size='14'></td>"; echo "</td>"; echo "<td>" . $LANG['financial'][114] . " :</td><td>"; showDateFormItem("inventory_date", $ic->fields["inventory_date"], true, $editcalendar); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][78] . " :</td>"; echo "<td><input type='text' {$option} name='warranty_value' value='" . formatNumber($ic->fields["warranty_value"], true) . "' size='14'></td>"; echo "<td rowspan='5'>" . $LANG['common'][25] . " :</td>"; echo "<td rowspan='5' class='middle'>"; echo "<textarea cols='45' rows='9' name='comment' >" . $ic->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][81] . " :</td><td>"; echo formatNumber(self::Amort($ic->fields["sink_type"], $ic->fields["value"], $ic->fields["sink_time"], $ic->fields["sink_coeff"], $ic->fields["warranty_date"], $ic->fields["use_date"], $date_tax, "n")); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][22] . " :</td><td >"; if ($withtemplate == 2) { echo self::getAmortTypeName($ic->fields["sink_type"]); } else { self::dropdownAmortType("sink_type", $ic->fields["sink_type"]); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][23] . " :</td><td>"; if ($withtemplate == 2) { echo $ic->fields["sink_time"]; } else { Dropdown::showInteger("sink_time", $ic->fields["sink_time"], 0, 15); } echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][77] . " :</td>"; echo "<td>"; autocompletionTextField($ic, "sink_coeff", array('size' => 14, 'option' => $option)); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . $LANG['financial'][89] . " :</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"]); } else { echo "<td colspan='2'>"; } echo "</td>"; if (!in_array($item->getType(), array('Cartridge', 'CartridgeItem', 'Consumable', 'ConsumableItem', 'Software', 'SoftwareLicense'))) { echo "<td>" . $LANG['financial'][90] . " :</td><td>"; echo self::showTco($item->getField('ticket_tco'), $ic->fields["value"], $ic->fields["warranty_date"]); } else { echo "<td colspan='2'>"; } echo "</td></tr>"; echo "<tr><th colspan='4'>" . $LANG['financial'][7] . "</th></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][29] . " :</td><td>"; showDateFormItem("warranty_date", $ic->fields["warranty_date"], true, $editcalendar); echo "</td>"; echo "<td>" . $LANG['financial'][15] . " :</td><td>"; if ($withtemplate == 2) { // -1 = life if ($ic->fields["warranty_duration"] == -1) { echo $LANG['financial'][2]; } else { echo $ic->fields["warranty_duration"]; } } else { Dropdown::showInteger("warranty_duration", $ic->fields["warranty_duration"], 0, 120, 1, array(-1 => $LANG['financial'][2])); } if ($ic->fields["warranty_duration"] >= 0) { echo " " . $LANG['financial'][57]; } echo "<span class='small_space'>" . $LANG['financial'][88] . "</span> "; echo getWarrantyExpir($ic->fields["warranty_date"], $ic->fields["warranty_duration"]); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . $LANG['financial'][16] . " :</td>"; echo "<td >"; autocompletionTextField($ic, "warranty_info", array('option' => $option)); echo "</td>"; if ($CFG_GLPI['use_mailing']) { echo "<td>" . $LANG['setup'][247] . " :</td>"; echo "<td>"; echo self::dropdownAlert("alert", $ic->fields["alert"]); Alert::displayLastAlert('Infocom', $ic->fields['id']); echo "</td>"; } else { echo "</td><td colspan='2'>"; } echo "</td></tr>"; if ($canedit) { echo "<tr>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='hidden' name='id' value='" . $ic->fields['id'] . "'>"; echo "<input type='submit' name='update' value=\"" . $LANG['buttons'][7] . "\"\n class='submit'>"; echo "</td>"; echo "<td class='tab_bg_2 center' colspan='2'>"; echo "<input type='submit' name='delete' value=\"" . $LANG['buttons'][6] . "\"\n class='submit'>"; echo "</td></tr>"; echo "</table></div></form>"; } else { echo "</table></div>"; } } } }
static function giveItem($itemtype, $ID, array $data, $num, $meta = 0, array $addobjectparams = array()) { global $CFG_GLPI, $LANG, $PLUGIN_HOOKS; $searchopt =& Search::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { return PluginMobileSearch::giveItem($data["TYPE"], $ID, $data, $num, $meta); } // 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"]; switch ($table . '.' . $field) { case "glpi_users_validation.name": 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 = getUserNameMobile($split[$k], 2); $out .= $userdata['name'] . " "; } else { $out .= getUserNameMobile($split[$k], 1); } } } return $out; } else { if (!empty($linkfield)) { $toadd = ''; if ($itemtype == 'Ticket' && $data[$NAME . $num . "_3"] > 0) { $userdata = getUserNameMobile($data[$NAME . $num . "_3"], 2); $toadd = " "; } //Stevenes $name1 = explode("\$\$", $data[$NAME . $num]); // return $name1['0'].' ('.$name1['1'].')'; $link_user = $_SESSION['mobileSearchLastLink'] = "<a href=" . $CFG_GLPI["root_doc"] . "/plugins/mobile/front/item.php?itemtype=user&menu=admin&ssmenu=user&id=" . $name1['1'] . ">" . $name1['0'] . " (" . $name1['1'] . ")</a>"; return $link_user; // return formatUserNameMobile($data[$NAME.$num."_3"],$data[$NAME.$num],$data[$NAME.$num."_2"], $data[$NAME.$num."_4"],1).$toadd; } } break; case "glpi_profiles.interface": return Profile::getInterfaceName($data[$NAME . $num]); break; case "glpi_profiles.name": if ($itemtype == 'User') { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . $split2[$k]; if ($split3[$k]) { $text .= " (R)"; } 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"]); $added = array(); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . $split2[$k]; if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } else { if ($data[$NAME . $num . "_2"] == 0) { // Set name for Root entity $data[$NAME . $num] = $LANG['entity'][2]; } } 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 = utf8_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 = utf8_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>') . $duration . " " . $LANG['financial'][57]; } 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) { $out .= $val . " " . $LANG['financial'][9]; } } 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 .= $val . " " . $LANG['financial'][57]; } if ($val < 0) { $out .= $LANG['financial'][2]; } } 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 $LANG['financial'][80]; } return ""; case "glpi_contracts.alert": switch ($data[$NAME . $num]) { case pow(2, Alert::END): return $LANG['buttons'][32]; case pow(2, Alert::NOTICE): return $LANG['financial'][10]; case pow(2, Alert::END) + pow(2, Alert::NOTICE): return $LANG['buttons'][32] . " + " . $LANG['financial'][10]; } return ""; case "glpi_tickets.count": if ($data[$NAME . $num] > 0 && Session::haveRight("ticket", Ticket::READALL)) { $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 href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.php?" . Toolbox::append_params($options) . "\" data-back='false'>"; $out .= $data[$NAME . $num]; $out .= "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_softwarelicenses.number": if ($data[$NAME . $num . "_2"] == -1) { return $LANG['software'][4]; } 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='" . $LANG['reservation'][22] . "'\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' data-back='false'>" . $LANG['common'][49] . "</a>"; } return "<a title='" . $LANG['reservation'][22] . "'\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' data-back='false'>" . 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(); return $events[$data[$NAME . $num]]; } return ''; 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_tickets.status': $status = Ticket::getStatus($data[$NAME . $num]); // status Stevenes Donato if ($data[$NAME . $num] == "1") { $data[$NAME . $num] = "new"; } if ($data[$NAME . $num] == "2") { $data[$NAME . $num] = "assign"; } if ($data[$NAME . $num] == "3") { $data[$NAME . $num] = "plan"; } if ($data[$NAME . $num] == "4") { $data[$NAME . $num] = "waiting"; } if ($data[$NAME . $num] == "5") { $data[$NAME . $num] = "solved"; } if ($data[$NAME . $num] == "6") { $data[$NAME . $num] = "closed"; } // return "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . $data[$NAME . $num] . ".png\"\n alt='{$status}' title='{$status}'> {$status}"; case 'glpi_tickets.priority': return Ticket::getPriorityName($data[$NAME . $num]); case 'glpi_tickets.urgency': return Ticket::getUrgencyName($data[$NAME . $num]); case 'glpi_tickets.impact': return Ticket::getImpactName($data[$NAME . $num]); case 'glpi_tickets.items_id': if (!empty($data[$NAME . $num . "_2"]) && class_exists($data[$NAME . $num . "_2"])) { $item = new $data[$NAME . $num . "_2"](); if ($item->getFromDB($data[$NAME . $num])) { return $item->getLink(true); } } return ' '; case 'glpi_tickets.id': $link = getItemTypeFormURLMobile('Ticket'); $out = "<a id='ticket" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num]; //$out .= 'id='.$data[$NAME.$num."_2"]; $out .= "\" data-back='false'>" . $data[$NAME . $num]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { //$out .= " (".$data[$NAME.$num."_2"].")"; $out .= $data[$NAME . $num . "_2"]; } $out .= "</a>"; return $out; case 'glpi_ticketvalidations.status': case "glpi_tickets.global_validation": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $status = TicketValidation::getStatus($val); $bgcolor = TicketValidation::getStatusColor($val); $out .= (empty($out) ? '' : '<br>') . "<div style=\"background-color:" . $bgcolor . ";\">" . $status . '</div>'; } return $out; 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']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": if (!empty($data[$NAME . $num . "_2"])) { if (isset($searchopt[$ID]["itemlink_type"])) { $link = getItemTypeFormURLMobile($searchopt[$ID]["itemlink_type"]); } else { $link = getItemTypeFormURLMobile($itemtype); } $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"] . "\" data-back='false'>"; $out .= $data[$NAME . $num] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; return $out; } else { if (isset($searchopt[$ID]["itemlink_type"])) { $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 = explode("\$\$", $split[$k]); if (isset($split2[1]) && $split2[1] > 0) { if ($count_display) { $out .= $separate; } $count_display++; $page = getItemTypeFormURLMobile($searchopt[$ID]["itemlink_type"]); $page .= strpos($page, '?') ? '&id' : '?id'; $out .= "<a id='" . $searchopt[$ID]["itemlink_type"] . "_" . $split2[1] . "'\n href='{$page}=" . $split2[1] . "' data-back='false'>"; $out .= $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } } } return $out; } } break; case "text": $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } return str_replace('$$$$', $separate, nl2br($data[$NAME . $num])); case "date": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . 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": return timestampToString($data[$NAME . $num]); case "realtime": return Ticket::getRealtime($data[$NAME . $num]); case "date_delay": $split = explode('$$$$', $data[$NAME . $num]); $out = ''; foreach ($split as $val) { if (strpos($val, ',')) { list($dat, $dur) = explode(',', $val); if (!empty($dat)) { $out .= (empty($out) ? '' : '<br>') . getWarrantyExpir($dat, $dur); } } } return empty($out) ? " " : $out; case "email": // Stevenes // $email=trim($data[$NAME.$num]); $email = explode('$$', $data[$NAME . $num]); if (!empty($email['0'])) { return $email['0']; //return "<a href='mailto:$email'>$email</a>"; } return " "; 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 (utf8_strlen($link) > 30) { $link = Toolbox::substr($link, 0, 30) . "..."; } //return "<a href=\"".formatOutputWebLink($orig_link)."\" target='_blank'>$link</a>"; return $orig_link; } 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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', Html::formatNumber($split[$k], false, 0)) . $unit; } } return $out; } return str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num], false, 0)) . $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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', Html::formatNumber($split[$k])) . $unit; } } return $out; } return str_replace(' ', ' ', Html::formatNumber($data[$NAME . $num])) . $unit; case "bool": return Dropdown::getYesNo($data[$NAME . $num]) . $unit; case "right": return Profile::getRightValue($data[$NAME . $num]); case "itemtypename": if (class_exists($data[$NAME . $num])) { $obj = new $data[$NAME . $num](); return $obj->getTypeName(); } else { return ""; } case "language": if (isset($CFG_GLPI['languages'][$data[$NAME . $num]])) { return $CFG_GLPI['languages'][$data[$NAME . $num]][0]; } else { return $LANG['setup'][46]; } break; } } // 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; } $count_display++; $out .= $split[$k] . $unit; } } return $out; } return $data[$NAME . $num] . $unit; }
/** * 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 ? * * @return string to print **/ static function giveItem($itemtype, $ID, $data, $num, $meta = 0) { global $CFG_GLPI, $LANG; $searchopt =& self::getOptions($itemtype); if (isset($CFG_GLPI["union_search_type"][$itemtype]) && $CFG_GLPI["union_search_type"][$itemtype] == $searchopt[$ID]["table"]) { return self::giveItem($data["TYPE"], $ID, $data, $num, $meta); } // 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"]; 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); $out .= $userdata['name'] . " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } else { $out .= getUserName($split[$k], 1); } } } // 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 = " " . showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false)); } return formatUserName($data[$NAME . $num . "_3"], $data[$NAME . $num], $data[$NAME . $num . "_2"], $data[$NAME . $num . "_4"], 1) . $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"]); $count_display = 0; $added = array(); for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . Dropdown::getDropdownName('glpi_entities', $split2[$k]); if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_complete_entities.completename": if ($itemtype == 'User') { $out = ""; $split = explode("\$\$\$\$", $data[$NAME . $num]); $split2 = explode("\$\$\$\$", $data[$NAME . $num . "_2"]); $split3 = explode("\$\$\$\$", $data[$NAME . $num . "_3"]); $added = array(); $count_display = 0; for ($k = 0; $k < count($split); $k++) { if (strlen(trim($split[$k])) > 0) { $text = $split[$k] . " - " . Dropdown::getDropdownName('glpi_profiles', $split2[$k]); if ($split3[$k]) { $text .= " (R)"; } if (!in_array($text, $added)) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= $text; $added[] = $text; } } } return $out; } break; case "glpi_entities.completename": if ($data[$NAME . $num . "_2"] == 0) { // Set name for Root entity $data[$NAME . $num] = $LANG['entity'][2]; } 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 = utf8_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 = utf8_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>') . $duration . " " . $LANG['financial'][57]; } 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) { $out .= $val . " " . $LANG['financial'][9]; } } 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 .= $val . " " . $LANG['financial'][57]; } if ($val < 0) { $out .= $LANG['financial'][2]; } } 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 $LANG['financial'][80]; } return ""; case "glpi_contracts.alert": switch ($data[$NAME . $num]) { case pow(2, Alert::END): return $LANG['buttons'][32]; case pow(2, Alert::NOTICE): return $LANG['financial'][10]; case pow(2, Alert::END) + pow(2, Alert::NOTICE): return $LANG['buttons'][32] . " + " . $LANG['financial'][10]; } 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 = $linkid . " - " . Dropdown::getDropdownName('glpi_tickets', $linkid); if (count($displayed)) { $out .= "<br>"; } $displayed[$linkid] = $linkid; $out .= $text; } } return $out; case "glpi_tickets.count": if ($data[$NAME . $num] > 0 && haveRight("show_all_ticket", "1")) { 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 { $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?" . append_params($options, '&') . "\">"; $out .= $data[$NAME . $num] . "</a>"; } else { $out = $data[$NAME . $num]; } return $out; case "glpi_softwarelicenses.number": if ($data[$NAME . $num . "_2"] == -1) { return $LANG['software'][4]; } 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=\"" . $LANG['reservation'][22] . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data["refID"] . "' >" . $LANG['common'][49] . "</a>"; } return "<a title=\"" . $LANG['reservation'][22] . "\"\n href='" . $CFG_GLPI["root_doc"] . "/front/reservationitem.form.php?id=" . $data['refID'] . "' >" . 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(); return $events[$data[$NAME . $num]]; } return ''; 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_tickets.status': $status = Ticket::getStatus($data[$NAME . $num]); return "<img src=\"" . $CFG_GLPI["root_doc"] . "/pics/" . $data[$NAME . $num] . ".png\"\n alt=\"{$status}\" title=\"{$status}\"> {$status}"; case 'glpi_tickets.type': return Ticket::getTicketTypeName($data[$NAME . $num]); case 'glpi_tickets.priority': return Ticket::getPriorityName($data[$NAME . $num]); case 'glpi_tickets.urgency': return Ticket::getUrgencyName($data[$NAME . $num]); case 'glpi_tickets.impact': return Ticket::getImpactName($data[$NAME . $num]); case 'glpi_tickets.items_id': if (!empty($data[$NAME . $num . "_2"]) && class_exists($data[$NAME . $num . "_2"])) { $item = new $data[$NAME . $num . "_2"](); if ($item->getFromDB($data[$NAME . $num])) { return $item->getLink(true); } } return ' '; case 'glpi_tickets.name': $link = 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"] == 'solved') { $out .= "&forcetab=4"; } $out .= "\">" . $data[$NAME . $num]; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; $out .= showToolTip(nl2br($data[$NAME . $num . "_3"]), array('applyto' => 'ticket' . $data[$NAME . $num . "_2"], 'display' => false)); return $out; case "glpi_tickets.due_date": // No due date in waiting status if ($data[$NAME . $num . '_2'] == 'waiting') { $data[$NAME . $num] = ""; } break; case 'glpi_ticketvalidations.status': case "glpi_tickets.global_validation": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $status = TicketValidation::getStatus($val); $bgcolor = TicketValidation::getStatusColor($val); $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); case 'glpi_fieldunicities.fields': $values = explode(',', $data[$NAME . $num]); $item = new $data['ITEMTYPE'](); $message = array(); foreach ($values as $field) { $table = getTableNameForForeignKeyField($field); if ($table != '') { $searchOption = $item->getSearchOptionByField('field', 'name', $table); } else { $searchOption = $item->getSearchOptionByField('field', $field); } $message[] = $searchOption['name']; } return implode(',', $message); } //// 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']; } // Preformat items if (isset($searchopt[$ID]["datatype"])) { switch ($searchopt[$ID]["datatype"]) { case "itemlink": if (!empty($data[$NAME . $num . "_2"])) { if (isset($searchopt[$ID]["itemlink_type"])) { $link = getItemTypeFormURL($searchopt[$ID]["itemlink_type"]); } else { $link = getItemTypeFormURL($itemtype); } $out = "<a id='" . $itemtype . "_" . $data[$NAME . $num . "_2"] . "' href=\"" . $link; $out .= strstr($link, '?') ? '&' : '?'; $out .= 'id=' . $data[$NAME . $num . "_2"] . "\">" . $data[$NAME . $num] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($data[$NAME . $num])) { $out .= " (" . $data[$NAME . $num . "_2"] . ")"; } $out .= "</a>"; return $out; } if (isset($searchopt[$ID]["itemlink_type"])) { $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 = explode("\$\$", $split[$k]); if (isset($split2[1]) && $split2[1] > 0) { if ($count_display) { $out .= $separate; } $count_display++; $page = getItemTypeFormURL($searchopt[$ID]["itemlink_type"]); $page .= strpos($page, '?') ? '&id' : '?id'; $out .= "<a id='" . $searchopt[$ID]["itemlink_type"] . "_" . $data['id'] . "_" . $split2[1] . "' href='{$page}=" . $split2[1] . "'>" . $split2[0] . $unit; if ($_SESSION["glpiis_ids_visible"] || empty($split2[0])) { $out .= " (" . $split2[1] . ")"; } $out .= "</a>"; } } } return $out; } break; case "text": $separate = '<br>'; if (isset($searchopt[$ID]['splititems']) && $searchopt[$ID]['splititems']) { $separate = '<hr>'; } $text = str_replace('$$$$', $separate, nl2br($data[$NAME . $num])); if (isset($searchopt[$ID]['htmltext']) && $searchopt[$ID]['htmltext']) { $text = html_clean(unclean_cross_side_scripting_deep($text)); } return $text; case "date": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . convDate($val); } return $out; case "datetime": $split = explode("\$\$\$\$", $data[$NAME . $num]); $out = ''; foreach ($split as $val) { $out .= (empty($out) ? '' : '<br>') . convDateTime($val); } return $out; case "timestamp": $withseconds = false; if (isset($searchopt[$ID]['withseconds'])) { $withseconds = $searchopt[$ID]['withseconds']; } return timestampToString($data[$NAME . $num], $withseconds); case "date_delay": $split = explode('$$$$', $data[$NAME . $num]); $out = ''; foreach ($split as $val) { if (strpos($val, ',')) { list($dat, $dur) = explode(',', $val); if (!empty($dat)) { $out .= (empty($out) ? '' : '<br>') . getWarrantyExpir($dat, $dur); } } } return empty($out) ? " " : $out; case "email": $email = trim($data[$NAME . $num]); if (!empty($email)) { return "<a href='mailto:{$email}'>{$email}</a>"; } return " "; 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 (utf8_strlen($link) > $CFG_GLPI["url_maxlength"]) { $link = utf8_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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', formatNumber($split[$k], false, 0)) . $unit; } } return $out; } return str_replace(' ', ' ', formatNumber($data[$NAME . $num], false, 0)) . $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) { if ($count_display) { $out .= "<br>"; } $count_display++; $out .= str_replace(' ', ' ', formatNumber($split[$k])) . $unit; } } return $out; } return str_replace(' ', ' ', formatNumber($data[$NAME . $num])) . $unit; case "bool": return Dropdown::getYesNo($data[$NAME . $num]) . $unit; case "right": return Profile::getRightValue($data[$NAME . $num]); case "itemtypename": if (class_exists($data[$NAME . $num])) { $obj = new $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 $LANG['setup'][46]; } } // 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; } $count_display++; $out .= $split[$k] . $unit; } } return $out; } return $data[$NAME . $num] . $unit; }
/** * Cron action on contracts : alert depending of the config : on notice and expire * * @param $task for log, if NULL display * **/ static function cronContract($task = NULL) { global $DB, $CFG_GLPI, $LANG; if (!$CFG_GLPI["use_mailing"]) { return 0; } $message = array(); $items_notice = array(); $items_end = array(); $cron_status = 0; $contract_infos[Alert::END] = array(); $contract_infos[Alert::NOTICE] = array(); $contract_messages = array(); foreach (Entity::getEntitiesToNotify('use_contracts_alert') as $entity => $value) { $query_notice = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::NOTICE . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::NOTICE) . ") >'0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND `glpi_contracts`.`notice` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL `glpi_contracts`.`duration` MONTH),\n CURDATE()) > '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`\n -`glpi_contracts`.`notice`) MONTH),\n CURDATE()) < '0'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'"; $query_end = "SELECT `glpi_contracts`.*\n FROM `glpi_contracts`\n LEFT JOIN `glpi_alerts`\n ON (`glpi_contracts`.`id` = `glpi_alerts`.`items_id`\n AND `glpi_alerts`.`itemtype` = 'Contract'\n AND `glpi_alerts`.`type`='" . Alert::END . "')\n WHERE (`glpi_contracts`.`alert` & " . pow(2, Alert::END) . ") > '0'\n AND `glpi_contracts`.`is_deleted` = '0'\n AND `glpi_contracts`.`begin_date` IS NOT NULL\n AND `glpi_contracts`.`duration` <> '0'\n AND DATEDIFF(ADDDATE(`glpi_contracts`.`begin_date`,\n INTERVAL (`glpi_contracts`.`duration`) MONTH),\n CURDATE()) < '0'\n AND `glpi_alerts`.`date` IS NULL\n AND `glpi_contracts`.`entities_id` = '" . $entity . "'"; $querys = array(Alert::NOTICE => $query_notice, Alert::END => $query_end); foreach ($querys as $type => $query) { foreach ($DB->request($query) as $data) { $entity = $data['entities_id']; $message = $data["name"] . ": " . getWarrantyExpir($data["begin_date"], $data["duration"], $data["notice"]) . "<br>\n"; $contract_infos[$type][$entity][$data['id']] = $data; if (!isset($contract_messages[$type][$entity])) { $contract_messages[$type][$entity] = $LANG['mailing'][37] . "<br />"; } $contract_messages[$type][$entity] .= $message; } } } foreach (array(Alert::NOTICE => "notice", Alert::END => "end") as $type => $event) { foreach ($contract_infos[$type] as $entity => $contracts) { if (NotificationEvent::raiseEvent($event, new Contract(), array('entities_id' => $entity, 'contracts' => $contracts))) { $message = $contract_messages[$type][$entity]; $cron_status = 1; if ($task) { $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ": {$message}\n"); $task->addVolume(1); } else { addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ": {$message}"); } $alert = new Alert(); $input["itemtype"] = 'Contract'; $input["type"] = $type; foreach ($contracts as $id => $contract) { $input["items_id"] = $id; $alert->add($input); unset($alert->fields['id']); } } else { if ($task) { $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ": Send contract alert failed\n"); } else { addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ": Send contract alert failed", false, ERROR); } } } } return $cron_status; }