Пример #1
0
<?php

function format_seconds($secs)
{
    $vals = array('d' => $secs / 86400 % 7, 'h' => $secs / 3600 % 24, 'm' => $secs / 60 % 60, 's' => $secs % 60);
    $ret = array();
    foreach ($vals as $k => $v) {
        if ($v > 0) {
            $ret[] = sprintf('%02d', $v);
        }
    }
    return join(':', $ret);
}
var_dump(format_seconds(3602 * 25));
Пример #2
0
         echo "<td><script type='text/javascript'>\n//<![CDATA[\n";
         echo "var act = new Activity();";
         echo "act.id = {$task->id};";
         echo "act.start = {$startdate}; ";
         echo "addActivity(act);";
         echo "\n//]]>\n</script>";
         echo "{$strNotCompleted}</td>";
         $duration = $now - $startdate;
         //echo "<td id='duration{$task->id}'><em><div id='duration{$task->id}'>".format_seconds($duration)."</div></em></td>";
         echo "<td id='duration{$task->id}'>" . format_seconds($duration) . "</td>";
     } else {
         $duration = $enddate - $startdate;
         $a = $duration % $billing[-1]['customerperiod'];
         $duration += $billing[-1]['customerperiod'] - $a;
         echo "<td>" . format_date_friendly($enddate) . "</td>";
         echo "<td>" . format_seconds($duration) . "</td>";
         $closedduration += $duration;
         $temparray['owner'] = $task->owner;
         $temparray['starttime'] = $startdate;
         $temparray['duration'] = $duration;
         $billing[$task->owner][] = $temparray;
     }
     $totalduration += $duration;
     echo "<td>" . format_date_friendly($lastupdated) . "</td>";
 }
 if ($show == 'completed') {
     echo "<td>";
     if ($enddate > 0) {
         echo ldate($CONFIG['dateformat_date'], $enddate);
     }
     echo "</td>";
$product_name = product_name($incident->product);
if ($incident->softwareid > 0) {
    $software_name = software_name($incident->softwareid);
}
$servicelevel_id = maintenance_servicelevel($incident->maintenanceid);
$servicelevel_tag = $incident->servicelevel;
if ($servicelevel_tag == '') {
    $servicelevel_tag = servicelevel_id2tag(maintenance_servicelevel($incident->maintenanceid));
}
$servicelevel_name = servicelevel_name($servicelevelid);
if ($incident->closed == 0) {
    $closed = time();
} else {
    $closed = $incident->closed;
}
$opened_for = format_seconds($closed - $incident->opened);
$priority = $incident->priority;
// Lookup the service level times
$slsql = "SELECT * FROM `{$dbServiceLevels}` WHERE tag='{$servicelevel_tag}' AND priority='{$incident->priority}' ";
$slresult = mysql_query($slsql);
if (mysql_error()) {
    trigger_error("MySQL Query Error " . mysql_error(), E_USER_WARNING);
}
$servicelevel = mysql_fetch_object($slresult);
// Get next target
$target = incident_get_next_target($incidentid);
// Calculate time remaining in SLA
$working_day_mins = ($CONFIG['end_working_day'] - $CONFIG['start_working_day']) / 60;
switch ($target->type) {
    case 'initialresponse':
        $slatarget = $servicelevel->initial_response_mins;
Пример #4
0
function pdf_availability()
{
    global $g_si, $g_start, $g_end, $g_period, $g_canvas, $g_label, $g_downtimes;
    $stat = get_stats_service();
    if (!$stat) {
        return;
    }
    $downtimes = $g_downtimes;
    if (is_null($downtimes)) {
        $downtimes = $stat->getDownTimes($g_si, $g_start * 1000, $g_end * 1000);
        $g_downtimes = $downtimes;
    }
    if (is_null($downtimes)) {
        $g_canvas->newLine();
        $g_canvas->writeTextLineIndent(20, "No Data");
        return;
    }
    $downtimes = array_reverse($downtimes);
    $total = 0;
    $count = 0;
    foreach ($downtimes as $downtime) {
        $et = $downtime->ET;
        if ($et > 0) {
            $total += $et;
            $count++;
        }
    }
    $total /= 1000;
    $avg = 0;
    if ($count > 0) {
        $avg = $total / $count;
    }
    $uptime = 100 - $total / $g_period * 100;
    $g_canvas->writeSubsection("Availability");
    $col1 = 120;
    $col2 = 300;
    $g_canvas->writeTextColumn($col1, 'r', "Period:");
    $g_canvas->writeTextColumn($col2, 'l', format_seconds($g_period));
    $g_canvas->newLine();
    $g_canvas->writeTextColumn($col1, 'r', "Data Range:");
    $g_canvas->writeTextColumn($col2, 'l', date("Y-m-d H:i", $g_start) . " through " . date("Y-m-d H:i", $g_end));
    $g_canvas->newLine();
    $g_canvas->writeTextColumn($col1, 'r', "Number of Downtimes:");
    $g_canvas->writeTextColumn($col2, 'l', $count);
    $g_canvas->newLine();
    $g_canvas->writeTextColumn($col1, 'r', "Total Downtime:");
    $g_canvas->writeTextColumn($col2, 'l', format_seconds($total));
    $g_canvas->newLine();
    $g_canvas->writeTextColumn($col1, 'r', "Average Downtime Period:");
    $g_canvas->writeTextColumn($col2, 'l', format_seconds($avg));
    $g_canvas->newLine();
    $g_canvas->writeTextColumn($col1, 'r', "Availability: ");
    $g_canvas->writeTextColumn($col2, 'l', number_format($uptime, 4) . "%");
    $g_canvas->newLine();
    $g_canvas->writeSubsection("Downtimes");
    $col1 = 120;
    $col2 = 120;
    $col3 = 100;
    $col4 = 185;
    $g_canvas->setFont("Courier-Bold", 9);
    $g_canvas->writeTextColumnHeader($col1, 'l', "Stop Time");
    $g_canvas->writeTextColumnHeader($col2, 'l', "Restart Time");
    $g_canvas->writeTextColumnHeader($col3, 'l', "Elapsed Time");
    $g_canvas->writeTextColumnHeader($col3, 'l', "Notes");
    $g_canvas->newLine();
    $g_canvas->newLine();
    $g_canvas->setFont("Courier", 9);
    foreach ($downtimes as $downtime) {
        $et = $downtime->ET / 1000;
        if ($downtime->isDataAbsent()) {
            $note = '* No data: using report start time';
        } else {
            if ($downtime->isEstimated()) {
                $note = '* Approximate';
            } else {
                $note = '';
            }
        }
        $g_canvas->writeTextColumn($col1, 'l', date("Y-m-d H:i:s", $downtime->startTime / 1000) . ($note ? " *" : ""));
        $g_canvas->writeTextColumn($col2, 'l', date("Y-m-d H:i:s", $downtime->endTime / 1000));
        $g_canvas->writeTextColumn($col3, 'l', format_seconds($et));
        $g_canvas->writeTextColumn($col4, 'l', $note);
        $g_canvas->newLine();
    }
}
Пример #5
0
 } elseif ($schedule->status == 'disabled') {
     $shade = 'expired';
 } elseif ($lastruntime > 0 and $lastruntime + $schedule->interval < $now) {
     $shade = 'notice';
 }
 echo "<tr class='{$shade}'>";
 echo "<td><a class='info' href='{$_SERVER['PHP_SELF']}?mode=edit&amp;id={$schedule->id}'>{$schedule->action}";
 echo "<span>";
 echo "{$schedule->description}";
 if (!empty($schedule->params)) {
     echo "\n<br /><strong>{$schedule->paramslabel} = {$schedule->params}</strong>";
 }
 echo "</span></a></td>";
 echo "<td>{$schedule->start}</td>";
 if ($schedule->type == 'interval') {
     echo "<td>" . format_seconds($schedule->interval, TRUE) . "</td>";
 } elseif ($schedule->type == 'date') {
     echo "<td>";
     if ($schedule->date_type == 'month') {
         echo sprintf($strDayOfMonth, $schedule->date_offset);
     } elseif ($schedule->date_type == 'year') {
         echo sprintf($strDayOfYear, $schedule->date_offset);
     }
     echo "</td>";
 }
 echo "<td>";
 if (mysql2date($schedule->end) > 0) {
     echo "{$schedule->end}";
 } else {
     echo "-";
 }
Пример #6
0
         $times = array();
         foreach ($items as $item) {
             $timediff = strtotime($item['eventEndDate']) - strtotime($item['eventStartDate']);
             $times[$item['description']] += $timediff;
             $daytime += $timediff;
         }
         ksort($times);
         $html = array();
         foreach ($times as $description => $time) {
             $html[] = "<strong>{$description}</strong>: " . format_seconds($time);
         }
         echo implode('<br />', $html);
         echo "</td>";
         echo "<td>";
         if ($daytime > 0) {
             echo format_seconds($daytime);
         }
         echo "</td>";
         $date += 86400;
     }
     echo "</table>";
     echo "<p align = 'center'><a href='{$_SERVER['PHP_SELF']}?user={$user}&amp;date={$date}&amp;approve=1'>{$strApprove}</a> | ";
     echo "<a href='{$_SERVER['PHP_SELF']}?user={$user}&amp;date={$date}&amp;approve=2'>{$strDecline}</a></p>";
     include APPLICATION_INCPATH . 'htmlfooter.inc.php';
 } else {
     if ($approve == 1) {
         $newCompletion = 2;
     } else {
         $newCompletion = 0;
     }
     $sql = "UPDATE `{$dbTasks}` SET completion = {$newCompletion} WHERE distribution = 'event' AND owner = {$user} ";
			print "<td valign=\"bottom\" align=\"right\" width=\"5%\" class=\"calendar_cell_right\">\n\t\t";
			print "<a href=\"javascript:void(0)\" onclick=\"javascript:window.open(" .
						"'trans_info.php?trans_num=$data[trans_num]'" . 
						",'Task Event Info','location=0,directories=no" .
						",status=no,scrollbar=yes,menubar=no,resizable=1,width=500,height=200')\">";
			print "&nbsp;&nbsp;$data[diff_time]<a>\n\t</td>\n</tr>\n";
			$total_time += $data["diff"];
			$grand_total_time += $data["diff"];
		}
  
		if ($total_time) {
			$formatted_time = format_seconds($total_time);
			print "<tr><td colspan=\"4\" align=\"right\" class=\"calendar_totals_line_weekly_right\">" .
							"Total: <span class=\"calendar_total_value_weekly\">$formatted_time</span></td></tr>";
		}
		$formatted_time = format_seconds($grand_total_time);
	}

