<?
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DataDivisions, Build 1.0, 12/11/2003 #
# FileName: funcDisplayCommon.php #
# File Description: #
# Provides functions common throughout many display processes (back-end, #
# middle and front-end functionality) #
# Functions Included In This File: #
# startGenHTMLReturn(), genTextHTMLReturn(), genBarHTMLReturn() #
# genPlotHTMLReturn(), defDisplayWidth(), defDisplayHeight() #
# genDisplayHeader(), genShuffleAssoc(), get12HourTime() #
# getTextDayOfWeek(), getRealServerTime(), parseErrorLogLines() #
# #
# +-----------------------------------------------------------------------+ #
# | DataDivisions - Website Statistic Visualization Software | #
# | Copyright (c) 2003, Brian Willison | #
# +-----------------------------------------------------------------------+ #
# | The contents of this file are subject to the GNU General Public | #
# | License version 2 (June 1991). This file and all its contents (incl. | #
# | functions, methods, etc.) are free for general use within any | #
# | community. This software is distributed with the intent to allow | #
# | developers the opportunity to copy, manipulate and revamp this | #
# | application in part or whole for best use cases. | #
# | | #
# | This software is distributed "AS-IS" with no warranties of any kind | #
# | either expressed or implied. | #
# | | #
# | Please refer to the GPL license document for more information: | #
# | (_docs/gplLicense.pdf) | #
# +-----------------------------------------------------------------------+ #
# | Developer, Designer, Initial Creator: | #
# | Brian Willison (hide@address.com) | #
# +-----------------------------------------------------------------------+ #
# | Initial Download Reference: | #
# | http://datadivisions.sourceforge.net | #
# +-----------------------------------------------------------------------+ #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
// Function: Start Generating Display HTML
function startGenHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayType,$displayParam,$limit,$username) {
switch($displayType) {
// Call Required Display Function data array,displayParam(square...),limit (y/n),max display width,max display height,number of info packets,initialize return html,username
case "text":$htmlReturn = genTextHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,defDisplayWidth($displayParam),defDisplayHeight($displayParam),sizeof(array_keys($dataArrayFull)),"",$username);break;
case "bar":$htmlReturn = genBarHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,defDisplayWidth($displayParam),defDisplayHeight($displayParam),sizeof(array_keys($dataArrayFull)),"",$username);break;
case "plot":$htmlReturn = genPlotHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,defDisplayWidth($displayParam),defDisplayHeight($displayParam),sizeof(array_keys($dataArrayFull)),"",$username);break;
default:$htmlReturn = genTextHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,defDisplayWidth($displayParam),defDisplayHeight($displayParam),sizeof(array_keys($dataArrayFull)),"",$username);break;
}
return $htmlReturn;
}
// Function: Generate Text Display HTML Return
function genTextHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,$displayWidth,$displayHeight,$numberDataSections,$htmlReturn,$username) {
$htmlReturn .= "\n\t\t\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$displayWidth."\" height=\"";
//if (pageName != "viewDetails")
$htmlReturn .= $displayHeight;
//else
// $htmlReturn .= "100%";
$htmlReturn .= "\" align=\"center\">";
// Define Space Limit (so text does not run past allocated space height)
$limitCounter = 0;
if ($displayParam == "1full" || $displayParam == "vert")
$limitMaxRows = 25;
else
$limitMaxRows = 9;
foreach ($dataArrayFull as $key=>$val) {
// Define Row Background Color
$rowBgColor = ($limitCounter % 2 == 0) ? appBackgroundColor: appContentColor;
// Check If Results Greater Than Max Limit Of Display Lines - Bypass For View Details Page
if ($limitCounter <= $limitMaxRows || pageName == "viewDetails") {
$key = trim($key);$val = trim($val);
$htmlReturn .= "\n\t\t\t\t\t\t\t<tr bgcolor=\"".$rowBgColor."\" onmouseover=\"setPointer(this, ".$limitCounter.", 'over', '".$rowBgColor."', '".savedDisplayHeaderColor."', '".savedDisplayHeaderColor."');\" onmouseout=\"setPointer(this, ".$limitCounter.", 'out', '".$rowBgColor."', '".savedDisplayHeaderColor."', '".savedDisplayHeaderColor."');\" onmousedown=\"setPointer(this, ".$limitCounter.", 'click', '".$rowBgColor."', '".savedDisplayHeaderColor."', '".savedDisplayHeaderColor."');\">\n\t\t\t\t\t\t\t<td><p>";
if (ereg("http://",$key))
$htmlReturn .= "<a href=\"".$key."\" target=\"new\">";
// Truncate Long Text Lines To Fit Display Size If Not View Details Page
if (pageName != "viewDetails") {
$totalChars = strlen($key) + strlen($val);
if ($displayParam == "square" || $displayParam == "vert") {
if (strlen($val) >= 10)
$val = substr($val,0,5)."...";
if ($totalChars > 49)
$key = substr($key,0,(49-strlen($val)-3))."...";
} else {
if (strlen($val) >= 10)
$val = substr($val,0,5)."...";
if ($totalChars > 99)
$key = substr($key,0,(99-strlen($val)-3))."...";
}
}
$htmlReturn .= $key;
if (ereg("http://",$key))
$htmlReturn .= "</a>";
$htmlReturn .= "</td><td align=\"right\"><p>".$val."</td>\n\t\t\t\t\t\t\t</tr>";
$limitCounter++;
} else {
$htmlReturn .= "\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td valign=\"top\" colspan=\"2\"><p class=\"small\"><i>Click \"View Extended Information\" above to see full list.</i></td>\n\t\t\t\t\t\t\t</tr>";
break;
}
}
$htmlReturn .= "\n\t\t\t\t\t\t\t</table>\n";
return $htmlReturn;
}
// Function: Generate Bar Display HTML Return
function genBarHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,$displayWidth,$displayHeight,$numberDataSections,$htmlReturn,$username) {
// Decrease Display Height To Allow For Text Description Of Graph Underneath
$displayHeight -= 10;
$htmlReturn .= "\n\t\t\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$displayWidth."\" height=\"".$displayHeight."\" align=\"center\">\n\t\t\t\t\t\t\t<tr height=\"".$displayHeight."\">";
// Define Bar Color From Reference Number (errors = red, else...)
$imgColorArray = array("Red","Blue","Green");
// Error Displays Always In Red
if ($refNum == "029" || $refNum == "030" || $refNum == "031" || $refNum == "032")
$imgColor = $imgColorArray[0];
else
$imgColor = $imgColorArray[mt_rand(1,2)];
// Find Width Of Each Bar
$barWidth = (int)($displayWidth/$numberDataSections)-2;
// Find MaxVal(height) From Highest Value
$maxVal = 0;
foreach ($dataArrayFull as $key=>$val)
$maxVal = ($val > $maxVal) ? $val+1 : $maxVal+1; // add 1 for maxVal=displayHeight offset
// Generate Bar Graph HTML
foreach ($dataArrayFull as $key=>$val) {
$key = trim($key);$val = trim($val);
// Determine % Of Val To Max Val = Output Height
$percentVal = $val/$maxVal;
$retSpacerHeight = (int)($displayHeight-$displayHeight*$percentVal);
$retBarHeight = (int)($displayHeight*$percentVal);
// Set Zero Spacer Height To One For Consistent Display
$retBarHeight = ($retBarHeight == 0) ? 1 : $retBarHeight;
$retBarHeight = ($retBarHeight >= $displayHeight-1) ? $retBarHeight-1: $retBarHeight;
// Set Offset Of Spacer Heights So Baseline Is Always Consistent And Even Lowest Numbers Show
$retBarHeightOffset = ($retBarHeight == 0 || $retBarHeight == 1) ? 2 : 0;
$htmlReturn .= "\n\t\t\t\t\t\t\t<td valign=\"top\" align=\"center\"><p>".retWriteSpacer($barWidth,$retSpacerHeight-$retBarHeightOffset);
$htmlReturn .= "<br><img src=\"".imgUrl."spacer".$imgColor.".gif\" width=\"".$barWidth."\" height=\"".$retBarHeight."\" border=\"0\" ";
// Calculate ToolTip Width From String Length
$toolTipWidth = ((strlen($key)+strlen($val))*10);
if ($toolTipWidth > 175)
$toolTipWidth = 175;
$htmlReturn .= "onmouseover=\"ddrivetip('<p>".$key.": ".$val."','',".$toolTipWidth.");\" onmouseout=\"hideddrivetip();\"></td>";
}
$htmlReturn .= "\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align=\"center\" colspan=\"".$numberDataSections."\">";
$htmlReturn .= "<p class=\"graphDescText\" align=\"center\">".$displayDescription."\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n";
return $htmlReturn;
}
// Function: Generate Plot Display HTML Return
function genPlotHTMLReturn($dataArrayFull,$refNum,$displayDescription,$displayParam,$limit,$displayWidth,$displayHeight,$numberDataSections,$htmlReturn,$username) {
// Decrease Display Height To Allow For Text Description Of Graph Underneath
$displayHeight -= 10;
$htmlReturn .= "\n\t\t\t\t\t\t\t<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"".$displayWidth."\" height=\"".$displayHeight."\" align=\"center\"><tr height=\"".$displayHeight."\">";
// Handle Country Flags - Not Normal Plot
if ($refNum == "011") {
$dataArrayKeys = array_keys($dataArrayFull);
$dataArrayVals = array_values($dataArrayFull);
// Set Number Of Flags To Display
if ($displayParam == "square" || $displayParam == "vert") $numToDisplay = 3;
else $numToDisplay = 6;
// Calculate Total Of All Values
$totalValues = 0;
for ($i=0; $i<$numToDisplay; $i++)
$totalValues += $dataArrayVals[$i];
// Calculate Percentage Values Of Individual Country To Total Values
$percentValues = array();
for ($i=0; $i<$numToDisplay; $i++)
array_push($percentValues,($dataArrayVals[$i]/$totalValues));
// Calculate Adjustments To Extra Large 1st Value
if ($percentValues[0] >= .75) {
$percentDiff = $percentValues[0] - .75;
$percentDiff /= $numToDisplay;
$percentValues[0] = .75;
for ($i=1; $i<$numToDisplay; $i++)
$percentValues[$i] += $percentDiff;
$valSmallDisplay = TRUE;
}
// Calculate New Image Dimensions (width=0,height=1 in array)
$imageWidths = array();
$imageHeights = array();
for ($i=0; $i<$numToDisplay; $i++) {
$imageDims = getimagesize(imgUrl."flags/".$dataArrayKeys[$i].".jpg");
if ($numToDisplay == 6)
$imageWidth = (int)(($percentValues[$i]*$displayWidth)/2);
else
$imageWidth = (int)($percentValues[$i]*$displayWidth);
$imageHeight = (int)($percentValues[$i]*$imageDims[1]);
array_push($imageWidths,$imageWidth);
array_push($imageHeights,$imageHeight);
}
// Generate HTML/Image Output
for ($i=0; $i<$numToDisplay; $i++) {
// Calculate ToolTip Width From String Length
$toolTipWidth = ((strlen($dataArrayKeys[$i])+strlen($dataArrayVals[$i]))*10);
$htmlReturn .= "\n\t\t\t\t\t\t\t<td align=\"center\"><p><img src=\"".imgUrl."flags/".$dataArrayKeys[$i].".jpg\" width=\"".$imageWidths[$i]."\" height=\"".$imageHeights[$i]."\" border=\"0\" ";
$htmlReturn .= "onmouseover=\"ddrivetip('<p>".(strtoupper($dataArrayKeys[$i])).": ".$dataArrayVals[$i]."','',".$toolTipWidth.");\" onmouseout=\"hideddrivetip();\"></td>";
}
$htmlReturn .= "\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>";
for ($i=0; $i<$numToDisplay; $i++) {
$htmlReturn .= "\n\t\t\t\t\t\t\t<td align=\"center\"><p";
if ($valSmallDisplay == TRUE && $i > 0)
$htmlReturn .= " class=\"small\"";
$htmlReturn .= ">".$dataArrayVals[$i]."</td>";
}
// Normail Plot Display
} else {
// Define Bar Color From Reference Number (errors = red, else...)
$imgColorArray = array("Red","Blue","Green");
if ($refNum == "029" || $refNum == "030" || $refNum == "031" || $refNum == "032")
$imgColor = $imgColorArray[0];
else
$imgColor = $imgColorArray[mt_rand(1,2)];
// Find Width Of Each Vertical Plot
$vertWidth = (int)($displayWidth/$numberDataSections)-2;
// Find MaxVal(height) From Highest Value
$maxVal = 0;
foreach ($dataArrayFull as $key=>$val)
$maxVal = ($val > $maxVal) ? $val+1 : $maxVal+1; // add 1 for maxVal=displayHeight offset
// Generate Plot Images HTML
foreach ($dataArrayFull as $key=>$val) {
$key = trim($key);$val = trim($val);
// Determine % Of Val To Max Val = Output Height
$percentVal = $val/$maxVal;
$retSpacerHeight = (int)($displayHeight-$displayHeight*$percentVal);
$retBarHeight = (int)($displayHeight*$percentVal);
$retBarHeight = ($retBarHeight >= $displayHeight-1) ? $retBarHeight-1: $retBarHeight;
$htmlReturn .= "\n\t\t\t\t\t\t\t<td valign=\"top\" align=\"center\"><p>".retWriteSpacer($vertWidth,$retSpacerHeight-4);
if ($retBarHeight != 0) {
// Calculate ToolTip Width From String Length
$toolTipWidth = ((strlen($key)+strlen($val))*10);
if ($toolTipWidth > 175)
$toolTipWidth = 175;
$htmlReturn .= "<br><img src=\"".imgUrl."plot".$imgColor.".gif\" width=\"7\" height=\"7\" border=\"0\" ";
$htmlReturn .= "onmouseover=\"ddrivetip('<p>".$key.": ".$val."','',".$toolTipWidth.");\" onmouseout=\"hideddrivetip();\"></td>";
}
}
}
$htmlReturn .= "\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align=\"center\" colspan=\"".$numberDataSections."\">";
$htmlReturn .= "<p class=\"graphDescText\" align=\"center\">".$displayDescription."\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</table>\n";
return $htmlReturn;
}
// Function: Define Display Width For Individual Display
function defDisplayWidth($displayParam) {
switch($displayParam) {
case "1full":$displayWidth = mainDisplayContentWidth-individualDisplayWidthOffset;break;
case "vert":$displayWidth = (mainDisplayContentWidth/2)-individualDisplayWidthOffset;break;
case "horiz":$displayWidth = mainDisplayContentWidth-individualDisplayWidthOffset;break;
case "square":$displayWidth = (mainDisplayContentWidth/2)-individualDisplayWidthOffset;break;
}
return $displayWidth;
}
// Function: Define Display Height For Individual Display
function defDisplayHeight($displayParam) {
if (pageName == "viewDetails") {
$displayHeight = mainDisplayContentHeight-30;
} else {
switch($displayParam) {
case "1full":$displayHeight = mainDisplayContentHeight-individualDisplayHeightOffset;break;
case "vert":$displayHeight = mainDisplayContentHeight-individualDisplayHeightOffset;break;
case "horiz":$displayHeight = (mainDisplayContentHeight/2)-individualDisplayHeightOffset;break;
case "square":$displayHeight = (mainDisplayContentHeight/2)-individualDisplayHeightOffset;break;
}
}
return $displayHeight;
}
// Function: Generate Display Header Text/Links
function genDisplayHeader($whichPage,$displayTitle,$refNum,$displayType,$displayParam,$displayIndivLoc,$username) {
// Determine View Details Pop Up Window Width & Height
if (eregi("square",$displayIndivLoc)) {
$popUpWidth = appPopUpViewDetailsSquareWidth;
$popUpHeight = appPopUpViewDetailsSquareHeight;
$displayTemplate = templateViewDetailsSquare;
} elseif (eregi("horiz",$displayIndivLoc)) {
$popUpWidth = appPopUpViewDetailsHorizWidth;
$popUpHeight = appPopUpViewDetailsSquareHeight;
$displayTemplate = templateViewDetailsHoriz;
} elseif (eregi("vert",$displayIndivLoc)) {
$popUpWidth = appPopUpViewDetailsVertWidth;
$popUpHeight = appPopUpViewDetailsSquareHeight;
$displayTemplate = templateViewDetailsVert;
} else {
$popUpWidth = appPopUpViewDetailsFullWidth;
$popUpHeight = appPopUpViewDetailsSquareHeight;
$displayTemplate = templateViewDetailsFull;
}
// Generate HTML Header To Return
$htmlReturn = templateStartHTML.$displayTitle.templateMiddleStartHTML;
if ($whichPage != "viewDetails")
$htmlReturn .="(<a href=\"javascript:popWinViewDetails('".viewDetailsPage."?refNum1=".$refNum."&refNum1DisplayType=".$displayType."&refNum1DisplayParam=".$displayParam."&displayParams=".$displayParam."&displayTemplate=".$displayTemplate."&popUpWidth=".$popUpWidth."&monthView=".monthViewForLog."&username=".$username."',".$popUpWidth.",".$popUpHeight.",'".$displayIndivLoc."',".(savedDisplaySectionWidth+appSectionSpacerWidth).");\">View Extended Information</a>)";
$htmlReturn .= templateMiddleEndHTML;
return $htmlReturn;
}
// Function: Shuffle Associative Array Without Losing KV Pairings
function genShuffleAssoc($inDataArray) {
for ($i=0; $i<sizeof($inDataArray); $i++)
$shuffleArray[] = $i;
shuffle($shuffleArray);
foreach($shuffleArray as $shufKey1=>$shufVal1) {
$counter = 0;
foreach($inDataArray as $shufKey1=>$shufVal2) {
if ($shufVal1 == $counter) {
$returnArray[$shufKey1] = $shufVal2;
break;
}
$counter++;
}
}
return $returnArray;
}
// Function: Convert 24-hour Time To 12-hour Time
function get12HourTime($whichTime) {
switch($whichTime) {
case 0:$returnTime = "12am - 1am";break;
case 1:$returnTime = "1am - 2am";break;
case 2:$returnTime = "2am - 3am";break;
case 3:$returnTime = "3am - 4am";break;
case 4:$returnTime = "4am - 5am";break;
case 5:$returnTime = "5am - 6am";break;
case 6:$returnTime = "6am - 7am";break;
case 7:$returnTime = "7am - 8am";break;
case 8:$returnTime = "8am - 9am";break;
case 9:$returnTime = "9am - 10am";break;
case 10:$returnTime = "10am - 11am";break;
case 11:$returnTime = "11am - 12pm";break;
case 12:$returnTime = "12pm - 1pm";break;
case 13:$returnTime = "1pm - 2pm";break;
case 14:$returnTime = "2pm - 3pm";break;
case 15:$returnTime = "3pm - 4pm";break;
case 16:$returnTime = "4pm - 5pm";break;
case 17:$returnTime = "5pm - 6pm";break;
case 18:$returnTime = "6pm - 7pm";break;
case 19:$returnTime = "7pm - 8pm";break;
case 20:$returnTime = "8pm - 9pm";break;
case 21:$returnTime = "9pm - 10pm";break;
case 22:$returnTime = "10pm - 11pm";break;
case 23:$returnTime = "11pm - 12am";break;
}
return $returnTime;
}
// Function: Convert Date TimeStamp To Text Day Of Week
function getTextDayOfWeek($whichDate) {
$date = substr($whichDate,0,4)."-".substr($whichDate,4,2)."-".substr($whichDate,6,2);
/* Get week of year for date given */
return date("l",strtotime($date));
}
// Function: Convert Full Unix TimeStamp To Readable Date & Time
function getRealServerTime($timeStamp) {
$year = substr($timeStamp,0,4);
$month = substr($timeStamp,4,2);
$day = substr($timeStamp,6,2);
$hour = substr($timeStamp,8,2);
$minute = substr($timeStamp,10,2);
$second = substr($timeStamp,12,2);
$amPm = "am";
if ($hour > 12) {
$hour = $hour - 12;
$amPm = "pm";
}
if ($hour < 10)
$hour = substr($hour,1,1);
return $month."/".$day."/".$year." (".$hour.":".$minute." ".$amPm.")";
}
// Function: Handle Parsing Error Log Lines
function parseErrorLogLines($lineToParse) {
$lineToParse = ereg_replace("]",",",$lineToParse);
$lineToParse = ereg_replace("\[","",$lineToParse);
$lineToParse = ereg_replace(" /",",",$lineToParse);
return $lineToParse;
}
?>