Location: PHPKode > projects > BugIn and Ticketing System > bugin-0.65/inc/report.inc.php
<?php

function secsToTime($num_secs) {
// Convert $num_secs to Hours:Minutes:Seconds

	$hours = intval($num_secs / 3600);
	$num_secs -= $hours * 3600;

	$minutes = intval($num_secs / 60);
	$minutes = sprintf("%02d", $minutes);
	$num_secs -= $minutes * 60;
	$seconds = $num_secs;
  $seconds = sprintf("%02d", $seconds);
	return "$hours:$minutes:$seconds";
}


echo <<<EOT
<form method="{$options['formMethod']}" action="{$options[baseURL]}{$options[formSubmitTo]}">
<input type="hidden" name="area" value="report">
Choose a Begin Date:
EOT;
DateSelector("begin", time());

echo <<<EOT
<br>
Choose a End Date:
EOT;
DateSelector("end", time());
echo <<<EOT
<br>
<input type="submit" value="{$verbage['submit']}" />

</form>

EOT;

if (isset($begin)) {
	$repTicketList = array();
	$repTicketList['whole'] = array();
	$timeBegin = "{$begin['year']}{$begin['month']}{$begin['day']}000000";
	$timeEnd = "{$end['year']}{$end['month']}{$end['day']}235959";
	/* CLM
		Use Left() to get just year and month. 
		Required for MSSQL
	*/	
	if ($tmp = $bugDatabase->getTicketList(" date_added <= left({$timeEnd}, 8) AND date_added >= left({$timeBegin}, 8)", "", "date_added")) {
			while (list($key, $value) = each($tmp)) {
				ereg("^([0-9]{4})([0-9]{2})([0-9]{2})", strval($value['date_added']), $regs);
				$y = $regs[1];
				$m = $regs[2];
				$d = $regs[3];

				$value['repDate'] = "$m/$d/$y";
				$repTicketList["$y$m$d"][] = $value;
				array_push ($repTicketList['whole'], $value);
			}
		}
	for ($i = intval("{$begin['year']}{$begin['month']}{$begin['day']}"); $i <= intval("{$end['year']}{$end['month']}{$end['day']}"); $i ++) {
		ereg("^([0-9]{4})([0-9]{2})([0-9]{2})",strval($i), $regs);
		$y = $regs[1];
		$m = $regs[2];
		$d = $regs[3];
		if (checkdate ($m, $d, $y)) {
			$succ ++;
		}
	}


	if ($num = count($repTicketList['whole'])) {
		echo "Tickets Total: ".$num." in $succ days<br>\n";
		
		$repId = 0;

		// Gather info to report....
		while (list($key, $value) = each($repTicketList)) {
			while (list($key1, $value1) = each($value)) {
				if ($key == "whole") {
					$reports[$repId]['repDate'] = "{$begin['month']}/{$begin['day']}/{$begin['year']} through {$end['month']}/{$end['day']}/{$end['year']}";
				}
				else {
					$reports[$repId]['repDate'] = $value1['repDate'];
				}

				if (in_array($value1['status'], explode(",", $options['closedNum']))) {
					$reports[$repId]['project'][$value1['project']]['count'] ++;
					$reports[$repId]['project'][$value1['project']]['time'] += intval($value1['age']);
					$reports[$repId]['project']['time'] += intval($value1['age']);
					$reports[$repId]['group'][$value1['group']] ++;
				}
				elseif ($value1['id']) {
					$reports[$repId]['numStillOpen'] ++;
					$value1['name'] = htmlentities($value1['short_desc']);
					$reports[$repId]['tixStillOpen'][] = $value1;
				}

			}
			$repId ++;
		}




		// Print out the information....  ungh....
		while (list($key, $value) = @each($reports)) {
			$ticketLinkList = "";
			while(list($one, $two) = @each($value['tixStillOpen'])) {
				$ticketLinkList .= "<li><a href=\"{$options['baseURL']}?area=view&num={$two['id']}\">#{$two['id']}</a> <a href=\"{$options['baseURL']}?area=view&num={$two['id']}\">{$two['name']}</a></li>";
			}

			$totalTime = secsToTime($value['project']['time']);
			echo <<<EOT

Report for <b>{$value['repDate']}</b>
<hr>
Total Time for All Tickets: {$totalTime}<br>
Number of tickets still open: {$value['numStillOpen']}<br>
<ol type="1">
{$ticketLinkList}
</ol>

EOT;
			reset($bugDatabase->lists['project']);

			while (list($key1, $value1) = each($bugDatabase->lists['project']) ) {
				if (!isset($value[project][$value1['id']]['count'])) {
					$count = 0;
				}
				else {
					$count = $value['project'][$value1['id']]['count'];
					$average = secsToTime(intval($value['project'][$value1['id']]['time'] / $count));
					echo "<b>Project: {$value1['name']}</b> - $count ticket".(($count - 1) ? "s" : "")." opened, $average average time to close<br>";
				}


			}
			echo <<<EOT
			<br><br>

EOT;
		}
	}
}
//printVar($repTicketList);
?>
Return current item: BugIn and Ticketing System