// ================================================== // Copyright (c) 2011-2011 Artica Soluciones Tecnologicas // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; version 2 // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. global $config; check_login (); $filter['limit'] = 0; $incidents = filter_incidents ($filter); unset($filter['limit']); /* Add a form to carry filter between statistics and search views */ echo '<form id="search_form" method="post" action="index.php?sec=incidents&sec2=operation/incidents/incident_search&option=search" style="clear: both">'; foreach ($filter as $key => $value) { print_input_hidden ("search_".$key, $value); } print_input_hidden ("offset", get_parameter("offset")); echo "</form>"; /* Add a form to generate HTML reports */ echo '<form id="html_report_form" method="post" target="_blank" action="index.php" style="clear: both">'; foreach ($filter as $key => $value) { print_input_hidden ("search_".$key, $value);
function api_get_stats($return_type, $param, $token, $user) { global $config; $config['id_user'] = $user; $param = explode($token, $param); $filter = array(); if (isset($param[0])) { $filter['metric'] = $param[0]; } else { return; } // No valid metric passed as parameter if (isset($param[1])) { $filter['string'] = $param[1]; } else { $filter["string"] = ""; } if (isset($param[2])) { $filter['status'] = $param[2]; } else { $filter["status"] = "1,2,3,4,5,6,7"; } // If we need closed incidents, status is fixed to 5 and 6 status if ($filter["metric"] == "closed") { $filter["status"] = "6,7"; } if ($filter["metric"] == "sla_compliance") { $filter["status"] = "1,2,3,4,5"; } if ($filter["metric"] == "avg_life") { $filter["status"] = "6,7"; } if ($filter["metric"] == "avg_scoring") { $filter["status"] = "6,7"; } if (isset($param[3])) { $filter['id_user'] = $param[3]; } else { $filter["id_user"] = ""; } if (isset($param[4])) { $filter['id_group'] = $param[4]; } else { $filter["id_group"] = 1; } if (isset($param[5])) { $filter['id_company'] = $param[5]; } else { $filter["id_company"] = 0; } if (isset($param[6])) { $filter['id_product'] = $param[6]; } else { $filter["id_product"] = 0; } if (isset($param[7])) { $filter['id_inventory'] = $param[7]; } else { $filter["id_inventory"] = 0; } // No values defined for other filters available but not used: $filter['priority'] = (int) get_parameter('search_priority', -1); $filter['serial_number'] = (string) get_parameter('search_serial_number'); $filter['id_building'] = (int) get_parameter('search_id_building'); $filter['sla_fired'] = false; $filter['id_incident_type'] = (int) get_parameter('search_id_incident_type'); $filter['first_date'] = (string) get_parameter('search_first_date'); $filter['last_date'] = (string) get_parameter('search_last_date'); //$incidents = filter_incidents ($filter); $incidents = filter_incidents($filter, false, false); $stats = get_incidents_stats($incidents); /* $data ["total_incidents"] = $total; $data ["opened"] = $opened; $data ["closed"] = $total - $opened; $data ["avg_life"] = $mean_lifetime; $data ["avg_worktime"] = $mean_work; $data ["sla_compliance"] = $sla_compliance; $data ["avg_scoring"] = $scoring_avg; */ $ret = ''; if ($return_type == 'xml') { $ret = "<xml>\n"; $ret .= "<data>"; } switch ($filter['metric']) { case "total_incidents": $ret .= $stats["total_incidents"]; break; case "opened": $ret .= $stats["opened"]; break; case "closed": $ret .= $stats["closed"]; break; case "avg_life": $ret .= $stats["avg_life"]; break; case "sla_compliance": $ret .= $stats["sla_compliance"]; break; case "avg_scoring": $ret .= $stats["avg_scoring"]; break; case "avg_worktime": $ret .= $stats["avg_worktime"]; break; } if ($return_type == 'xml') { $ret .= "</data>\n"; $ret .= "</xml>\n"; } return $ret; }
$custom .= "<em>".__("There aren't custom search defined for this user")."</em>"; $custom .= "</td>"; $custom .= "</tr>"; $custom .= "</table>"; } else { foreach ($custom_searches as $cs) { $c_search = get_custom_search ($cs['id'], 'incidents'); if ($c_search) { if ($c_search["form_values"]) { $filter_search = unserialize($c_search["form_values"]); } } $count_cs = filter_incidents ($filter_search, true); $custom .="<div class='custom_search'>"; $custom .= "<a href='index.php?sec=incidents&sec2=operation/incidents/incident_search&saved_searches=".$cs["id"]."'>".$cs["name"]." ". "(". $count_cs.")" . "</a><br>"; $custom .="</div>"; } $custom .= "<div style='clear:both;'></div>"; } $table->colspan[0][0] = 2; $table->data[0][0] = print_container('incident_custom_search', __('Custom search'), $custom); $groups = get_user_groups(); asort($groups);
function incidents_search_result($filter, $ajax = false, $return_incidents = false, $print_result_count = false, $no_parents = false, $resolve_names = false, $report_mode = false, $csv_mode = false) { global $config; $params = ""; foreach ($filter as $key => $value) { $params .= "&search_" . $key . "=" . $value; } //Only show incident for last year if there isn't a search by dates if (!$filter['first_date'] && !$filter['last_date']) { $filter_year = $filter; $now = print_mysql_timestamp(); $year_in_seconds = 3600 * 24 * 365; $year_ago_unix = time() - $year_in_seconds; $year_ago = date("Y-m-d H:i:s", $year_ago_unix); $filter_year['first_date'] = $year_ago; $filter_year['last_date'] = $now; $count_this_year = filter_incidents($filter_year, true, false, $no_parents, $csv_mode); $aux_text = "(" . $count_this_year . ")" . print_help_tip(__("Tickets created last year"), true); } if (!$report_mode) { //Add offset to filter parameters $offset = get_parameter("offset"); $filter["offset"] = $offset; // Store the previous limit filter $limit_aux = $filter["limit"]; } // Set the limit filter to 0 to retrieve all the tickets for the array pagination $filter["limit"] = 0; // All the tickets the user sees are retrieved $incidents = filter_incidents($filter, false, true, $no_parents, $csv_mode); $count = empty($incidents) ? 0 : count($incidents); if ($resolve_names) { $incidents_aux = array(); $i = 0; foreach ($incidents as $inc) { $incidents_aux[$i] = $inc; $incidents_aux[$i]['estado'] = incidents_get_incident_status_text($inc['id_incidencia']); $incidents_aux[$i]['resolution'] = incidents_get_incident_resolution_text($inc['id_incidencia']); $incidents_aux[$i]['prioridad'] = incidents_get_incident_priority_text($inc['id_incidencia']); $incidents_aux[$i]['id_grupo'] = incidents_get_incident_group_text($inc['id_incidencia']); $incidents_aux[$i]['id_group_creator'] = incidents_get_incident_group_text($inc['id_incidencia']); //~ $incidents_aux[$i]['id_incident_type'] = incidents_get_incident_type_text ($inc['id_incidencia']); $i++; } $incidents = $incidents_aux; } if ($return_incidents) { return $incidents; } if (!$report_mode) { // Set the limit filter to its previous value $filter["limit"] = $limit_aux; $url = "index.php?sec=incidents&sec2=operation/incidents/incident_search" . $params; $incidents = print_array_pagination($incidents, $url, $offset); } $statuses = get_indicent_status(); $resolutions = get_incident_resolutions(); // ORDER BY if ($filter['order_by'] && !is_array($filter['order_by'])) { $order_by = json_decode(clean_output($filter['order_by']), true); } else { $order_by = $filter['order_by']; } if (!$report_mode) { if ($order_by["id_incidencia"] != "") { if ($order_by["id_incidencia"] == "DESC") { $id_order_image = " <a href='javascript:changeIncidentOrder(\"id_incidencia\", \"ASC\")'><img src='images/arrow_down_orange.png'></a>"; } else { $id_order_image = " <a href='javascript:changeIncidentOrder(\"id_incidencia\", \"\")'><img src='images/arrow_up_orange.png'></a>"; } } else { $id_order_image = " <a href='javascript:changeIncidentOrder(\"id_incidencia\", \"DESC\")'><img src='images/block_orange.png'></a>"; } if ($order_by["prioridad"] != "") { if ($order_by["prioridad"] == "DESC") { $priority_order_image = " <a href='javascript:changeIncidentOrder(\"prioridad\", \"ASC\")'><img src='images/arrow_down_orange.png'></a>"; } else { $priority_order_image = " <a href='javascript:changeIncidentOrder(\"prioridad\", \"\")'><img src='images/arrow_up_orange.png'></a>"; } } else { $priority_order_image = " <a href='javascript:changeIncidentOrder(\"prioridad\", \"DESC\")'><img src='images/block_orange.png'></a>"; } } else { $id_order_image = ""; $priority_order_image = ""; } // ---------------------------------------- // Here we print the result of the search // ---------------------------------------- echo '<table width="99%" cellpadding="0" cellspacing="0" border="0px" class="result_table listing" id="incident_search_result_table">'; echo '<thead>'; echo "<tr>"; echo "<th>"; echo print_checkbox('incidentcb-all', "", false, true); echo "</th>"; echo "<th>"; echo __('ID') . $id_order_image; echo "</th>"; echo "<th>"; echo __('SLA'); echo "</th>"; if ($report_mode) { echo "<th>"; echo __(' % SLA'); echo "</th>"; } echo "<th>"; echo __('Ticket'); echo "</th>"; echo "<th>"; echo __('Group') . "<br><i>" . __('Company') . "</i>"; echo "</th>"; echo "<th>"; echo __('Status') . "<br><i>" . __('Resolution') . "</i>"; echo "</th>"; echo "<th>"; echo __('Priority') . $priority_order_image; echo "</th>"; echo "<th style='width: 70px;'>"; echo __('Updated') . "<br><i>" . __('Started') . "</i>"; echo "</th>"; if ($config["show_creator_incident"] == 1) { echo "<th>"; } echo __('Creator'); echo "</th>"; if ($config["show_owner_incident"] == 1) { echo "<th>"; } echo __('Owner'); echo "</th>"; echo "</tr>"; echo '</thead>'; echo "<tbody>"; if ($incidents == false) { echo '<tr><td colspan="11">' . __('Nothing was found') . '</td></tr>'; } else { foreach ($incidents as $incident) { /* We print the rows directly, because it will be used in a sortable jQuery table and it only needs the rows */ if ($incident["estado"] < 3) { $tr_status = 'class="red_row"'; } elseif ($incident["estado"] < 6) { $tr_status = 'class="yellow_row"'; } else { $tr_status = 'class="green_row"'; } echo '<tr ' . $tr_status . ' id="incident-' . $incident['id_incidencia'] . '"'; echo " style='border-bottom: 1px solid #ccc;' >"; echo '<td>'; print_checkbox_extended('incidentcb-' . $incident['id_incidencia'], $incident['id_incidencia'], false, '', '', 'class="cb_incident"'); echo '</td>'; //Print incident link if not ajax, if ajax link to js funtion to replace parent $link = "index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=" . $incident["id_incidencia"]; if ($ajax) { $link = "javascript:update_parent('" . $incident["id_incidencia"] . "')"; } echo '<td>'; if (!$report_mode) { echo '<strong><a href="' . $link . '">#' . $incident['id_incidencia'] . '</a></strong></td>'; } else { echo '<strong>' . '#' . $incident['id_incidencia'] . '</strong></td>'; } // SLA Fired ?? if ($incident["affected_sla_id"] != 0) { echo '<td width="25"><img src="images/exclamation.png" /></td>'; } else { echo '<td></td>'; } // % SLA if ($report_mode) { echo "<td>"; if ($incident["affected_sla_id"] != 0) { echo format_numeric(get_sla_compliance_single_id($incident['id_incidencia'])); } else { echo ""; } echo "</td>"; } echo '<td>'; if (!$report_mode) { echo '<strong><a href="' . $link . '">' . $incident['titulo'] . '</a></strong><br>'; } else { echo '<strong>' . $incident['titulo'] . '</strong><br>'; } echo "<span style='font-size:11px;font-style:italic'>"; echo incidents_get_incident_type_text($incident["id_incidencia"]); // Added by slerena 26Ago2013 $sql = sprintf("SELECT *\n\t\t\t\t\t\t\tFROM tincident_type_field\n\t\t\t\t\t\t\tWHERE id_incident_type = %d", $incident["id_incident_type"]); $config['mysql_result_type'] = MYSQL_ASSOC; $type_fields = get_db_all_rows_sql($sql); $type_fields_values_text = ""; if ($type_fields) { foreach ($type_fields as $type_field) { if ($type_field["show_in_list"]) { $field_data = get_db_value_filter("data", "tincident_field_data", array("id_incident" => $incident["id_incidencia"], "id_incident_field" => $type_field["id"])); if ($field_data) { if ($type_field["type"] == "textarea") { $field_data = "<div style='display: inline-block;' title='{$field_data}'>" . substr($field_data, 0, 15) . "...</div>"; } $type_fields_values_text .= " <div title='" . $type_field["label"] . "' style='display: inline-block;'>[{$field_data}]</div>"; } } } } echo " {$type_fields_values_text}"; echo '</span></td>'; echo '<td>' . get_db_value("nombre", "tgrupo", "id_grupo", $incident['id_grupo']); if ($config["show_creator_incident"] == 1) { $id_creator_company = get_db_value("id_company", "tusuario", "id_usuario", $incident["id_creator"]); if ($id_creator_company != 0) { $company_name = (string) get_db_value('name', 'tcompany', 'id', $id_creator_company); echo "<br><span style='font-size:11px;font-style:italic'>{$company_name}</span>"; } } echo '</td>'; $resolution = isset($resolutions[$incident['resolution']]) ? $resolutions[$incident['resolution']] : __('None'); echo '<td class="f9"><strong>' . $statuses[$incident['estado']] . '</strong><br /><em>' . $resolution . '</em></td>'; // priority echo '<td>'; print_priority_flag_image($incident['prioridad']); $last_wu = get_incident_lastworkunit($incident["id_incidencia"]); if ($last_wu["id_user"] == $incident["id_creator"]) { echo "<br><img src='images/comment.gif' title='" . $last_wu["id_user"] . "'>"; } echo '</td>'; echo '<td style="font-size:11px;">' . human_time_comparation($incident["actualizacion"]); // Show only if it's different if ($incident["inicio"] != $incident["actualizacion"]) { echo "<br><em>[" . human_time_comparation($incident["inicio"]); echo "]</em>"; } echo "<br>"; echo '<span style="font-size:9px;">'; if (isset($config["show_user_name"]) && $config["show_user_name"]) { $updated_by = get_db_value('nombre_real', 'tusuario', 'id_usuario', $last_wu["id_user"]); } else { $updated_by = $last_wu["id_user"]; } echo $updated_by; echo "</span>"; echo '</td>'; if ($config["show_creator_incident"] == 1) { echo "<td class='f9'>"; if (isset($config["show_user_name"]) && $config["show_user_name"]) { $incident_creator = get_db_value('nombre_real', 'tusuario', 'id_usuario', $incident["id_creator"]); } else { $incident_creator = $incident["id_creator"]; } //~ echo substr($incident_creator,0,12); echo $incident_creator; echo "</td>"; } if ($config["show_owner_incident"] == 1) { echo "<td class='f9'>"; if (isset($config["show_user_name"]) && $config["show_user_name"]) { $incident_owner = get_db_value('nombre_real', 'tusuario', 'id_usuario', $incident["id_usuario"]); } else { $incident_owner = $incident["id_usuario"]; } echo $incident_owner; echo "</td>"; } echo '</tr>'; } } echo "</tbody>"; echo "</table>"; if (!$report_mode) { pagination($count, $url, $offset, false, $aux_text); } if ($print_result_count) { echo "<h5>" . $count . __(" ticket(s) found") . "</h5>"; } echo "<br>"; }