/**
 * Print a table with statistics of a list of inventories.
 *
 * @param array List of inventories to get stats.
 * @param bool Whether to return an output string or echo now (optional, echo by default).
 *
 * @return Inventories stats if return parameter is true. Nothing otherwise
 */
function print_inventory_stats($inventories, $return = false)
{
    $output = '';
    $total = sizeof($inventories);
    $inventory_incidents = 0;
    $inventory_opened = 0;
    foreach ($inventories as $inventory) {
        $incidents = get_incidents_on_inventory($inventory['id'], false);
        if (sizeof($incidents) == 0) {
            continue;
        }
        $inventory_incidents++;
        foreach ($incidents as $incident) {
            if ($incident['estado'] != 7 && $incident['estado'] != 6) {
                $inventory_opened++;
                break;
            }
        }
    }
    $incidents_pct = 0;
    if ($total != 0) {
        $incidents_pct = format_numeric($inventory_incidents / $total * 100);
        $incidents_opened_pct = format_numeric($inventory_opened / $total * 100);
    }
    $table->width = '50%';
    $table->class = 'float_left blank';
    $table->style = array();
    $table->style[1] = 'vertical-align: top';
    $table->rowspan = array();
    $table->rowspan[0][1] = 3;
    $table->data = array();
    $table->data[0][0] = print_label(__('Total objects'), '', '', true, $total);
    $data = array(__('With tickets') => $inventory_incidents, __('Without tickets') => $total - $inventory_incidents);
    $table->data[0][1] = pie3d_chart($config['flash_charts'], $data, 200, 150);
    $table->data[1][0] = print_label(__('Total objects with tickets'), '', '', true, $inventory_incidents . ' (' . $incidents_pct . '%)');
    $table->data[2][0] = print_label(__('Total objects with opened tickets'), '', '', true, $inventory_opened . ' (' . $incidents_opened_pct . '%)');
    $output .= print_table($table, true);
    if ($return) {
        return $output;
    }
    echo $output;
}
}
//**********************************************************************
// Tabs
//**********************************************************************
print_inventory_tabs('incidents', $id, $inventory_name);
$table->width = '99%';
$table->class = 'listing';
$table->data = array();
$table->head = array();
$table->head[0] = __('Title');
$table->head[1] = __('Date');
$table->head[2] = __('Priority');
$table->head[3] = __('Status');
$table->head[4] = __('Assigned user');
$table->head[5] = __('View');
$incidents = get_incidents_on_inventory($id, false);
foreach ($incidents as $incident) {
    $data = array();
    if (!give_acl($config['id_user'], $incident['id_grupo'], 'IR')) {
        continue;
    }
    $data[0] = $incident['titulo'];
    $data[1] = $incident['inicio'];
    $data[2] = print_priority_flag_image($incident['prioridad'], true);
    $data[3] = get_db_value('name', 'tincident_status', 'id', $incident['estado']);
    $user_avatar = get_db_value('avatar', 'tusuario', 'id_usuario', $incident['id_usuario']);
    $data[4] = print_user_avatar($incident['id_usuario'], true, true);
    $data[4] .= " " . $incident['id_usuario'];
    $data[5] = '<a href="index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=' . $incident['id_incidencia'] . '"><img src="images/zoom.png" /></a>';
    array_push($table->data, $data);
}