<?php

/***************************************************************************

 userinfo.php
 -------------
 copyright : (C) 2002-2003 The ezContents Development Team

 ***************************************************************************/

/***************************************************************************
 The ezContents Development Team offers no warranties on this script.
 The owner/licensee of the script is solely responsible for any problems
 caused by installation of the script or use of the script.

 All copyright notices regarding ezContents must remain intact on the
 scripts and in the HTML for the scripts.

 For more info on ezContents,
 visit http://www.ezcontents.org/

/***************************************************************************

/***************************************************************************
 *
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the License which can be found within the
 *	zipped package.
 *
 ***************************************************************************/

$GLOBALS["rootdp"] = './';
require_once ($GLOBALS["rootdp"]."include/config.php");
require_once ($GLOBALS["rootdp"]."include/db.php");
require_once ($GLOBALS["rootdp"]."include/session.php");


// This global is empty when framed.
if (($GLOBALS["gsUseFrames"] == '') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
	include ($GLOBALS["rootdp"]."include/settings.php");
	include ($GLOBALS["rootdp"]."include/functions.php");
	include ($GLOBALS["rootdp"]."include/banners.php");
	includeLanguageFiles('admin');
} // Frames includes
includeLanguageFiles('preferences');


if ($GLOBALS["gsShowTopMenu"] == 'Y') {
	if (!isset($HTTP_GET_VARS["groupname"])) {
		if (!isset($HTTP_GET_VARS["topgroupname"])) { $HTTP_GET_VARS["topgroupname"] = $GLOBALS["gsHomepageTopGroup"]; }
		$HTTP_GET_VARS["groupname"] = GetGroupName($HTTP_GET_VARS["topgroupname"]);
	}
}

if (($EZ_SESSION_VARS["LoginCookie"] != '') && ($HTTP_POST_VARS["submitted"] != "yes")) {
	if (bVerifyLogin()) { GetGlobalData();
	} else { exit; }
}


$GLOBALS["form"] = 'preferences';
$GLOBALS["tabindex"] = 1024;

if ($HTTP_POST_VARS["submitted"] == "yes") {
	if (bCheckForm()) {
		UpdatePreferences();
		if($GLOBALS["gsSendConfMail"] == 'Y') {
			SendMail();
		}
		// Timer values for cookies
		// 15 Minutes	= 900;
		// 1 Hour	= 3600;
		// 2 Hours	= 7200;
		// 6 Hours	= 21600;
		// 1 Day	= 86400;
		// 1 Year	= 31622400;
		if ($HTTP_POST_VARS["retaincookie"] == 'Y') { setcookie ("UserIdCookie", $EZ_SESSION_VARS["LoginCookie"], time()+31622400);
		} else { setcookie ("UserIdCookie", '', time()-31622400); }
		if ($HTTP_POST_VARS["password"] != '') {
			$sPassword = md5($sPassword);
			$EZ_SESSION_VARS["PasswordCookie"] = $sPassword;
		}
		$EZ_SESSION_VARS["UserName"] = $HTTP_POST_VARS["authorname"];
		if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
			HTMLHeader('preferences');
			StyleSheet();
			?>
			</head>
			<body marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="10" class="mainback">
			<?php
		} else {
			?>
			<table border="0" cellspacing="5" cellpadding="0" width="100%"><tr><td>
			<?php
		}

		//////////////////////////////////// TO DO - CHANGE HTML OUTPUT //////////////////////////////////
		?>
		<table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="98%" class="headercontent">
			<tr><td class="tablecontent">&nbsp;<?php
			if ($EZ_SESSION_VARS["LoginCookie"] != '') {
				echo $GLOBALS["tPrefsUpdated"];
			} else {
				echo $GLOBALS["tPrefsRegistered"];
				$EZ_SESSION_VARS["LoginCookie"] = $HTTP_POST_VARS["login"];
			}
			?>
			<br />&nbsp;</td></tr>
		</table>
		<?php
		db_session_write();
		exit;
	} else {
		GetFormData();
	}
}

frmAuthorForm();

