Location: PHPKode > projects > DataDivisions > includes/funcGlobal.php
<?
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# DataDivisions, Build 1.0, 12/11/2003                                      #
# FileName: funcGlobal.php                                                  #
# File Description:                                                         #
#   Provides functions needed for all pages and functions (back-end, middle #
#   and front-end functionality)                                            #
#   Functions Included In This File:                                        #
#     writeSpacer(), retWriteSpacer(), genDate(), setUserLoginCookie()      #
#     setAppSessionCookie(), deleteCookies(), redirectToLoginPage()         #
#     redirectToRegisterConfirmPage(), redirectToSaveDisplayConfirmPage()   #
#     redirectToEmailDisplayConfirmPage(),                                  #
#     redirectToEditDisplayConfirmPage(),                                   #
#     redirectToDeleteDisplayConfirmPage(), redirectToDisplayPage()         #
#     dbConnect(), dbClose(), genErrorMsg(), genAppFullHeader()             #
#     genAppSavedDisplays(), genAppDataDisplay(), genAppFullFooter()        #
#     genAppSmHeader(), genAppSmFooter(), genAppViewDetails()               #
#                                                                           #
# +-----------------------------------------------------------------------+ #
# | 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: Write Spacer Gif
function writeSpacer($width,$height) {
	printf("<img src=\"%sspacer.gif\" width=\"%d\" height=\"%d\" border=\"0\">",imgUrl,$width,$height);
}
// Function: Write Spacer Gif - Return Value Not To Screen
function retWriteSpacer($width,$height) {
	return "<img src=\"".imgUrl."spacer.gif\" width=\"".$width."\" height=\"".$height."\" border=\"0\">";
}
// Function: Generate Date
function genDate($whichStyle) {
	switch ($whichStyle) {
		case "text":return date("F j, Y");break;
		default:return date("F j, Y");break;
	}
}
// Function: Set User Login/"Remember" Cookie
function setUserLoginCookie($username) {
	setcookie("dataDivisionsUsername",$username,mktime(0,0,0,1,1,2010),"/",serverName);
}
// Function: Set Session Cookie
function setAppSessionCookie($username) {
	setcookie("dataDivisionsAppSession",$username,time()+3600,"/",serverName);
}
// Function: Delete Cookies From Logout
function deleteCookies() {
	setcookie("dataDivisionsAppSession","",time()-3600,"/",serverName);
	setcookie("dataDivisionsUsername","",time()-3600,"/",serverName);
}
// Function: Redirect User To Login Page
function redirectToLoginPage() {
	header("Location: ".loginPage);
}
// Function: Redirect User To Registration Confirmation Page - After Successful Registration
function redirectToRegisterConfirmPage() {
	header("Location: ".registerConfirmPage);
}
// Function: Redirect User To Save Display Confirmation Page - After Successful Display Save
function redirectToSaveDisplayConfirmPage() {
	header("Location: ".saveDisplayConfirmPage);
}
// Function: Redirect User To Email Display Confirmation Page - After Successful Email Send
function redirectToEmailDisplayConfirmPage() {
	header("Location: ".emailDisplayConfirmPage);
}
// Function: Redirect User To Edit Display Confirmation Page - After Successful Edit Saved Display
function redirectToEditDisplayConfirmPage() {
	header("Location: ".editDisplayConfirmPage);
}
// Function: Redirect User To Edit Display Confirmation Page - After Successful Edit Saved Display
function redirectToDeleteDisplayConfirmPage() {
	header("Location: ".deleteDisplayConfirmPage);
}
// Function: Redirect User To Display Page - After Successful Login
function redirectToDisplayPage() {
	header("Location: ".displayPage);
}
// Function: DB Connect
function dbConnect() {
	$dbOpen = mysql_connect(dbHost,dbUser,dbPass) or die ("Could not connect: ".mysql_error());
	mysql_select_db(dbName);
	return $dbOpen;
}
// Function: DB Close
function dbClose($dbToClose) {
	mysql_close($dbToClose);
}
// Function: Generate Error Message
function genErrorMsg($whichMsg) {
	switch($whichMsg) {
		case 1: // blank submit
			$error = "Please make sure to fill in all fields before clicking \"Submit\".";
		break;
		case 2: // login, password incorrect
			$error = "The password you have supplied is incorrect. Please try again.";
		break;
		case 3: // login, no user in db
			$error = "The username you have supplied does not have an active account. Please try again, or register.";
		break;
		case 4: // register, username already exists in db
			$error = "The username you have selected is already taken. Please try again.";
		break;
		case 5: // register, passwords don't match
			$error = "The password and confirmation passwords do not match. Please try again.";
		break;
		case 6: // email to send to is not correctly formatted
			$error = "The email address supplied is invalid. Please try again.";
		break;
		case 7: // invalid refNum supplied on display page
			$error = "The display you are attempting to view is unavailable or does not exist.";
		break;
	}
	return $error;
}
// Function: Generate Application Full/Display Header
function genAppFullHeader($whichPage,$username) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title><?=appName?></title>
<?include(cssStyleFile);?>
<script language="javascript" src="<?=funcJavaScriptFile?>"></script>
</head>

