<!-- Begin Debugging -->
<script type='text/javascript'> //<![CDATA[
// Hide lists
$(function()
{
        $('#SQLdetails, #incFiles', '#debugdiv').hide();
});
 
function showDetails(obj, targetObj)
{
        var SQL = targetObj, SQLTrigger = obj;
 
        SQL.slideToggle('normal', function()
        {
                if ( SQL.is(':hidden') )
                        SQLTrigger.html('Show Details');
                else
                        SQLTrigger.html('Hide Details');
        });
 
        return false;
}
//]]>
</script>
<a id='showDebug' href='' title='Show Debug Details' onclick="$('#debugdiv').slideToggle('normal'); return false;"><?php print $this->translate('Show debug details')?></a>
 
<div id='debugdiv' style="display:none;">
	<h3 class='debug'><?php print $this->translate('Debug Information')?>:</h3>
	<fieldset>
	<legend><?php print $this->translate('SQL Info')?></legend>
	<?php
	$dbDebug = Zend_Registry::get('dbAdapter');
	$profiler = $dbDebug->getProfiler();
	$longestTime = 0;
	$longestQuery = null;
	?>
	<?php echo ($totalQueries = $profiler->getTotalNumQueries()) == 1 ? "$totalQueries query" : "$totalQueries queries" ?> 
	run in <?php echo round($totalQueryTime = $profiler->getTotalElapsedSecs(),3 )?> seconds.<br />
	<a id='showSQL' href='' title='Show Query Details' onclick="return showDetails($('#showSQL'), $('#SQLdetails'))"><?php print $this->translate('Show Details')?></a>
	<div id='SQLdetails'>
	<b>Query details:</b>
	<?php 
	//echo '<pre>$profiler' . print_r($profiler,true) . '</pre>';  
	$queryProfilesArray = $profiler->getQueryProfiles();
	if ( is_array($queryProfilesArray) )
	{

		foreach ( $queryProfilesArray as $key => $profile ) {
			$queryTime = $profile->getElapsedSecs();
			$color = '';

			if ( $queryTime > $longestTime ) {
			        $longestTime  = $queryTime;
			        $longestQuery = $profile->getQuery();
			}

			// Query color
			if ( $queryTime >= 5 ) $color = 'red';
			if ( $queryTime >= 1 ) $color = 'orange';

			printf("<hr />%d: <b>[</b><code style='color: %s'>%s</code><b>]</b> %.4f (%s)\n", ++$key, $color, $profile->getQuery(), $profile->getElapsedSecs(), implode(',', $profile->getQueryParams()));
		}
	}
	?>
	</div>
	<p style='margin-bottom: 0'>
	<?php print $this->translate('Longest execution time')?>: <?php echo round($longestTime, 3) ?><br />
	<?php print $this->translate('Longest query')?>: <?php echo $longestQuery?><br />
	<?php print $this->translate('Average query execution time')?>: <?php printf('%.4f', @($totalQueryTime / $totalQueries))?><br />
	<?php print $this->translate('Number of queries per seconds')?>: <?php echo @intval($totalQueries / $totalQueryTime)?>
	</p>
	</fieldset>
	<p>
	- <?php print $this->translate('Memory usage')?>: <?php echo memory_get_usage().' bytes'?><br />
	- <?php print $this->translate('Allocated memory')?>: <?php // echo memory_get_peak_usage().' bytes'?><br />
	- <?php print $this->translate('Included files')?>: <a id='showIncFiles' href='' title='Show Included Files' onclick="return showDetails($('#showIncFiles'), $('#incFiles'))">Show Details</a>
	<div id='incFiles'>
		<?php echo implode("\n<br />", get_included_files())?>
	</div>
	</p>
	<fieldset>
	<legend><?php print $this->translate('File Info')?></legend>
	- <?php print $this->translate('Date of last modification')?>: <?php echo gmdate('D, d M Y H:i:s', getlastmod()).' GMT'?><br />
	- <?php print $this->translate('Page generation time')?>: <?php echo round(microtime(true) - DEBUG_START_MT,3) ?>
	</fieldset>
	<br />
	<fieldset>
	<legend><?php print $this->translate('Browser Info')?></legend>
	- <?php print $this->translate('Accepted languages')?>: <?php echo $_SERVER['HTTP_ACCEPT_LANGUAGE']?><br />
	- <?php print $this->translate('Accepted encoding')?>: <?php echo $_SERVER['HTTP_ACCEPT_ENCODING']?><br />
	- <?php print $this->translate('User agent')?>: <?php echo $_SERVER['HTTP_USER_AGENT']?>
	</fieldset>
</div>
<!-- End Debugging -->
<script type='text/javascript'> //<![CDATA[
// Hide lists
$(function()
{
	$('#SQLdetails, #incFiles').hide();
});
 
function showDetails(obj, targetObj)
{
	targetObj.slideToggle('normal', function()
	{
		if ( targetObj.is(':hidden') )
			obj.html('Show Details');
		else
			obj.html('Hide Details');
	});
	return false; 
}
//]]>
</script>
