/**
 * Print a table with statistics of a list of incidents.
 *
 * @param array List of incidents to get stats.
 * @param bool Whether to return an output string or echo now (optional, echo by default).
 *
 * @return Incidents stats if return parameter is true. Nothing otherwise
 */
function print_incidents_stats_simply($incidents, $return = false, $simple_mode = false)
{
    global $config;
    require_once $config["homedir"] . "/include/functions_graph.php";
    $pdf_output = (int) get_parameter('pdf_output', 0);
    $ttl = $pdf_output + 1;
    // Max graph legend string length (without the '...')
    $max_legend_strlen = 17;
    // Necessary for flash graphs
    include_flash_chart_script();
    // TODO: Move this function to function_graphs to encapsulate flash
    // chart script inclusion or make calls to functions_graph when want
    // print a flash chart
    $output = '';
    $total = sizeof($incidents);
    $opened = 0;
    $total_hours = 0;
    $total_workunits = 0;
    $total_lifetime = 0;
    $max_lifetime = 0;
    $oldest_incident = false;
    $scoring_sum = 0;
    $scoring_valid = 0;
    if ($incidents === false) {
        $incidents = array();
    }
    $assigned_users = array();
    $creator_users = array();
    $submitter_label = "";
    $user_assigned_label = "";
    $incident_id_array = array();
    //Initialize incident status array
    $incident_status = array();
    $incident_status[STATUS_NEW] = 0;
    $incident_status[STATUS_UNCONFIRMED] = 0;
    $incident_status[STATUS_ASSIGNED] = 0;
    $incident_status[STATUS_REOPENED] = 0;
    $incident_status[STATUS_VERIFIED] = 0;
    $incident_status[STATUS_RESOLVED] = 0;
    $incident_status[STATUS_PENDING_THIRD_PERSON] = 0;
    $incident_status[STATUS_CLOSED] = 0;
    //Initialize priority array
    $incident_priority = array();
    $incident_priority[PRIORITY_INFORMATIVE] = 0;
    $incident_priority[PRIORITY_LOW] = 0;
    $incident_priority[PRIORITY_MEDIUM] = 0;
    $incident_priority[PRIORITY_SERIOUS] = 0;
    $incident_priority[PRIORITY_VERY_SERIOUS] = 0;
    $incident_priority[PRIORITY_MAINTENANCE] = 0;
    //Initialize status timing array
    $incident_status_timing = array();
    $incident_status_timing[STATUS_NEW] = 0;
    $incident_status_timing[STATUS_UNCONFIRMED] = 0;
    $incident_status_timing[STATUS_ASSIGNED] = 0;
    $incident_status_timing[STATUS_REOPENED] = 0;
    $incident_status_timing[STATUS_VERIFIED] = 0;
    $incident_status_timing[STATUS_RESOLVED] = 0;
    $incident_status_timing[STATUS_PENDING_THIRD_PERSON] = 0;
    $incident_status_timing[STATUS_CLOSED] = 0;
    //Initialize users time array
    $users_time = array();
    //Initialize groups time array
    $groups_time = array();
    foreach ($incidents as $incident) {
        $inc_stats = incidents_get_incident_stats($incident["id_incidencia"]);
        if ($incident['actualizacion'] != '0000-00-00 00:00:00') {
            $lifetime = $inc_stats[INCIDENT_METRIC_TOTAL_TIME];
            if ($lifetime > $max_lifetime) {
                $oldest_incident = $incident;
                $max_lifetime = $lifetime;
            }
            $total_lifetime += $lifetime;
        }
        //Complete incident status timing array
        foreach ($inc_stats[INCIDENT_METRIC_STATUS] as $key => $value) {
            $incident_status_timing[$key] += $value;
        }
        //fill users time array
        foreach ($inc_stats[INCIDENT_METRIC_USER] as $user => $time) {
            if (!isset($users_time[$user])) {
                $users_time[$user] = $time;
            } else {
                $users_time[$user] += $time;
            }
        }
        //Inidents by group time
        foreach ($inc_stats[INCIDENT_METRIC_GROUP] as $key => $time) {
            if (!isset($groups_time[$key])) {
                $groups_time[$key] = $time;
            } else {
                $groups_time[$key] += $time;
            }
        }
        //Get only id from incident filter array
        //used for filter in some functions
        array_push($incident_id_array, $incident['id_incidencia']);
        // Take count of assigned / creator users
        if (isset($assigned_users[$incident["id_usuario"]])) {
            $assigned_users[$incident["id_usuario"]]++;
        } else {
            $assigned_users[$incident["id_usuario"]] = 1;
        }
        if (isset($creator_users[$incident["id_creator"]])) {
            $creator_users[$incident["id_creator"]]++;
        } else {
            $creator_users[$incident["id_creator"]] = 1;
        }
        // Scoring avg.
        if ($incident["score"] > 0) {
            $scoring_valid++;
            $scoring_sum = $scoring_sum + $incident["score"];
        }
        $hours = get_incident_workunit_hours($incident['id_incidencia']);
        $workunits = get_incident_workunits($incident['id_incidencia']);
        $total_hours += $hours;
        $total_workunits = $total_workunits + sizeof($workunits);
        //Open incidents
        if ($incident["estado"] != 7) {
            $opened++;
        }
        //Incidents by status
        $incident_status[$incident["estado"]]++;
        //Incidents by priority
        $incident_priority[$incident["prioridad"]]++;
    }
    $closed = $total - $opened;
    $opened_pct = 0;
    $mean_work = 0;
    $mean_lifetime = 0;
    if ($total != 0) {
        $opened_pct = format_numeric($opened / $total * 100);
        $mean_work = format_numeric($total_hours / $total, 2);
    }
    $mean_lifetime = $total_lifetime / $total;
    // Get avg. scoring
    if ($scoring_valid > 0) {
        $scoring_avg = format_numeric($scoring_sum / $scoring_valid);
    } else {
        $scoring_avg = "N/A";
    }
    // Get incident SLA compliance
    $sla_compliance = get_sla_compliance($incidents);
    //Create second table
    // Find the 5 most active users (more hours worked)
    $most_active_users = array();
    if ($incident_id_array) {
        $most_active_users = get_most_active_users(8, $incident_id_array);
    }
    $users_label = '';
    $users_data = array();
    foreach ($most_active_users as $user) {
        $users_data[$user['id_user']] = $user['worked_hours'];
    }
    // Remove the items with no value
    foreach ($users_data as $key => $value) {
        if (!$value || $value <= 0) {
            unset($users_data[$key]);
        }
    }
    if (empty($most_active_users) || empty($users_data)) {
        $users_label = "<div class='container_adaptor_na_graphic2'>";
        $users_label .= graphic_error(false);
        $users_label .= __("N/A");
        $users_label .= "</div>";
    } else {
        arsort($users_data);
        $users_label .= pie3d_graph($config['flash_charts'], $users_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    }
    // Find the 5 most active incidents (more worked hours)
    $most_active_incidents = get_most_active_incidents(5, $incident_id_array);
    $incidents_label = '';
    foreach ($most_active_incidents as $incident) {
        $incidents_data[$incident['id_incidencia']] = $incident['worked_hours'];
    }
    // Remove the items with no value
    foreach ($incidents_data as $key => $value) {
        if (!$value || $value <= 0) {
            unset($incidents_data[$key]);
        }
    }
    if (empty($most_active_incidents) || empty($incidents_data)) {
        $incidents_label .= graphic_error(false);
        $incidents_label .= __("N/A");
        $incidents_label = "<div class='container_adaptor_na_graphic'>" . $incidents_label . "</div>";
    } else {
        arsort($incidents_data);
        $incidents_label .= pie3d_graph($config['flash_charts'], $incidents_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    }
    // TOP X creator users
    $creator_assigned_data = array();
    foreach ($creator_users as $clave => $valor) {
        $creator_assigned_data["{$clave} ({$valor})"] = $valor;
    }
    if (empty($creator_assigned_data)) {
        $submitter_label = "<div style='width:300px; height:150px;'>";
        $submitter_label .= graphic_error(false);
        $submitter_label .= __("N/A");
        $submitter_label .= "</div>";
    } else {
        arsort($creator_assigned_data);
        $submitter_label .= "<br/>" . pie3d_graph($config['flash_charts'], $creator_assigned_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    }
    // TOP X scoring users
    $scoring_label = "";
    $top5_scoring = get_best_incident_scoring(5, $incident_id_array);
    foreach ($top5_scoring as $submitter) {
        $scoring_data[$submitter["id_usuario"]] = $submitter["total"];
    }
    if (empty($top5_scoring)) {
        $scoring_label .= graphic_error(false);
        $scoring_label .= __("N/A");
        $scoring_label = "<div class='container_adaptor_na_graphic2'>" . $scoring_label . "</div>";
    } else {
        arsort($scoring_data);
        $scoring_label .= "<br/>" . pie3d_graph($config['flash_charts'], $scoring_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    }
    // TOP X assigned users
    $user_assigned_data = array();
    foreach ($assigned_users as $clave => $valor) {
        $user_assigned_data["{$clave} ({$valor})"] = $valor;
    }
    if (empty($user_assigned_data)) {
        $user_assigned_label = "<div style='width:300px; height:150px;'>";
        $user_assigned_label .= graphic_error(false);
        $user_assigned_label .= __("N/A");
        $user_assigned_label .= "</div>";
    } else {
        arsort($user_assigned_data);
        $user_assigned_label .= "<br/>" . pie3d_graph($config['flash_charts'], $user_assigned_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    }
    // Show graph with incidents by group
    foreach ($incidents as $incident) {
        $grupo = safe_output(dame_grupo($incident["id_grupo"]));
        if (strlen($grupo) > $max_legend_strlen) {
            $grupo = substr($grupo, 0, $max_legend_strlen) . "...";
        }
        if (!isset($incident_group_data[$grupo])) {
            $incident_group_data[$grupo] = 0;
        }
        $incident_group_data[$grupo] = $incident_group_data[$grupo] + 1;
    }
    arsort($incident_group_data);
    // Show graph with incidents by source group
    foreach ($incidents as $incident) {
        $grupo_src = safe_output(dame_grupo($incident["id_group_creator"]));
        if (strlen($grupo_src) > $max_legend_strlen) {
            $grupo_src = substr($grupo_src, 0, $max_legend_strlen) . "...";
        }
        if (!isset($incident_group_data2[$grupo_src])) {
            $incident_group_data2[$grupo_src] = 0;
        }
        $incident_group_data2[$grupo_src] = $incident_group_data2[$grupo_src] + 1;
    }
    arsort($incident_group_data2);
    // Show graph with tickets open/close histogram
    $ticket_oc_graph = '<div class="pie_frame">' . graph_ticket_oc_histogram($incidents, 650, 250, $ttl) . "</div>";
    $container_title = __("Ticket Open/Close histogram");
    $container_ticket_oc = print_container('container_ticket_oc', $container_title, $ticket_oc_graph, 'open', true, true, "container_simple_title", "container_simple_div");
    // Show graph with tickets open/close histogram
    $ticket_activity_graph = '<div class="pie_frame">' . graph_ticket_activity_calendar($incidents) . "</div>";
    $container_title = __("Ticket activity");
    $container_ticket_activity = print_container('container_ticket_activity', $container_title, $ticket_activity_graph, 'open', true, true, "container_simple_title", "container_simple_div");
    //Print first table
    $output .= "<table class='listing' width=190px border=0 cellspacing=0 cellpadding=0 border=0 >";
    $output .= "<tr>";
    $output .= "<th>" . __("Metric") . "</th>";
    $output .= "<th>" . __("Value") . "</th>";
    $output .= "</tr>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>" . __('Total tickets') . "</strong></td>";
    $output .= "<td valign=top align=center>";
    $output .= $total;
    $output .= "</td>";
    $output .= "</tr>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>" . __('Avg. life time') . "</strong></td>";
    $output .= "<td valign=top align=center>";
    $output .= format_numeric($mean_lifetime / 86400, 2) . " " . __("Days");
    $output .= "</td>";
    $output .= "</tr>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>";
    $output .= __('Avg. work time');
    $output .= "</strong></td>";
    $output .= "<td align=center>" . $mean_work . ' ' . __('Hours') . "</td>";
    $output .= "</tr>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>";
    $output .= __('Avg. Scoring');
    $output .= "</strong></td>";
    $output .= "<td align=center>" . $scoring_avg . "</td>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>";
    $output .= __('Total work time');
    $output .= "</strong></td>";
    $output .= "<td align=center>" . $total_hours . " " . __("Hours") . "</td>";
    $output .= "</tr>";
    $output .= "<tr>";
    $output .= "<td align=center><strong>";
    $output .= __('Total work units');
    $output .= "</strong></td>";
    $output .= "<td align=center>" . $total_workunits . "</td>";
    $output .= "</tr></table>";
    $container_title = __("Tickets statistics");
    $container_incident_statistics = print_container('container_incident_statistics', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $output = "<div class='pie_frame'>" . $incidents_label . "</div>";
    $container_title = __("Top 5 active tickets");
    $container_top5_incidents = print_container('container_top5_incidents', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    if ($incidents) {
        $output = graph_incident_statistics_sla_compliance($incidents, 300, 150, $ttl);
    } else {
        $output = "<div style='width:300px; height:150px;'>";
        $output .= graphic_error(false);
        $output .= __("N/A");
        $output .= "</div>";
    }
    $output = "<div class='container_adaptor_graphic'>" . $output . "</div>";
    $output = "<div class='pie_frame'>" . $output . "</div>";
    $container_title = __("SLA compliance");
    $container_sla_compliance = print_container('container_sla_compliance', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $status_aux .= "<table class='listing' style='width: 420px; margin: 10px auto;' cellspacing=0 cellpadding=0 border=0>";
    $status_aux .= "<tr>";
    $status_aux .= "<th style='text-align:center;'><strong>" . __("Status") . "</strong></th>";
    $status_aux .= "<th style='text-align:center;'><strong>" . __("Number") . "</strong></th>";
    $status_aux .= "<th style='text-align:center;'><strong>" . __("Total time") . "</strong></th>";
    $status_aux .= "</tr>";
    foreach ($incident_status as $key => $value) {
        $name = get_db_value('name', 'tincident_status', 'id', $key);
        $status_aux .= "<tr>";
        $status_aux .= "<td>" . $name . "</td>";
        $status_aux .= "<td style='text-align:center;'>" . $value . "</td>";
        $time = $incident_status_timing[$key];
        $status_aux .= "<td style='text-align:center;'>" . give_human_time($time, true, true, true) . "</td>";
        $status_aux .= "</tr>";
    }
    $status_aux .= "</table>";
    $container_title = __("Ticket by status");
    $container_status_incidents = print_container('container_status_incidents', $container_title, $status_aux, 'no', true, true, "container_simple_title", "container_simple_div");
    $priority_aux .= "<table class='listing table_priority_report' style='width: 420px;' cellspacing=0 cellpadding=0 border=0>";
    $priority_aux .= "<tr>";
    $priority_aux .= "<th style='text-align:center;'><strong>" . __("Priority") . "</strong></th>";
    $priority_aux .= "<th style='text-align:center;'><strong>" . __("Number") . "</strong></th>";
    $priority_aux .= "</tr>";
    foreach ($incident_priority as $key => $value) {
        $priority_aux .= "<tr>";
        $priority_aux .= "<td>" . get_priority_name($key) . "</td>";
        $priority_aux .= "<td style='text-align:center;'>" . $value . "</td>";
        $priority_aux .= "</tr>";
    }
    $priority_aux .= "</table>";
    $priority_aux = $priority_aux;
    $container_title = __("Tickets by priority");
    $container_priority_incidents = print_container('container_priority_incidents', $container_title, $priority_aux, 'no', true, true, "container_simple_title", "container_simple_div");
    if ($oldest_incident) {
        $oldest_incident_time = get_incident_workunit_hours($oldest_incident["id_incidencia"]);
        $output = "<table class='listing'>";
        $output .= "<th>";
        $output .= __("Metric");
        $output .= "</th>";
        $output .= "<th>";
        $output .= __("Value");
        $output .= "</th>";
        $output .= "</tr>";
        $output .= "<tr>";
        $output .= "<td>";
        $output .= "<strong>" . __("Ticket Id") . "</strong>";
        $output .= "</td>";
        $output .= "<td>";
        $output .= '<a href="index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=' . $oldest_incident['id_incidencia'] . '">#' . $oldest_incident['id_incidencia'] . "</strong></a>";
        $output .= "</td>";
        $output .= "</tr>";
        $output .= "<tr>";
        $output .= "<td>";
        $output .= "<strong>" . __("Ticket title") . "</strong>";
        $output .= "</td>";
        $output .= "<td>";
        $output .= '<a href="index.php?sec=incidents&sec2=operation/incidents/incident_dashboard_detail&id=' . $oldest_incident['id_incidencia'] . '">' . $oldest_incident['titulo'] . "</strong></a>";
        $output .= "</td>";
        $output .= "</tr>";
        $output .= "<tr>";
        $output .= "<td>";
        $output .= "<strong>" . __("Worktime hours") . "</strong>";
        $output .= "</td>";
        $output .= "<td>";
        $output .= $oldest_incident_time . " " . __("Hours");
        $output .= "</td>";
        $output .= "</tr>";
        $output .= "<tr>";
        $output .= "<td>";
        $output .= "<strong>" . __("Lifetime") . "</strong>";
        $output .= "</td>";
        $output .= "<td>";
        $output .= format_numeric($max_lifetime / 86400) . " " . __("Days");
        $output .= "</td>";
        $output .= "</tr>";
        $output .= "</table>";
    } else {
        $output = graphic_error(false);
        $output .= __("N/A");
    }
    $output_aux = "<div style='width:100%; height:170px;'>";
    $output_aux .= $output;
    $output_aux .= "</div>";
    $container_title = __("Longest closed ticket");
    $container_longest_closed = print_container('container_longest_closed', $container_title, $output_aux, 'no', true, true, "container_simple_title", "container_simple_div");
    $data = array(__('Open') => $opened, __('Closed') => $total - $opened);
    $data = array(__('Close') => $total - $opened, __('Open') => $opened);
    $output = pie3d_graph($config['flash_charts'], $data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'], $ttl);
    $output = "<div class='pie_frame'>" . $output . "</div>";
    $container_title = __("Open / Close ticket");
    $container_openclose_incidents = print_container('container_openclose_incidents', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $clean_output = get_parameter("clean_output");
    $container_title = __("Top active users");
    $output = "<div class='pie_frame'>" . $users_label . "</div>";
    $container_topactive_users = print_container('container_topactive_users', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $container_title = __("Top ticket submitters");
    $output = "<div class='pie_frame'>" . $submitter_label . "</div>";
    $container_topincident_submitter = print_container('container_topincident_submitter', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $container_title = __("Top assigned users");
    $output = "<div class='pie_frame'>" . $user_assigned_label . "</div>";
    $container_user_assigned = print_container('container_user_assigned', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $container_title = __("Tickets by group");
    $output = "<br/>" . pie3d_graph($config['flash_charts'], $incident_group_data, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'] - 1, $ttl);
    $output = "<div class='pie_frame'>" . $output . "</div>";
    $container_incidents_group = print_container('container_incidents_group', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $container_title = __("Tickets by creator group");
    $output = "<br/>" . pie3d_graph($config['flash_charts'], $incident_group_data2, 300, 150, __('others'), $config["base_url"], "", $config['font'], $config['fontsize'] - 1, $ttl);
    $output = "<div class='pie_frame'>" . $output . "</div>";
    $container_incident_creator_group = print_container('container_incident_creator_group', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $container_title = __("Top 5 average scoring by user");
    $output = "<div class='pie_frame'>" . $scoring_label . "</div>";
    $container_top5_scoring = print_container('container_top5_scoring', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    //Print second table
    $output = "<table class='listing' style='width: 320px; margin: 10px auto'>";
    $output .= "<tr>";
    $output .= "<th style='text-align:center;'><strong>" . __("Group") . "</strong></th>";
    $output .= "<th style='text-align:center;'><strong>" . __("Time") . "</strong></th>";
    $output .= "</tr>";
    $count = 1;
    arsort($groups_time);
    foreach ($groups_time as $key => $value) {
        //Only show first 5
        if ($count == 5) {
            break;
        }
        $output .= "<tr>";
        $group_name = get_db_value('nombre', 'tgrupo', 'id_grupo', $key);
        $output .= "<td>" . $group_name . "</td>";
        $output .= "<td style='text-align: center'>" . give_human_time($value, true, true, true) . "</td>";
        $output .= "</tr>";
        $count++;
    }
    $output .= "</table>";
    $output .= '<br>';
    $output .= '<br>';
    $container_title = __("Top 5 group by time");
    $container_top5_group_time = print_container('container_top5_group_time', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    $output = "<table class='listing' style='width: 420px; margin: 10px'>";
    $output .= "<tr>";
    $output .= "<th style='text-align:center;'><strong>" . __("User") . "</strong></th>";
    $output .= "<th style='text-align:center;'><strong>" . __("Time") . "</strong></th>";
    $output .= "</tr>";
    $count = 1;
    arsort($users_time);
    foreach ($users_time as $key => $value) {
        //Only show first 5
        if ($count == 5) {
            break;
        }
        $output .= "<tr>";
        $user_real = get_db_value('nombre_real', 'tusuario', 'id_usuario', $key);
        $output .= "<td>" . $user_real . "</td>";
        $output .= "<td style='text-align: center'>" . give_human_time($value, true, true, true) . "</td>";
        $output .= "</tr>";
        $count++;
    }
    $output .= "</table>";
    $output .= "</table>";
    $container_title = __("Top 5 users by time");
    $container_top5_user_time = print_container('container_top5_user_time', $container_title, $output, 'no', true, true, "container_simple_title", "container_simple_div");
    if ($simple_mode) {
        // First row
        echo $container_incidents_group;
        echo $container_topincident_submitter;
        echo $container_user_assigned;
        // Second row
        echo $container_incident_statistics;
        echo $container_top5_group_time;
        echo $container_sla_compliance;
    } else {
        // First row
        echo $container_incidents_group;
        echo $container_topincident_submitter;
        echo $container_user_assigned;
        // Second row
        echo $container_incident_statistics;
        echo $container_top5_group_time;
        echo $container_sla_compliance;
        echo '<br><br>';
        // Third row
        echo $container_status_incidents;
        echo $container_priority_incidents;
        //Fourth row
        echo $container_topactive_users;
        echo $container_top5_incidents;
        echo $container_openclose_incidents;
        echo '<br><br><br>';
        //~ // Fifth row
        echo $container_ticket_oc;
        echo '<br><br><br><br><br><br><br><br><br><br><br><br>';
        //~ // Sixth row
        echo $container_ticket_activity;
    }
}
Esempio n. 2
0
$date_to = get_parameter("date_to", 0);
$mode = get_parameter("mode", 1);
$percent = get_parameter("percent", 0);
$days = get_parameter("days", 0);
$type = get_parameter("type", "");
$background = get_parameter("background", "#ffffff");
$id_incident = get_parameter("id_incident");
$period = get_parameter("period");
$ajax = get_parameter("is_ajax");
if ($type == "incident_a") {
    incident_peruser($width, $height);
} elseif ($type == "workunit_task") {
    graph_workunit_task($width, $height, $id_task);
} elseif ($type == "workunit_user") {
    graph_workunit_user($width, $height, $id_user, $date_from);
} elseif ($type == "workunit_project_user") {
    graph_workunit_project_user($width, $height, $id_user, $date_from, $date_to);
} elseif ($type == "project_tree") {
    project_tree($id_project, $id_user);
} elseif ($type == "all_project_tree") {
    all_project_tree($id_user, $completion, $project_kind);
} elseif ($type == "sla_slicebar") {
    if ($ajax) {
        echo graph_sla_slicebar($id_incident, $period, $width, $height);
    } else {
        graph_sla_slicebar($id_incident, $period, $width, $height);
    }
}
// Always at the end of the funtions_graph
include_flash_chart_script();
Esempio n. 3
0
function fs_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index)
{
    global $config;
    $graph_type = "StackedArea2D";
    $chart = new FusionCharts($graph_type, $width, $height);
    $pixels_between_xdata = 25;
    $max_xdata_display = round($width / $pixels_between_xdata);
    $ndata = count($chart_data);
    if ($max_xdata_display > $ndata) {
        $xdata_display = $ndata;
    } else {
        $xdata_display = $max_xdata_display;
    }
    $step = round($ndata / $xdata_display);
    if (is_array(reset($chart_data))) {
        $data2 = array();
        $count = 0;
        foreach ($chart_data as $i => $values) {
            $count++;
            $show_name = '0';
            if ($count % $step == 0) {
                $show_name = '1';
            }
            if (isset($long_index[$i])) {
                $chart->addCategory($i, 'hoverText=' . $long_index[$i] . ';showName=' . $show_name);
            } else {
                $chart->addCategory($i, 'showName=' . $show_name);
            }
            $c = 0;
            foreach ($values as $i2 => $value) {
                $data2[$i2][$i] = $value;
                $c++;
            }
        }
        $data = $data2;
    } else {
        $data = array($chart_data);
    }
    $a = 0;
    $empty = 1;
    foreach ($data as $i => $value) {
        $legend_text = '';
        if (isset($legend[$i])) {
            $legend_text = $legend[$i];
        }
        $alpha = '';
        $areaBorderColor = '';
        $colour = '';
        $showAreaBorder = 1;
        //0 old default
        if (isset($color[$i])) {
            if (!isset($color[$i]['border'])) {
                $showAreaBorder = 1;
            }
            if (isset($color[$i]['alpha'])) {
                $alpha = 'alpha=' . $color[$i]['alpha'] . ';';
            }
            if (isset($color[$i]['border'])) {
                $areaBorderColor = 'areaBorderColor=#' . $color[$i]['border'] . ';';
            }
            if (isset($color[$i]['color'])) {
                $colour = 'color=#' . $color[$i]['color'];
            }
        }
        $chart->addDataSet($legend_text, $alpha . 'showAreaBorder=' . $showAreaBorder . ';' . $areaBorderColor . $colour);
        $count = 0;
        $step = 10;
        $num_vlines = 0;
        foreach ($value as $i2 => $v) {
            if ($count++ % $step == 0) {
                $show_name = '1';
                $num_vlines++;
            } else {
                $show_name = '0';
            }
            $empty = 0;
            if ($a < 3) {
                $a++;
                //			$chart->addCategory(date('G:i', $i2), //'');
                //				'hoverText=' . date (html_entity_decode ($config['date_format'], ENT_QUOTES, "UTF-8"), $i2) .
                //				';showName=' . $show_name);
            }
            //Add data
            $chart->addChartData($v);
        }
    }
    $chart->setChartParams('animation=0;numVDivLines=' . $num_vlines . ';showShadow=0;showAlternateVGridColor=1;showNames=1;rotateNames=1;' . 'lineThickness=0.1;anchorRadius=0.5;showValues=0;baseFontSize=9;showLimits=0;' . 'showAreaBorder=1;areaBorderThickness=0.1;areaBorderColor=000000' . ($empty == 1 ? ';yAxisMinValue=0;yAxisMaxValue=1' : ''));
    $random_number = uniqid();
    $div_id = 'chart_div_' . $random_number;
    $chart_id = 'chart_' . $random_number;
    $output = '<div id="' . $div_id . '" style="z-index:1;"></div>';
    if (!isset($config['homeurl'])) {
        $config['homeurl'] = '';
    }
    $output .= include_flash_chart_script($config['homeurl']);
    //$output .= '<script language="JavaScript" src="include/graphs/FusionCharts/FusionCharts.js"></script>';
    $output .= '<script type="text/javascript">
			<!--
			function pie_' . $chart_id . ' () {
				var myChart = new FusionCharts("include/graphs/FusionCharts/FCF_' . $graph_type . '.swf", "' . $chart_id . '", "' . $width . '", "' . $height . '", "0", "1");
				myChart.setDataXML("' . addslashes($chart->getXML()) . '");
				myChart.addParam("WMode", "Transparent");
				myChart.render("' . $div_id . '");
			}
					pie_' . $chart_id . ' ();
			-->
		</script>';
    return $output;
}