function frmAuthorForm()
{
	global $EZ_SESSION_VARS;

	$f = 0;
	if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
		HTMLHeader('userinfo');
		StyleSheet();
		?>
		<script language="JavaScript" type="text/javascript">
		<!-- Begin
		function putFocus(formInst, elementInst) {
			if (document.forms.length > 0) {
				document.forms[formInst].elements[elementInst].focus();
			}
		}
		//  End -->
		</script>
		</head>
		<?php
		if ($EZ_SESSION_VARS["LoginCookie"] != '') {
			?><body marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="10" class="mainback" onLoad="putFocus('MaintAuthors','password');"><?php
		} else {
			?><body marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="10" class="mainback" onLoad="putFocus('MaintAuthors','login');"><?php
		}
	}
	?>
	<table border="0" cellspacing="5" cellpadding="0" width="100%">
	<tr><td>
	<table border="0" width="100%" cellspacing="0" cellpadding="0">
	<tr>
		<td align="center">
				<form name="MaintAuthors" action="userinfo.php" method="POST" enctype="multipart/form-data">
				<table border="0" width="100%" cellspacing="0" cellpadding="3">
				<tr class="headercontent">
					<td colspan="2" class="header">
						<?php
						if ($EZ_SESSION_VARS["LoginCookie"] != '') { echo $GLOBALS["tFormTitle"];
						} else { echo $GLOBALS["tFormTitle2"]; }
						?>
					</td>
				</tr>
				<tr class="tablecontent">
						<td class="content" colspan="2"><?php echo $GLOBALS["tRegisterIntroText"]; ?><br /><br /></td>
				</tr>
				<?php echo $GLOBALS["strErrors"]; ?>
				<?php
				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hLoginName"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<?php
					if ($EZ_SESSION_VARS["LoginCookie"] != '') {
						?><td valign=top class="content"><b><?php echo $GLOBALS["tLoginName"]; ?></b></td><?php
					} else {
						?><td valign=top class="content"><b><?php echo $GLOBALS["tLoginName"]; ?></b></td><?php
					}
					?><td><?php
					if ($EZ_SESSION_VARS["LoginCookie"] != '') {
						?><input type="text" name="login" size="20" value="<?php echo $GLOBALS["fsLogin"]; ?>" maxlength="20" disabled><?php
					} else {
						?><input type="text" name="login" size="20" value="<?php echo $GLOBALS["fsLogin"]; ?>" maxlength="20"><?php
					}
					?></td>
				</tr>
				<?php
				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hPassword"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<td class="content" valign=top><b><?php echo $GLOBALS["tPassword"]; ?></b></td>
					<td class="content">
					<input type="password" name="password" size="32" value="" maxlength="32">
					</td>
				</tr>
				<?php
				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hRetypePassword"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<td class="content" valign=top><b><?php echo $GLOBALS["tRetypePassword"]; ?></b></td>
					<td class="content">
					<input type="password" name="re_password" size="32" value="" maxlength="32">
					</td>
				</tr>
				<?php
				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hAuthorname"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<td class="content" valign=top><b><?php echo $GLOBALS["tAuthorname"]; ?></b></td>
					<td class="content">
						<input type="text" name="authorname" size="50" value="<?php echo $GLOBALS["fsAuthorName"]; ?>" maxlength="50">
					</td>
				</tr>
				<?php
				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hEMail"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<td class="content" valign=top><b><?php echo $GLOBALS["tEMail"]; ?></b></td>
					<td class="content">
						<input type="text" name="authoremail" size="50" value="<?php echo $GLOBALS["fsAuthorEmail"]; ?>" maxlength="255" onChange="return emailCheck(this.value);">
					</td>
				</tr>
				<?php
				if($GLOBALS["gsAddressStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hAddress"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tAddress"]; ?></b></td>
						<td class="content">
							<input type="text" name="address" size="50" value="<?php echo $GLOBALS["fsAddress"]; ?>" maxlength="100">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsCityStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hCity"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tCity"]; ?></b></td>
						<td class="content">
							<input type="text" name="city" size="50" value="<?php echo $GLOBALS["fsCity"]; ?>" maxlength="50">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsStateStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hState"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tState"]; ?></b></td>
						<td class="content">
							<input type="text" name="state" size="50" value="<?php echo $GLOBALS["fsState"]; ?>" maxlength="50">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsZipStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hZip"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tZip"]; ?></b></td>
						<td class="content">
							<input type="text" name="zip" size="20" value="<?php echo $GLOBALS["fsZip"]; ?>" maxlength="20">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsPhoneStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hPhone"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tPhone"]; ?></b></td>
						<td class="content">
							<input type="text" name="phone" size="20" value="<?php echo $GLOBALS["fsPhone"]; ?>" maxlength="20">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsFaxStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hFax"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tFax"]; ?></b></td>
						<td class="content">
							<input type="text" name="fax" size="20" value="<?php echo $GLOBALS["fsFax"]; ?>" maxlength="20">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsWebsiteStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hWebsite"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tWebsite"]; ?></b></td>
						<td class="content">
							<input type="text" name="website" size="50" value="<?php echo $GLOBALS["fsWebsite"]; ?>" maxlength="255">
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsNewsletterStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hNewsletter"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tNewsletter"]; ?></b></td>
						<td class="content">
								<input type="checkbox" name="newsletter" value="Y" <?php if($GLOBALS["fbNewsletter"] == 'Y') echo "checked"?><?php echo $GLOBALS["fieldstatus"]; ?>>
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsCommentsStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hComments"]; ?></td>
						</tr>
						<?php
					}
					?><tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tComments"]; ?></b></td>
						<td class="content">
							<textarea rows="4" name="comments" cols="40"<?php echo $GLOBALS["fieldstatus"]; ?>><?php echo htmlspecialchars($GLOBALS["fsComments"]); ?></textarea>
						</td>
					</tr>
				<?php
				}

				if($GLOBALS["gsCountryStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hCountry"]; ?></td>
						</tr>
						<?php
					}
					?>
					<tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tCountry"]; ?></b></td>
						<td class="content">
								<select name="countrycode" size="1">
								<OPTION value="00">
								<?php RenderCountries($GLOBALS["fsCountryCode"]); ?>
								</select>
						</td>
					</tr>
					<?php
				}

				if($GLOBALS["gsLanguageStatus"] != "N") {
					if($GLOBALS["gsShowHelptexts"] == "Y") {
						?>
						<tr class="tablecontent">
							<td colspan="2" class="helptext"><?php echo $GLOBALS["hLanguage"]; ?></td>
						</tr>
						<?php
					}
					?>
					<tr class="tablecontent">
						<td class="content" valign=top><b><?php echo $GLOBALS["tLanguage"]; ?></b</td>
						<td class="content">
								<select name="languagecode" size="1">
								<OPTION value="00">
								<?php RenderLanguages($GLOBALS["fsLanguageCode"]); ?>
								</select>
						</td>
					</tr>
				<?php
				}

				if($GLOBALS["gsShowHelptexts"] == "Y") {
					?>
					<tr class="tablecontent">
						<td colspan="2" class="helptext"><?php echo $GLOBALS["hRetainCookie"]; ?></td>
					</tr>
					<?php
				}
				?>
				<tr class="tablecontent">
					<td valign=top class="content"><b><?php echo $GLOBALS["tRetainCookie"]; ?></b></td>
					<td class="content">
						<input type="checkbox" name="retaincookie" value="Y" <?php if ($EZ_SESSION_VARS["LoginCookie"] != '') echo "checked"; ?>>
					</td>
				</tr>
				<tr class="tablecontent">
					<td class="content" colspan="2" align="<?php echo $GLOBALS["left"]; ?>">
						<?php
						if ($EZ_SESSION_VARS["LoginCookie"] != '') {
							?><input type="submit" value="<?php echo $GLOBALS["tUpdate"]; ?>" name="submit">&nbsp;<?php
						} else {
							?><input type="submit" value="<?php echo $GLOBALS["tRegister"]; ?>" name="submit">&nbsp;<?php
						}
						?>
						<input type="reset" value="<?php echo $GLOBALS["tReset"]; ?>" name="reset">&nbsp;
					</td>
				</tr>
				</table>
				<input type="hidden" name="ezSID" value="<?php echo $GLOBALS["ezSID"]; ?>">
				<input type="hidden" name="submitted" value="yes">
				<input type="hidden" name="regdate" value="<?php echo $GLOBALS["fsRegDate"]; ?>">
				<input type="hidden" name="page" value="<?php echo $HTTP_POST_VARS["page"]; ?>">
			</form>
		</td>
	</tr>
	</table>
	<?php
} // function frmAuthorForm()


