<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 9/22/2014	ELL

$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'CreateAcctLink'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$CreateAcctLink = $row["option_value"];
}
else
	$CreateAcctLink = "create_account.php";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'CreateAcctLinkTxt'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$CreateAcctLinkTxt = $row["option_value"];
}
else
	$CreateAcctLinkTxt = "Create Account";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'LoginLink'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$LoginLink = $row["option_value"];
}
else
	$LoginLinkoption_name = "login.php";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'LoginLinkTxt'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$LoginLinkTxt = $row["option_value"];
}
else
	$LoginLinkTxt = "Login";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'MyAcctLink'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$MyAcctLink = $row["option_value"];
}
else
	$MyAcctLink = "my_account.php";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'MyAcctLinkTxt'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$MyAcctLinkTxt = $row["option_value"];
}
else
	$MyAcctLinkTxt = "My Account";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'LogoutLinkTxt'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$LogoutLinkTxt = $row["option_value"];
}
else
	$LogoutLinkTxt = "Logout";
	
$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'LogoutRedirectOverride'";
$result = $bwb_dbh->query($query);
if ($result->rowCount() > 0)	{
	$row = $result->fetch(PDO::FETCH_ASSOC);
	if (isset($row["option_value"]) && ($row["option_value"] != ""))
		$LogoutRedirect = $row["option_value"];
	else
		$LogoutRedirect = $this_page;
}
else
	$LogoutRedirect = $this_page;
?>

<div id="login_logout">
<?php if ((!$userid) || (!$curr_session)) { ?>
	<div id="create_acct_div_btn" class="link_div"><a href="<?php echo $CreateAcctLink; ?>"><span id="create_acct_btn_txt" class="link_txt"><?php echo $CreateAcctLinkTxt; ?></span></a></div>
	<div id="login_div_btn" class="link_div"><a href="<?php echo $LoginLink; ?>"><span id="login_btn_txt" class="link_txt"><?php echo $LoginLinkTxt; ?></span></a></div>
<?php }  if (($userid) && ($curr_session)) { ?>
	<div id="my_account_div_btn" class="link_div"><a href="<?php echo $MyAcctLink; ?>"><span id="my_account_btn_txt" class="link_txt"><?php echo $MyAcctLinkTxt; ?></span></a></div>
    <div id="logout_form_div">
    <form name="frmLogOut" id="frmLogOut" method="post" action="/php/logout.php">
      <div id="logout_div_btn" class="link_div" onClick="document.getElementById('frmLogOut').submit();"><a href="#"><span id="logout_btn_txt" class="link_txt"><?php echo $LogoutLinkTxt; ?></span></a></div>
      <input type="hidden" name="logout_redirect" id="logout_redirect" value="<?php echo $webpage_dir . $LogoutRedirect; ?>" />
    </form>
    </div>
<?php } ?>
</div>