<body bgcolor="<?=screenColor?>" topmargin="<?=appTopMargin?>" leftmargin="<?=appLeftMargin?>" marginheight="<?=appTopMargin?>" marginwidth="<?=appLeftMargin?>" onresize="window.location.reload();">

<div id="dhtmlToolTip"></div>
<script language="javascript" type="text/javascript" src="<?=funcJavaToolTipFile?>"></script>

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr><td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="<?=appWidth?>">
<tr bgcolor="<?=appBorderColor?>">
<td valign="top"><?writeSpacer(1,1)?></td>
<td valign="top"><?writeSpacer(contentWidth/2,1)?></td>
<td valign="top"><?writeSpacer(contentWidth/2,1)?></td>
<td valign="top"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,45)?></td>
<td valign="top" bgcolor="<?=appHeaderColor?>"><img src="<?=imgUrl?>logo.gif" width="300" height="45" border="0" alt="<?=appName?>"></td>
<td align="right" bgcolor="<?=appHeaderColor?>"><?
	printf("<p class=\"appHeader\">Logged in as: %s <a href=\"%s\" class=\"logout\"><img src=\"".imgUrl."btnLogout.gif\" width=\"36\" height=\"11\" border=\"0\" alt=\"LOGOUT\"></a><br>Viewing: %s<br>Statistics For: %s",$username,logoutPage,websiteName,switchDropDownArchiveText(monthViewForLog));
	?></td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,45)?></td>
</tr>
<tr>
<td valign="top" colspan="4" bgcolor="<?=appBorderColor?>"><?writeSpacer(appWidth,1)?></td>
</tr>
<tr bgcolor="<?=appBackgroundColor?>">
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,6)?></td>
<td valign="top" bgcolor="<?=appContentColor?>"><?writeSpacer(1,1)?></td>
<td valign="top" bgcolor="<?=appContentColor?>"><?writeSpacer(1,1)?></td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
<td valign="top" colspan="2" bgcolor="<?=appBackgroundColor?>">
	
	<table border="0" cellspacing="0" cellpadding="0" width="<?=contentWidth?>">
	<tr>
	<td valign="top"><?writeSpacer(savedDisplaySectionWidth,1)?></td>
	<td valign="top"><?writeSpacer(appSectionSpacerWidth,1)?></td>
	<td valign="top"><?writeSpacer(mainDisplaySectionWidth,1)?></td>
	</tr>
	<tr>
