<?php
    session_start();          
    if(empty($_SESSION['p0B_c0ff33'])) header('location:login.php?goto=index');
	include "../db_function.php";

	$masg = -1;

	if (isset($_POST['btn_submit'])) {
		$detail_addr = mysql_real_escape_string($_POST['txt_detail']);
		$detail_copy = mysql_real_escape_string($_POST['txt_copyright']);

		// --- Save Footer Left / Address (page='address') ---
		$res_addr = mysql_query("SELECT id FROM tbltext WHERE page='address'");
		if ($res_addr && mysql_num_rows($res_addr) > 0) {
			mysql_query("UPDATE tbltext SET detail='" . $detail_addr . "' WHERE page='address'");
		} else {
			mysql_query("INSERT INTO tbltext (detail, page) VALUES ('" . $detail_addr . "', 'address')");
		}

		// --- Save Copyright text (page='footer_copyright') ---
		$res_copy = mysql_query("SELECT id FROM tbltext WHERE page='footer_copyright'");
		if ($res_copy && mysql_num_rows($res_copy) > 0) {
			mysql_query("UPDATE tbltext SET detail='" . $detail_copy . "' WHERE page='footer_copyright'");
		} else {
			mysql_query("INSERT INTO tbltext (detail, page) VALUES ('" . $detail_copy . "', 'footer_copyright')");
		}

		header("location:footer.php?p=footer&msg=1");
		exit();
	}

    if(empty($_GET['p'])){
        $_GET['p']="footer";
    }

	include('templates/header.php'); 
	include('templates/menu.php'); 

	// Load current saved values
	$res_addr = mysql_query("SELECT * FROM tbltext WHERE page='address'");
	$addr_row = ($res_addr && mysql_num_rows($res_addr) > 0) ? mysql_fetch_array($res_addr) : array();
	$current_addr = isset($addr_row['detail']) ? $addr_row['detail'] : '';

	$res_copy = mysql_query("SELECT * FROM tbltext WHERE page='footer_copyright'");
	$copy_row = ($res_copy && mysql_num_rows($res_copy) > 0) ? mysql_fetch_array($res_copy) : array();
	$current_copy = isset($copy_row['detail']) ? $copy_row['detail'] : 'រក្សាសិទ្ធិគ្រប់យ៉ាងនៅឆ្នាំ ២០១៣ ដោយ LoveWedding';
?>

<!-- start content-outer -->
<div id="content-outer">
<!-- start content -->
<div id="content">

<div id="page-heading">
  <h1>Edit Website Footer</h1>
</div>

<?php if ($masg == 0): ?>
<div id="message-red">
	<table border="0" width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td class="red-left">Failed to save footer content. Please try again.</td>
		<td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif" alt="" /></a></td>
	</tr>
	</table>
</div>
<?php endif; ?>
  
<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
<tr>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
	<th class="topleft"></th>
	<td id="tbl-border-top">&nbsp;</td>
	<th class="topright"></th>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
</tr>
<tr>
	<td id="tbl-border-left"></td>
	<td>
		<div id="content-table-inner">

		<form action="afooter.php?p=footer" method="post" id="formFooter">
			<table border="0" cellpadding="0" cellspacing="0" id="id-form">

			<!-- ROW 1: Copyright / Heading Text -->
			<tr>
				<th valign="top" style="padding-top:10px; width: 200px;">Copyright Text:</th>
				<td style="padding-top:10px;">
					<input type="text" name="txt_copyright" class="inp-form" style="width: 100%; font-family: 'Kh Freehand','Khmer OS',Arial,sans-serif; font-size: 13px;"
						value="<?php echo htmlspecialchars($current_copy); ?>"
						placeholder="e.g. រក្សាសិទ្ធិគ្រប់យ៉ាងនៅឆ្នាំ ២០១៣ ដោយ LoveWedding" />
					<br /><small style="color:#666;">This text appears as the copyright headline in the footer left section. Default: <em>រក្សាសិទ្ធិគ្រប់យ៉ាងនៅឆ្នាំ ២០១៣ ដោយ LoveWedding</em></small>
				</td>
				<td></td>
			</tr>

			<!-- ROW 2: Address / Contact Info -->
			<tr>
				<th valign="top" style="padding-top:12px;">Address / Contact Info:</th>
				<td style="padding-top:12px;">
					<textarea name="txt_detail" rows="6" class="inp-form"
						style="width: 100%; min-height: 110px; font-family: 'Kh Freehand','Khmer OS',Arial,sans-serif; font-size: 13px; resize: vertical;"
						placeholder="Enter contact address, phone number, email, etc..."><?php echo htmlspecialchars($current_addr); ?></textarea>
					<br /><small style="color:#666;">Additional address or contact text appearing below the copyright text.</small>
				</td>
				<td></td>
			</tr>

			<!-- ROW 3: Footer Right (static info display) -->
			<tr>
				<th style="padding-top: 8px;">Footer Right (Fixed):</th>
				<td style="padding-top: 8px;">
					<div style="padding: 8px 10px; background: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; font-size: 12px; color: #666; font-family: 'Kh Freehand', Arial, sans-serif;">
						<strong>Fixed Content:</strong> រចនាដោយ &nbsp;<a href="http://www.thecita.net" target="_blank">CITA</a> &nbsp;|&nbsp; <b>Advertise with us</b>
						<br /><small style="color: #999; margin-top: 4px; display: block;">This section is static and cannot be changed here.</small>
					</div>
				</td>
				<td></td>
			</tr>

			<!-- SUBMIT -->
			<tr>
				<th>&nbsp;</th>
				<td valign="top" style="padding-top: 12px;">
					<input type="submit" name="btn_submit" value="Save Footer" class="form-submit" />
					<a href="footer.php?p=footer" class="form-reset" style="display:inline-block; padding: 6px 14px; margin-left:10px; background:#999; color:#fff; text-decoration:none; border-radius:3px;">Cancel</a>
				</td>
				<td></td>
			</tr>
			</table>
		</form>

		<div class="clear"></div>
		</div>
	</td>
	<td id="tbl-border-right"></td>
</tr>
<tr>
	<th class="sized bottomleft"></th>
	<td id="tbl-border-bottom">&nbsp;</td>
	<th class="sized bottomright"></th>
</tr>
</table>
<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer -->

<div class="clear">&nbsp;</div>

<?php include('templates/footer.php'); ?>