function UpdatePreferences()
{
	global $EZ_SESSION_VARS, $HTTP_POST_VARS;

	$regisodate  = dbDateTime(sprintf("%04d-%02d-%02d", strftime("%Y"), strftime("%m"), strftime("%d")));

	$sLogin			= dbString($HTTP_POST_VARS["login"]);
	$sPassword		= dbString($HTTP_POST_VARS["password"]);
	$sAuthorName	= dbString($HTTP_POST_VARS["authorname"]);
	$sComments		= dbString($HTTP_POST_VARS["comments"]);
	$sAddress		= dbString($HTTP_POST_VARS["address"]);
	$sCity			= dbString($HTTP_POST_VARS["city"]);
	$sState			= dbString($HTTP_POST_VARS["state"]);
	$sZip			= dbString($HTTP_POST_VARS["zip"]);
	$sWebSite		= dbString($HTTP_POST_VARS["website"]);

	if ($HTTP_POST_VARS["countrycode"] == '00')  { $HTTP_POST_VARS["countrycode"] = ''; }
	if ($HTTP_POST_VARS["languagecode"] == '00') { $HTTP_POST_VARS["languagecode"] = ''; }

	if ($EZ_SESSION_VARS["LoginCookie"] != '') {
		$strQuery = "UPDATE ".$GLOBALS["eztbAuthors"]." SET authorname='".$sAuthorName."', authoremail='".$HTTP_POST_VARS["authoremail"]."', countrycode='".$HTTP_POST_VARS["countrycode"]."', language='".$HTTP_POST_VARS["languagecode"]."', phone='".$HTTP_POST_VARS["phone"]."', fax='".$HTTP_POST_VARS["fax"]."', address='".$sAddress."', city='".$sCity."', state='".$sState."', zip='".$sZip."', website='".$sWebSite."', comments='".$sComments."', newsletter='".$GLOBALS["gsNewsletter"]."' WHERE login='".$EZ_SESSION_VARS["LoginCookie"]."'";
	} else {
		$sPassword = md5($sPassword);
		$strQuery = "INSERT INTO ".$GLOBALS["eztbAuthors"]." VALUES('', '".$sLogin."', '".$sPassword."', '".$sAuthorName."','".$HTTP_POST_VARS["authoremail"]."', '".$regisodate."', '".$GLOBALS["gsPrivDefaultGroup"]."', '".$HTTP_POST_VARS["countrycode"]."', '".$HTTP_POST_VARS["languagecode"]."', '".$HTTP_POST_VARS["phone"]."', '".$HTTP_POST_VARS["fax"]."', '".$sAddress."', '".$sCity."', '".$sState."', '".$sZip."', '".$sWebSite."', '".$sComments."', '".$HTTP_POST_VARS["newsletter"]."', 'N', '0')";
	}
	$result = dbExecute($strQuery,true);
	if (($EZ_SESSION_VARS["LoginCookie"] != '') && ($sPassword != "")) {
		$sPassword = md5($sPassword);
		$strQuery = "UPDATE ".$GLOBALS["eztbAuthors"]." SET userpassword ='".$sPassword."' WHERE login='".$EZ_SESSION_VARS["LoginCookie"]."'";
		$result = dbExecute($strQuery,true);
		//  Update password for the session
		$EZ_SESSION_VARS["PasswordCookie"] = $sPassword;
		db_session_write();
	}
	dbCommit();
} // function UpdatePreferences()