<?
}
// Function: Generate Application Saved Displays Section & Content Spacer Section
function genAppSavedDisplays($whichPage,$username) {
?>
	<td valign="top">
	
		<table border="0" cellspacing="0" cellpadding="0" width="<?=savedDisplaySectionWidth?>" bgcolor="<?=savedDisplayContentColor?>">
		<tr bgcolor="<?=appBorderColor?>">
		<td valign="top"><?writeSpacer(3,1)?></td>
		<td valign="top"><?writeSpacer(9,1)?></td>
		<td valign="top"><?writeSpacer(120,1)?></td>
		<td valign="top"><?writeSpacer(3,1)?></td>
		<td valign="top"><?writeSpacer(1,1)?></td>
		</tr>
		<tr>
		<td bgcolor="<?=savedDisplayHeaderColor?>"></td>
		<td valign="top" colspan="2" bgcolor="<?=savedDisplayHeaderColor?>"><p class="savedDisplayHeader">Saved Displays</td>
		<td bgcolor="<?=savedDisplayHeaderColor?>"></td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr bgcolor="<?=appBorderColor?>">
		<td colspan="5"><?writeSpacer(1,1)?></td>
		</tr>
		<tr>
		<td colspan="4"><?writeSpacer(1,7)?></td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr>
		<td valign="top" colspan="4">
			
			<script language="javascript">
			var speed = 3		
			iens6 = document.all||document.getElementById
			ns4 = document.layers
			if (iens6) {
				document.write('<div id="savedDisplayContainer" style="position:relative;width:<?=savedDisplayContentWidth?>px;height:<?=savedDisplayContentHeight?>px;overflow:hidden;border:0px">')
				document.write('<div id="savedDisplayContent" style="position:absolute;width:<?=savedDisplayContentWidth?>px;left:0px;top:0px">')
			}
			</script>
			<ilayer name="nsContainer" width="<?=savedDisplayContentWidth?>" height="<?=savedDisplayContentHeight?>" clip="0,0,<?=savedDisplayContentWidth?>,<?=savedDisplayContentHeight?>">
			<layer name="nsContent" width="<?=savedDisplayContentWidth?>" height="<?=savedDisplayContentHeight?>" visibility="hidden">
			<table border="0" cellspacing="0" cellpadding="0" width="<?=(savedDisplaySectionWidth-1)?>">
			<tr>
			<td valign="top"><?writeSpacer(3,1)?></td>
			<td valign="top"><?writeSpacer(9,1)?></td>
			<td valign="top"><?writeSpacer(120,1)?></td>
			<td valign="top"><?writeSpacer(3,1)?></td>
			</tr>
			<?genSavedDisplaysInfo($whichPage,$username);?>
			</table>
			</ilayer>
			</ilayer>
			<script language="javascript">
			if (iens6) {
				document.write('</div></div>')
				var crossobj = document.getElementById ? document.getElementById("savedDisplayContent") : document.all.content
				var contentheight = crossobj.offsetHeight
			} else if (ns4) {
				var crossobj = document.nsContainer.document.nsContent
				var contentheight = crossobj.clip.height
			}
			</script>
			<script language="javascript" src="<?=funcJavaSavedDisplaysScrollFile?>"></script>
			
		</td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr>
		<td colspan="4"><?writeSpacer(1,6)?></td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr>
		<td colspan="4" align="center"><p class="small">
		<a href="javascript:;" onmouseover="scrollUp()" onmouseout="stopScroll()"><img src="<?=imgUrl?>btnSavedDisplaysScrollUp.gif" width="16" height="10" border="0"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="javascript:;" onmouseover="scrollDown()" onmouseout="stopScroll()"><img src="<?=imgUrl?>btnSavedDisplaysScrollDown.gif" width="16" height="10" border="0"></a>
		</td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr>
		<td colspan="4"><?writeSpacer(1,2)?></td>
		<td bgcolor="<?=appBorderColor?>"></td>
		</tr>
		<tr bgcolor="<?=appBorderColor?>">
		<td colspan="5"><?writeSpacer(1,1)?></td>
		</tr>
		<tr>
		<td colspan="5"><?writeSpacer(1,3)?></td>
		</tr>
		<tr>
		<td valign="top" align="center" colspan="5"><p class="small">
		Statistics Archive:<br>
		<?genDropDownArchive($whichPage,$username);?>
		</td>
		</tr>
		</table>
	
	</td>
	<td></td>
<?
}
// Function: Generate Data Display Content Section
function genAppDataDisplay($whichPage,$username,$_GET) {
?>
	<td valign="top">
	
		<table border="0" cellspacing="0" cellpadding="0" width="<?=mainDisplaySectionWidth?>">
		<tr bgcolor="<?=appBorderColor?>">
		<td valign="top"><?writeSpacer(1,1)?></td>
		<td valign="top"><?writeSpacer(mainDisplayContentWidth,1)?></td>
		</tr>
		<tr>
		<td bgcolor="<?=appBorderColor?>"></td>
		<td bgcolor="<?=appContentColor?>">
		
		<?startDataDisplay($whichPage,$username,$_GET);?>
		
		</td>
		</tr>
		<tr bgcolor="<?=appBorderColor?>">
		<td colspan="2"><?writeSpacer(1,1)?></td>
		</tr>
		</table>
	
	</td>
<?
}
// Function: Generate Application Full/Display Footer
function genAppFullFooter($whichPage,$username) {
?>
	</tr>
	</table>

</td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
</tr>
<tr bgcolor="<?=appBackgroundColor?>">
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,34)?></td>
<td colspan="2">

	<table border="0" cellspacing="0" cellpadding="0" width="<?=contentWidth?>">
	<tr>
	<td valign="top"><?writeSpacer(savedDisplaySectionWidth,1)?></td>
	<td valign="top"><?writeSpacer(appSectionSpacerWidth,1)?></td>
	<td valign="top"><?writeSpacer(mainDisplaySectionWidth,1)?></td>
	</tr>
	<tr>
	<td valign="top" align="center">
	<p class="small" align="center"><?writeSpacer(1,3)?><br><a href="javascript:popWinFAQ('<?=faqPage?>',400,360);">FAQ</a><br>
	</td>
	<td></td>
	<td align="center"><p><?writeSpacer(1,2)?><br>
	<?
		// If Random Display - Give Option To Save, Otherwise Don't
		if (isset($_GET['r']) || $_SERVER['QUERY_STRING'] == "") {
	?><a href="javascript:popWin('<?=saveDisplayPage."?displayUrl=("?>'+displayUrlForPopWin+'<?")"?>&username=<?=$username?>',<?=appPopUpWinWidth?>,290);"><img src="<?=imgUrl?>btnFooterSaveDisplay.gif" width="121" height="18" border="0" alt="Save This Display"></a><?
			writeSpacer(10,1);
		}
	?><a href="<?=phpSelf?>?r=<?
		echo rand(1000,1000000);
		if (isset($_GET['monthView']) && $_GET['monthView'] != "")
			echo "&monthView=".$_GET['monthView'];
	?>"><img src="<?=imgUrl?>btnFooterCreateDisplay.gif" width="130" height="18" border="0" alt="Create New Display"></a><?
		writeSpacer(10,1);
	?><a href="javascript:window.print();"><img src="<?=imgUrl?>btnFooterPrintThisPage.gif" width="104" height="18" border="0" alt="Print This Page"></a><?
		// Add Spacer Gifs To Center Footer Buttons
		if (!isset($_GET['r']))
			writeSpacer(26,1);
		else
			writeSpacer(19,1);
	?>
	</td>
	</tr>
	</table>