?>
						</tr>
					</td>
				</table>
			</td>
		</tr>
<? 
	if ($num > 0)
	{
?>
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_bottom_panel">
Пример #8
0
/**
    * Create a PNG chart
    * @author Ivan Lucas
    * @param string $type. The type of chart to draw. (e.g. 'pie').
    * @return resource a PNG image resource
    * @note Currently only has proper support for pie charts (type='pie')
    * @todo TODO Support for bar and line graphs
*/
function draw_chart_image($type, $width, $height, $data, $legends, $title = '', $unit = '')
{
    global $CONFIG;
    // Graph settings
    if (empty($width)) {
        $width = 500;
    }
    if (empty($height)) {
        $height = 150;
    }
    $fontfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . "FreeSans.ttf";
    // FIXME font file!
    if (!empty($fontfile) and file_exists($fontfile)) {
        $use_ttf = TRUE;
    } else {
        $use_ttf = FALSE;
    }
    $countdata = count($data);
    $sumdata = array_sum($data);
    if ($countdata > 8) {
        $height += ($countdata - 8) * 14;
    }
    $img = imagecreatetruecolor($width, $height);
    $white = imagecolorallocate($img, 255, 255, 255);
    $blue = imagecolorallocate($img, 240, 240, 255);
    $midblue = imagecolorallocate($img, 204, 204, 255);
    $darkblue = imagecolorallocate($img, 32, 56, 148);
    $black = imagecolorallocate($img, 0, 0, 0);
    $grey = imagecolorallocate($img, 224, 224, 224);
    $red = imagecolorallocate($img, 255, 0, 0);
    imagefill($img, 0, 0, $white);
    $rgb[] = "190,190,255";
    $rgb[] = "205,255,255";
    $rgb[] = "255,255,156";
    $rgb[] = "156,255,156";
    $rgb[] = "255,205,195";
    $rgb[] = "255,140,255";
    $rgb[] = "100,100,155";
    $rgb[] = "98,153,90";
    $rgb[] = "205,210,230";
    $rgb[] = "192,100,100";
    $rgb[] = "204,204,0";
    $rgb[] = "255,102,102";
    $rgb[] = "0,204,204";
    $rgb[] = "0,255,0";
    $rgb[] = "255,168,88";
    $rgb[] = "128,0,128";
    $rgb[] = "0,153,153";
    $rgb[] = "255,230,204";
    $rgb[] = "128,170,213";
    $rgb[] = "75,75,75";
    // repeats...
    $rgb[] = "190,190,255";
    $rgb[] = "156,255,156";
    $rgb[] = "255,255,156";
    $rgb[] = "205,255,255";
    $rgb[] = "255,205,195";
    $rgb[] = "255,140,255";
    $rgb[] = "100,100,155";
    $rgb[] = "98,153,90";
    $rgb[] = "205,210,230";
    $rgb[] = "192,100,100";
    $rgb[] = "204,204,0";
    $rgb[] = "255,102,102";
    $rgb[] = "0,204,204";
    $rgb[] = "0,255,0";
    $rgb[] = "255,168,88";
    $rgb[] = "128,0,128";
    $rgb[] = "0,153,153";
    $rgb[] = "255,230,204";
    $rgb[] = "128,170,213";
    $rgb[] = "75,75,75";
    switch ($type) {
        case 'pie':
            $cx = '120';
            $cy = '60';
            //Set Pie Postition. CenterX,CenterY
            $sx = '200';
            $sy = '100';
            $sz = '15';
            // Set Size-dimensions. SizeX,SizeY,SizeZ
            // Title
            if (!empty($title)) {
                $cy += 10;
                if ($use_ttf) {
                    imagettftext($img, 10, 0, 2, 10, $black, $fontfile, $title);
                } else {
                    imagestring($img, 2, 2, $legendY - 1, "{$title}", $black);
                }
            }
            //convert to angles.
            for ($i = 0; $i <= $countdata; $i++) {
                $angle[$i] = $data[$i] / $sumdata * 360;
                $angle_sum[$i] = array_sum($angle);
            }
            $background = imagecolorallocate($img, 255, 255, 255);
            //Random colors.
            for ($i = 0; $i <= $countdata; $i++) {
                $rgbcolors = explode(',', $rgb[$i]);
                $colors[$i] = imagecolorallocate($img, $rgbcolors[0], $rgbcolors[1], $rgbcolors[2]);
                $colord[$i] = imagecolorallocate($img, $rgbcolors[0] / 1.5, $rgbcolors[1] / 1.5, $rgbcolors[2] / 1.5);
            }
            //3D effect.
            $legendY = 80 - $countdata * 10;
            if ($legendY < 10) {
                $legendY = 10;
            }
            for ($z = 1; $z <= $sz; $z++) {
                for ($i = 0; $i < $countdata; $i++) {
                    imagefilledarc($img, $cx, $cy + $sz - $z, $sx, $sy, $angle_sum[$i - 1], $angle_sum[$i], $colord[$i], IMG_ARC_PIE);
                }
            }
            imagerectangle($img, 250, $legendY - 5, 470, $legendY + $countdata * 15, $black);
            //Top pie.
            for ($i = 0; $i < $countdata; $i++) {
                imagefilledarc($img, $cx, $cy, $sx, $sy, $angle_sum[$i - 1], $angle_sum[$i], $colors[$i], IMG_ARC_PIE);
                imagefilledrectangle($img, 255, $legendY + 1, 264, $legendY + 9, $colors[$i]);
                // Legend
                if ($unit == 'seconds') {
                    $data[$i] = format_seconds($data[$i]);
                }
                if ($use_ttf) {
                    imagettftext($img, 8, 0, 270, $legendY + 9, $black, $fontfile, substr(urldecode($legends[$i]), 0, 27) . " ({$data[$i]})");
                } else {
                    imagestring($img, 2, 270, $legendY - 1, substr(urldecode($legends[$i]), 0, 27) . " ({$data[$i]})", $black);
                }
                // imagearc($img,$cx,$cy,$sx,$sy,$angle_sum[$i1] ,$angle_sum[$i], $blue);
                $legendY += 15;
            }
            break;
        case 'line':
            $maxdata = 0;
            $colwidth = round($width / $countdata);
            $rowheight = round($height / 10);
            foreach ($data as $dataval) {
                if ($dataval > $maxdata) {
                    $maxdata = $dataval;
                }
            }
            imagerectangle($img, $width - 1, $height - 1, 0, 0, $black);
            for ($i = 1; $i < $countdata; $i++) {
                imageline($img, $i * $colwidth, 0, $i * $colwidth, $width, $grey);
                imageline($img, 2, $i * $rowheight, $width - 2, $i * $rowheight, $grey);
            }
            for ($i = 0; $i < $countdata; $i++) {
                $dataheight = $height - $data[$i] / $maxdata * $height;
                $legendheight = $dataheight > $height - 15 ? $height - 15 : $dataheight;
                $nextdataheight = $height - $data[$i + 1] / $maxdata * $height;
                imageline($img, $i * $colwidth, $dataheight, ($i + 1) * $colwidth, $nextdataheight, $red);
                imagestring($img, 3, $i * $colwidth, $legendheight, substr($legends[$i], 0, 6), $darkblue);
            }
            imagestring($img, 3, 10, 10, $title, $red);
            break;
        case 'bar':
            $maxdata = 0;
            $colwidth = round($width / $countdata);
            $rowheight = round($height / 10);
            foreach ($data as $dataval) {
                if ($dataval > $maxdata) {
                    $maxdata = $dataval;
                }
            }
            imagerectangle($img, $width - 1, $height - 1, 0, 0, $black);
            for ($i = 1; $i < $countdata; $i++) {
                imageline($img, $i * $colwidth, 0, $i * $colwidth, $width, $grey);
                imageline($img, 2, $i * $rowheight, $width - 2, $i * $rowheight, $grey);
            }
            for ($i = 0; $i < $countdata; $i++) {
                $dataheight = $height - $data[$i] / $maxdata * $height;
                $legendheight = $dataheight > $height - 15 ? $height - 15 : $dataheight;
                imagefilledrectangle($img, $i * $colwidth, $dataheight, ($i + 1) * $colwidth, $height, $darkblue);
                imagefilledrectangle($img, $i * $colwidth + 1, $dataheight + 1, ($i + 1) * $colwidth - 3, $height - 2, $midblue);
                imagestring($img, 3, $i * $colwidth + 4, $legendheight, substr($legends[$i], 0, 5), $darkblue);
            }
            imagestring($img, 3, 10, 10, $title, $red);
            break;
        default:
            imagerectangle($img, $width - 1, $height - 1, 1, 1, $red);
            imagestring($img, 3, 10, 10, "Invalid chart type", $red);
    }
    // Return a PNG image
    return $img;
}
    $current_month = date('m', $current_time);
    $current_year = date('Y', $current_time);
    $next_month = $current_month + $increment;
    $next_year = $current_year;
    if ($next_month > 12) {
        $next_year++;
        $next_month %= 12;
    }
    $next_time = mktime(0, 0, 0, $next_month, 1, $next_year);
    $stats = average_incident_duration($current_time, $next_time, $states);
    $row = ldate('F Y', mktime(0, 0, 0, $current_month, 1, $current_year)) . ",";
    if ($next_month > $current_month + 1 and $next_year == $current_year) {
        $row .= " - " . ldate('F Y', mktime(0, 0, 0, $next_month, 1, $next_year)) . ",";
    }
    $row .= $stats[0] . ",";
    $row .= format_seconds($stats[1] * 60) . ",";
    $row .= round($stats[2] / 60) . " {$strHours},";
    $row .= $stats[3] . ",";
    $row .= $stats[4] . ",";
    $row .= $stats[5];
    $data = $data . "\n" . $row;
    $current_time = $next_time;
}
if ($_REQUEST['output'] == 'csv') {
    echo create_report($data, 'csv', 'average_incident_duration.csv');
} else {
    include APPLICATION_INCPATH . 'htmlheader.inc.php';
    echo "<h2>{$title}</h2>";
    echo "<p align='center'>{$strOnlyShowsClosedCalls}</p>";
    echo "<p align='center'>";
    echo "<a href='{$_SERVER['PHP_SELF']}?mode=all&amp;increment={$increment}";
        // Only display if review is due in the next five days
        echo "<td align='center'>";
        echo sprintf($strReviewIn, format_workday_minutes($reviewremain));
    } elseif ($reviewremain <= 0) {
        echo "<td align='center' class='review'>";
        if ($reviewremain > -86400) {
            echo "" . icon('review', 16) . " {$strReviewDueNow}";
        } else {
            echo "" . icon('review', 16) . " " . sprintf($strReviewDueAgo, format_workday_minutes($reviewremain * -1));
        }
    } else {
        echo "<td align='center'>";
        if ($incidents['status'] == 2) {
            echo "{$strAge}: " . format_seconds($incidents["duration_closed"]);
        } else {
            echo sprintf($strXold, format_seconds($incidents["duration"]));
        }
    }
    echo "</td>";
    echo "</tr>\n";
}
echo "</table><br /><br />\n\n";
echo "<table class='incidentkey'><tr>";
echo "<td class='shade1'>{$strOpen}</td>";
echo "<td class='notice'>{$strSLAApproaching}</td>";
echo "<td class='urgent'>{$strSLADue}</td>";
echo "<td class='critical'>{$strSLAMissed}</td>";
echo "</tr></table>";
if ($rowcount != 1) {
    echo "<p align='center'>" . sprintf($strIncidentsMulti, "<strong>{$rowcount}</strong>") . "</p>";
} else {
    if ($incident->status == 7 or $incident->status == 2) {
        $end = $incident->closed;
    } else {
        $end = $now;
    }
    $publicholidays = get_public_holidays($incident->opened, $end);
    //calculate the last update
    $updatearray[$laststatus]['time'] += 60 * calculate_working_time($last, time(), $publicholidays);
    echo "<h3>{$strStatusSummary}</h3>";
    if (extension_loaded('gd')) {
        $data = array();
        $legends;
        foreach ($updatearray as $row) {
            array_push($data, $row['time']);
            $legends .= $GLOBALS[$row['name']] . "|";
        }
        $data = implode('|', $data);
        $title = urlencode($strStatusSummary);
        echo "<div style='text-align:center;'>";
        echo "<img src='chart.php?type=pie&data={$data}&legends={$legends}&title={$title}&unit=seconds' />";
        echo "</div>";
    } else {
        echo "<table align='center'>";
        echo "<tr><th>{$strStatus}</th><th>{$strTime}</th></tr>\n";
        foreach ($updatearray as $row) {
            echo "<tr><td>" . $row['name'] . "</td><td>" . format_seconds($row['time']) . "</td></tr>";
        }
        echo '</table>';
    }
}
include APPLICATION_INCPATH . 'incident_html_bottom.inc.php';
Пример #12
0
    } else {
        $softwarelist[$row->softwareid]++;
    }
    $countincidents++;
    if (!empty($row->externalid)) {
        $countextincidents++;
    }
    if ($row->duration_closed >= 1) {
        $totalduration = $totalduration + $row->duration_closed;
        $countclosed++;
    }
    echo "</tr>\n";
}
echo "</table>\n";
if (mysql_num_rows($result) >= 1 && $countclosed >= 1) {
    echo "<p align='center'>{$strAverageIncidentDuration}: " . format_seconds($totalduration / $countclosed) . "</p>";
}
echo "<p class='contextmenu' align='center'>{$strDisplay}: ";
echo "<a href=\"{$_SERVER['PHP_SELF']}?id={$id}&amp;mode={$mode}&amp;status=open\">{$strShowOpenIncidents}</a> | ";
echo "<a href=\"{$_SERVER['PHP_SELF']}?id={$id}&amp;mode={$mode}&amp;status=closed\">{$strShowClosedIncidents}</a> | ";
echo "<a href=\"{$_SERVER['PHP_SELF']}?id={$id}&amp;mode={$mode}\">{$strAll}</a>";
echo "</p>";
$countproducts = array_sum($productlist);
if ($mode == 'site') {
    $countcontacts = array_sum($contactlist);
}
if ($countproducts >= 1 or $contactcontacts >= 1) {
    foreach ($productlist as $product => $quantity) {
        $productpercentage = number_format($quantity * 100 / $countproducts, 1);
        $productlegends[] = urlencode(product_name($product) . " ({$productpercentage}%)");
    }