function GetGlobalData()
{
	global $EZ_SESSION_VARS;

	$strQuery = "SELECT * FROM ".$GLOBALS["eztbAuthors"]." WHERE login='".$EZ_SESSION_VARS["LoginCookie"]."'";
	$result  = dbRetrieve($strQuery,true,0,0);
	$rs		= dbFetch($result);

	$GLOBALS["fsLogin"]				= $rs["login"];
	$GLOBALS["fsAuthorPassword"]	= "";
	$GLOBALS["fsAuthorName"]		= $rs["authorname"];
	$GLOBALS["fsAuthorEmail"]		= $rs["authoremail"];
	$GLOBALS["fsRegDate"]			= $rs["regdate"];
	$GLOBALS["fsUsergroup"]			= $rs["usergroup"];
	$GLOBALS["fsCountryCode"]		= $rs["countrycode"];
	$GLOBALS["fsLanguageCode"]		= $rs["language"];
	$GLOBALS["fsPhone"]				= $rs["phone"];
	$GLOBALS["fsFax"]				= $rs["fax"];
	$GLOBALS["fsAddress"]			= $rs["address"];
	$GLOBALS["fsCity"]				= $rs["city"];
	$GLOBALS["fsState"]				= $rs["state"];
	$GLOBALS["fsZip"]				= $rs["zip"];
	$GLOBALS["fsWebsite"]			= $rs["website"];
	$GLOBALS["fsComments"]			= $rs["comments"];
	$GLOBALS["fbNewsletter"]		= $rs["newsletter"];

	dbFreeResult($result);
} // function GetGlobalData()