</td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" colspan="4" bgcolor="<?=appBorderColor?>"><?writeSpacer(appWidth,1)?></td>
</tr>
</table>
</td></tr></table>

</body>
</html>
<?
}
// Function: Generate Application Small Header
function genAppSmHeader($whichPage) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title><?=appName?></title>
<?include(cssStyleFile);?>
<script language="javascript">
// Function: Set Input Focus On Page Load
function setInputFocus() {
	document.forms[0].elements[0].focus();
}
// Function: Refresh Opener Window and Close PopUp Window
function finishGo() {
	window.close();
}
</script>
</head>

<body bgcolor="<?=screenColor?>" topmargin="<?=appTopMargin?>" leftmargin="<?=appLeftMargin?>" marginheight="<?=appTopMargin?>" marginwidth="<?=appLeftMargin?>" onload="setInputFocus();">

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr><td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="<?=appSmWidth?>" align="center">
<tr bgcolor="<?=appBorderColor?>">
<td valign="top"><?writeSpacer(1,1)?></td>
<td valign="top"><?writeSpacer(contentSmWidth,1)?></td>
<td valign="top"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,45)?></td>
<td valign="top" bgcolor="<?=appHeaderColor?>"><img src="<?=imgUrl?>logo.gif" width="300" height="45" border="0" alt="<?=appName?>"></td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,45)?></td>
</tr>
<tr>
<td valign="top" colspan="3" bgcolor="<?=appBorderColor?>"><?writeSpacer(appSmWidth,1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
<td valign="top" bgcolor="<?=appContentColor?>">

	<table border="0" celspacing="0" cellpadding="0" width="<?=contentSmWidth?>">
	<tr>
	<td valign="top"><?writeSpacer(10,15)?></td>
	<td valign="top"><?writeSpacer(86,15)?></td>
	<td valign="top"><?writeSpacer(18,15)?></td>
	<td valign="top"><?writeSpacer(217,15)?></td>
	<td valign="top"><?writeSpacer(10,15)?></td>
	</tr>
<?
}
// Function: Generate Application Small Footer
function genAppSmFooter($whichPage) {
?>
	</table>

</td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" colspan="3" bgcolor="<?=appBorderColor?>"><?writeSpacer(appSmWidth,1)?></td>
</tr>
</table>
</td></tr></table>

</body>
</html>
<?
}
// Function: Generate Application View Details Header
function genAppViewDetails($whichPage,$username) {
global $_GET;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title><?=appName?></title>
<?include(cssStyleFile);?>
<script language="javascript" src="<?=funcJavaScriptFile?>"></script>
</head>

<body bgcolor="<?=screenColor?>" topmargin="<?=appTopMargin?>" leftmargin="<?=appLeftMargin?>" marginheight="<?=appTopMargin?>" marginwidth="<?=appLeftMargin?>" onblur="window.focus();">

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%"><tr><td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr bgcolor="<?=appBorderColor?>">
<td valign="top"><?writeSpacer(1,1)?></td>
<td valign="top"><?writeSpacer((int)($_GET['popUpWidth']/2-13),1)?></td>
<td valign="top"><?writeSpacer((int)($_GET['popUpWidth']/2-13),1)?></td>
<td valign="top"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>">
<td valign="top" bgcolor="<?=appHeaderColor?>" colspan="2"><img src="<?=imgUrl?>logoViewDetails.gif" width="150" height="34" border="0" alt="<?=appNameShort?>"></td>
<td valign="top" bgcolor="<?=appBorderColor?>">
</tr>
<tr>
<td valign="top" colspan="4" bgcolor="<?=appBorderColor?>"><?writeSpacer((int)($_GET['popUpWidth']-26),1)?></td>
</tr>
<tr>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
<td valign="top" bgcolor="<?=appContentColor?>" colspan="2">

	<table border="0" celspacing="0" cellpadding="0" width="100%" height="100%">
	<tr>
	<td valign="top">
	
		<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
		<tr>
		<td bgcolor="<?=appContentColor?>" valign="top">
		
		<?startDataDisplayViewDetails($whichPage,$username,$_GET);?>
		
		</td>
		</tr>
		</table>
	
	</td>
	</tr>
	</table>

</td>
<td valign="top" bgcolor="<?=appBorderColor?>"><?writeSpacer(1,1)?></td>
</tr>
<tr>
<td valign="top" colspan="4" bgcolor="<?=appBorderColor?>"><?writeSpacer((int)($_GET['popUpWidth']-26),1)?></td>
</tr>
</table>
</td></tr></table>

</body>
</html>
<?
}
?>
Return current item: DataDivisions