function human_time_comparation($timestamp) { global $config; if (!is_numeric($timestamp)) { $timestamp = strtotime($timestamp); } $seconds = get_system_time() - $timestamp; return human_time_description_raw($seconds); }
function task_activity_graph($id_task, $width = 900, $height = 230, $area = false, $return = false) { global $config; $task = get_db_row("ttask", "id", $id_task); $output = ""; $start_unixdate = strtotime($task["start"]); $end_unixdate = strtotime("now"); $period = $end_unixdate - $start_unixdate; $resolution = 50; $interval = (int) ($period / $resolution); if (!$area) { $output .= __("Each bar is") . " " . human_time_description_raw($interval); $output .= "<br>"; } $data = get_db_all_rows_sql("SELECT tworkunit.duration as duration, \n tworkunit.timestamp as timestamp FROM tworkunit, tworkunit_task, ttask \n\t\t\tWHERE tworkunit_task.id_task = {$id_task}\n\t\t\tAND tworkunit_task.id_workunit = tworkunit.id GROUP BY tworkunit.id ORDER BY timestamp ASC"); if ($data === false) { $data = array(); } $min_necessary = 1; // Check available data if (count($data) < $min_necessary) { return; } // Set initial conditions $chart = array(); $names = array(); $chart2 = array(); // Calculate chart data for ($i = 0; $i < $resolution; $i++) { $timestamp = $start_unixdate + $interval * $i; $total = 0; $j = 0; while (isset($data[$j])) { $dftime = strtotime($data[$j]['timestamp']); if ($dftime >= $timestamp && $dftime < $timestamp + $interval) { $total += $data[$j]['duration']; } $j++; } $time_format = "M d"; $timestamp_human = clean_flash_string(date($time_format, $timestamp)); $chart2[$timestamp_human] = $total; } $colors['1day']['color'] = "#2179B1"; $colors['1day']['border'] = "#000"; $colors['1day']['alpha'] = 100; foreach ($chart2 as $key => $ch) { $chart3[$key]['1day'] = $ch; } $legend = array(); $xaxisname = __('Days'); $yaxisname = __('Hours'); if ($area) { $output .= area_graph($config['flash_charts'], $chart3, $width, $height, $colors, $legend, '', '', '', $yaxisname, '', '', $config['font'], $config['fontsize']); } else { $output .= vbar_graph($config['flash_charts'], $chart3, $width, $height, $colors, $legend, $xaxisname, $yaxisname, "", "", $config['font'], $config['fontsize']); } if ($return) { return $output; } else { echo $output; } }