function GetFormData()
{
	global $HTTP_POST_VARS;

	$GLOBALS["fsLogin"]				= $HTTP_POST_VARS["login"];
	$GLOBALS["fsAuthorPassword"]	= $HTTP_POST_VARS["password"];
	$GLOBALS["fsAuthorName"]		= $HTTP_POST_VARS["authorname"];
	$GLOBALS["fsAuthorEmail"]		= $HTTP_POST_VARS["authoremail"];
	$GLOBALS["fsRegDate"]			= $HTTP_POST_VARS["regdate"];
	$GLOBALS["fsUsergroup"]			= $HTTP_POST_VARS["usergroup"];
	$GLOBALS["fsCountryCode"]		= $HTTP_POST_VARS["countrycode"];
	$GLOBALS["fsLanguageCode"]		= $HTTP_POST_VARS["languagecode"];
	$GLOBALS["fsPhone"]				= $HTTP_POST_VARS["phone"];
	$GLOBALS["fsFax"]				= $HTTP_POST_VARS["fax"];
	$GLOBALS["fsAddress"]			= $HTTP_POST_VARS["address"];
	$GLOBALS["fsCity"]				= $HTTP_POST_VARS["city"];
	$GLOBALS["fsState"]				= $HTTP_POST_VARS["state"];
	$GLOBALS["fsZip"]				= $HTTP_POST_VARS["zip"];
	$GLOBALS["fsWebsite"]			= $HTTP_POST_VARS["website"];
	$GLOBALS["fsComments"]			= $HTTP_POST_VARS["comments"];
	$GLOBALS["fbNewsletter"]		= $HTTP_POST_VARS["newsletter"];

} // function GetFormData()


function bCheckForm()
{
	global $EZ_SESSION_VARS, $HTTP_POST_VARS;

	$bFormOK = true;
	$strMessage = '<tr class="tablecontent"><td colspan="2"><font color="'.$GLOBALS["gsErrFormFontColor"].'"><b>';
	if ($EZ_SESSION_VARS["LoginCookie"] == '') {
		if ($HTTP_POST_VARS["login"] == "") {
			$strMessage .= $GLOBALS["eLoginEmpty"].'<br />';
			$bFormOK = false;
		} else {
			if (bLoginNameExists()) {
				$strMessage .= $GLOBALS["eLoginExists"].'<br />';
				$bFormOK = false;
			}
		}
	}
	if ($HTTP_POST_VARS["password"] != $HTTP_POST_VARS["re_password"]) {
		$strMessage .= $GLOBALS["ePasswordError"].'<br />';
		$bFormOK = false;
	}
	if ($HTTP_POST_VARS["authorname"] == "") {
		$strMessage .= $GLOBALS["eNameEmpty"].'<br />';
		$bFormOK = false;
	}
	if(!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $HTTP_POST_VARS["authoremail"])) {
		$strMessage .= $GLOBALS["eEMailEmpty"].'<br />';
		$bFormOK = false;
	}
	if ($GLOBALS["gsPhoneStatus"] == "M" && $HTTP_POST_VARS["phone"] == "") {
		$strMessage .= $GLOBALS["ePhoneEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsFaxStatus"] == "M" && $HTTP_POST_VARS["fax"] == "") {
		$strMessage .= $GLOBALS["eFaxEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsAddressStatus"] == "M" && $HTTP_POST_VARS["address"] == "") {
		$strMessage .= $GLOBALS["eAddressEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsCityStatus"] == "M" && $HTTP_POST_VARS["city"] == "") {
		$strMessage .= $GLOBALS["eCityEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsStateStatus"] == "M" && $HTTP_POST_VARS["state"] == "") {
		$strMessage .= $GLOBALS["eStateEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsZipStatus"] == "M" && $HTTP_POST_VARS["zip"] == "") {
		$strMessage .= $GLOBALS["eZipEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsCountryStatus"] == "M" && $HTTP_POST_VARS["countrycode"] == "00") {
		$strMessage .= $GLOBALS["eCountryEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsLanguageStatus"] == "M" && $HTTP_POST_VARS["languagecode"] == "00") {
		$strMessage .= $GLOBALS["eLanguageEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsWebsiteStatus"] == "M" && $HTTP_POST_VARS["website"] == "") {
		$strMessage .= $GLOBALS["eWebsiteEmpty"].'<br />';
		$bFormOK = false;
	}

	if ($GLOBALS["gsCommentsStatus"] == "M" && $HTTP_POST_VARS["comments"] == "") {
		$strMessage .= $GLOBALS["eCommentsEmpty"].'<br />';
		$bFormOK = false;
	}

	$strMessage .= '</font></b><br /></td></tr>';
	if (!$bFormOK) { $GLOBALS["strErrors"] = $strMessage; }
	return $bFormOK;
} // function bCheckForm()


function bLoginNameExists()
{
	global $HTTP_POST_VARS;

	$strQuery = "SELECT login FROM ".$GLOBALS["eztbAuthors"]." WHERE login='".str_replace("'", "\'", $HTTP_POST_VARS["login"])."'";
	$result = dbRetrieve($strQuery,true,0,0);
	if (dbRowsReturned($result) > 0) {
		dbFreeResult($result);
		return true;
	}
	dbFreeResult($result);
	return false;
} // function bLoginNameExists()


function RenderCountries($CountryCode)
{
	$sqlQuery = "SELECT * FROM ".$GLOBALS["eztbCountries"]." ORDER BY countryname";
	$result = dbRetrieve($sqlQuery,true,0,0);
	while ($rs = dbFetch($result)) {
		echo "<option ";
		if ($CountryCode == $rs["countrycode"]) { echo "selected "; }
		echo 'value="'.$rs["countrycode"].'">'.$rs["countryname"];
	}
	dbFreeResult($result);
} // function RenderCountries()

function strGetCountry($CountryCode)
{
	$sqlQuery = "SELECT * FROM ".$GLOBALS["eztbCountries"]." WHERE countrycode='".$CountryCode."'";
	$result = dbRetrieve($sqlQuery,true,0,0);
	if ($rs = dbFetch($result)) { $strCountryName = $rs["countryname"]; }
	dbFreeResult($result);
	return $strCountryName;
} // function strGetCountry()


function RenderLanguages($LanguageCode)
{
	$sqlQuery = "SELECT * FROM ".$GLOBALS["eztbLanguages"]." WHERE enabled='Y' ORDER BY languagename";
	$result = dbRetrieve($sqlQuery,true,0,0);
	while ($rs = dbFetch($result)) {
		echo "<option ";
		if ($LanguageCode == $rs["languagecode"]) { echo "selected "; }
		echo "value=\"".$rs["languagecode"]."\">".$rs["languagename"];
	}
	dbFreeResult($result);
} // function RenderLanguages()

function strGetLanguage($LanguageCode)
{
	$sqlQuery = "SELECT * FROM ".$GLOBALS["eztbLanguages"]." WHERE languagecode='".$LanguageCode."'";
	$result = dbRetrieve($sqlQuery,true,0,0);
	if ($rs = dbFetch($result)) { $strLanguageName = $rs["languagename"]; }
	dbFreeResult($result);

	return $strLanguageName;

} // function strGetLanguage()

function strGetAdminEmail()
{
	$sqlQuery = "SELECT * FROM ".$GLOBALS["eztbAuthors"]." WHERE login='admin'";
	$result = dbRetrieve($sqlQuery,true,0,0);
	if ($rs = dbFetch($result)) { $strAdminEmail = $rs["authoremail"]; }
	dbFreeResult($result);
	return $strAdminEmail;
} // function strGetLanguage()

ShowFooterBanner();


function bVerifyLogin()
{
	global $EZ_SESSION_VARS;
	$strQuery = "SELECT login FROM ".$GLOBALS["eztbAuthors"]." WHERE login='".$EZ_SESSION_VARS["LoginCookie"]."' AND userpassword='".$EZ_SESSION_VARS["PasswordCookie"]."'";
	$result = dbRetrieve($strQuery,true,0,0);
	$rs			= dbFetch($result);
	if (dbRowsReturned($result) > 0) {
		dbFreeResult($result);
		return true;
	}
	dbFreeResult($result);

	if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
		HTMLHeader('userinfo');
		StyleSheet();
		?>
		</head>
		<body marginwidth="0" marginheight="0" leftmargin="5" rightmargin="5" topmargin="10" class="mainback"><?php
	} else { ?><table border="0" cellspacing="5" cellpadding="0" width="100%"><tr><td><?php } ?>

	<table border="1" cellpadding="1" cellspacing="0" align="center" valign="top" width="98%" class="headercontent">
		<tr><td class="tablecontent">&nbsp;<br />
				<?php
				echo $GLOBALS["tMustLogin"];
				if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
					?>
					<a href="<?php echo BuildLink('login.php'); ?>&ref=userdata.php" target="userdata">
					<?php
				} else {
					?>
					<a href="<?php echo BuildLink('control.php'); ?>&topgroupname=<?php echo $GLOBALS["topgroupname"]; ?>&groupname=<?php echo $GLOBALS["groupname"]; ?>&subgroupname=<?php echo $GLOBALS["subgroupname"]; ?>&ulink=login.php&ref=control.php&link=userinfo.php">
					<?php
				}
				?>
				<?php echo $GLOBALS["tLogin"]; ?></a> <?php echo $GLOBALS["tToUpdateDetails"]; ?>.<br />&nbsp;</td>
			</tr>
	</table>
	<?php
	return false;
} // function bVerifyLogin()


?>
</td></tr>
</table>
<?php
if (($GLOBALS["gsUseFrames"] == 'Y') && ($EZ_SESSION_VARS["noframesbrowser"] != True)) {
	?>
	</body>
	</html>
	<?php
}


function GetGroupName($topgroupname)
{
	$gname = $GLOBALS["gsHomepageGroup"];
	$strQuery = "SELECT * FROM ".$GLOBALS["eztbGroups"]." WHERE topgroupname='".$topgroupname."' AND language='".$GLOBALS["gsDefault_language"]."' ORDER BY grouporderid";
	$result = dbRetrieve($strQuery,true,0,1);
	if ($rs = dbFetch($result)) { $gname = $rs["groupname"]; }
	dbFreeResult($result);
	return $gname;
} // function GetGroupName()

function SendMail()
{
	global $HTTP_POST_VARS;

	$strSubmittedData = "\r\n---------------------------------------------------\r\n\r\n".
		$GLOBALS["tLoginName"] . ": ".$HTTP_POST_VARS["login"]."\r\n".
		$GLOBALS["tPassword"] . ": ".$HTTP_POST_VARS["password"]."\r\n".
		$GLOBALS["tAuthorname"] . ": ".$HTTP_POST_VARS["authorname"]."\r\n".
		$GLOBALS["tEMail"] . ": ".$HTTP_POST_VARS["authoremail"]."\r\n";
		if($GLOBALS["gsPhoneStatus"] != "N" && $HTTP_POST_VARS["phone"] != "")
			$strSubmittedData .= $GLOBALS["tPhone"] . ": ".$HTTP_POST_VARS["phone"]."\r\n";
		if($GLOBALS["gsFaxStatus"] != "N" && $HTTP_POST_VARS["fax"] != "")
			$strSubmittedData .= $GLOBALS["tFax"] . ": ".$HTTP_POST_VARS["fax"]."\r\n";
		if($GLOBALS["gsAddressStatus"] != "N" && $HTTP_POST_VARS["address"] != "")
			$strSubmittedData .= $GLOBALS["tAddress"] . ": ".$HTTP_POST_VARS["address"]."\r\n";
		if($GLOBALS["gsZipStatus"] != "N" && $HTTP_POST_VARS["zip"] != "")
			$strSubmittedData .= $GLOBALS["tZip"] . ": ".$HTTP_POST_VARS["zip"]."\r\n";
		if($GLOBALS["gsCityStatus"] != "N" && $HTTP_POST_VARS["city"] != "")
			$strSubmittedData .= $GLOBALS["tCity"] . ": ".$HTTP_POST_VARS["city"]."\r\n";
		if($GLOBALS["gsStateStatus"] != "N" && $HTTP_POST_VARS["state"] != "")
			$strSubmittedData .= $GLOBALS["tState"] . ": ".$HTTP_POST_VARS["state"]."\r\n";
		if($GLOBALS["gsCountryStatus"] != "N" && $HTTP_POST_VARS["countrycode"] != "00")
			$strSubmittedData .= $GLOBALS["tCountry"] . ": ".strGetCountry($HTTP_POST_VARS["countrycode"])."\r\n";
		if($GLOBALS["gsLanguageStatus"] != "N" && $HTTP_POST_VARS["languagecode"] != "00")
			$strSubmittedData .= $GLOBALS["tLanguage"] . ": ".strGetLanguage($HTTP_POST_VARS["languagecode"])."\r\n";
		if($GLOBALS["gsWebsiteStatus"] != "N" && $HTTP_POST_VARS["website"] != "")
			$strSubmittedData .= $GLOBALS["tWebsite"] . ": ".$HTTP_POST_VARS["website"]."\r\n";
		if($GLOBALS["gsNewsletterStatus"] != "N")
			$strSubmittedData .= $GLOBALS["tNewsletter"] . ": ".$HTTP_POST_VARS["newsletter"]."\r\n";
		if($GLOBALS["gsCommentsStatus"] != "N" && $HTTP_POST_VARS["comments"] != "")
			$strSubmittedData .= $GLOBALS["tComments"] . ":\r\n".$HTTP_POST_VARS["comments"]."\r\n";

	if($GLOBALS["gsServerUserEmail"] != '') {
		$GLOBALS["strServerUserAccount"] = $GLOBALS["gsServerUserEmail"];
	} else {
		$GLOBALS["strServerUserAccount"] = strGetAdminEmail();
	}

	mail($HTTP_POST_VARS["authoremail"], $GLOBALS["tReturnMailSubject"], "\r\n".$GLOBALS["tReturnMailBody"].$strSubmittedData, "From: ".strGetAdminEmail(), " -f".$GLOBALS["strServerUserAccount"]);
}


include($GLOBALS["rootdp"]."include/javafuncs.php");

?>
