<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
// 
// Copyright (C) 2003 - 2006 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

?>

<form action="sho_view.php" method="post" name="frm" id="id_frm">

<?php
if ($this->user_acs->checkPermission($resource_ids['node']['shoutbox'], $privilege_ids['add_item'])) { //resourece_id, Priv_id
?>
<div class="col_main">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_latest_shouts'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table width="100%" cellpadding="4" cellspacing="0" border="0">
					<?php
					if (isset($shouts)) {
					foreach($shouts as $key => $i):
					?>
					<tr valign="top">
						<td width="3" valign="top">
							<img src="<?php echo $templatePath;?>img/dot.png" width="3" height="9" alt="" /><br />
						</td>
						<td valign="top">
							<?php echo $this->date->formatDate($i['shoutbox_create_datetime'], 1);?><br />
						</td>
						<td valign="top">
							<?php echo $i['shoutbox_body'];?><br />
						</td>
						<td align="right" valign="top">
							<a href="sn_profile.php?user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
						</td>
					</tr>
					<?php
					endforeach;
					} else {
					?>
					<tr>
						<td colspan="4">
							<?php echo $lang['err_no_shouts'];?><br />
						</td>
					</tr>
					<?php }?>
				</table>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<div class="col_side">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_add_shout'];?><br />
		</div>

		<div class="box_mid">
			<div class="content">
				<p>
					<?php echo $lang['txt_shout_intro'];?><br />
				</p>
				
				<p>
					<textarea name="shout_text" onKeyPress="return updateCharsLeft(this, event, 200)" onBlur="truncatefield(this)" onChange="truncatefield(this)" onKeyUp="truncatefield(this)" cols="22" rows="4"></textarea><br />
				</p>
				
				<p align="right">
				<input type="text" size="3" name="charsleft" value="200" disabled onFocus="this.form.sub.focus()" />
				&nbsp;&nbsp;
				<input type="submit" name="insert_shout" value="<?php echo $lang['sub_shout'];?>" class="button_urgent" /><br />
				</p>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>
<?php
}
else {
?>
<div>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_latest_shouts'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<table width="100%" cellpadding="4" cellspacing="0" border="0">
					<?php
					if (isset($shouts)) {
					foreach($shouts as $key => $i):
					?>
					<tr valign="top">
						<td width="3" valign="top">
							<img src="<?php echo $templatePath;?>img/dot.png" width="3" height="9" alt="" /><br />
						</td>
						<td valign="top">
							<?php echo $this->date->formatDate($i['shoutbox_create_datetime'], 1);?><br />
						</td>
						<td valign="top">
							<?php echo $i['shoutbox_body'];?><br />
						</td>
						<td align="right" valign="top">
							<a href="sn_profile.php?user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
						</td>
					</tr>
					<?php
					endforeach;
					} else {
					?>
					<tr>
						<td colspan="4">
							<?php echo $lang['err_no_shouts'];?><br />
						</td>
					</tr>
					<?php }?>
				</table>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>
<?php }?>

</form>

<script language="javascript">
<!--

function messageLength( theForm ) {
	return theForm.elements[0].value.length
	}

function updateCharsLeft(obj, evt) {
	var stupidMac = false;

	if (navigator.appVersion.search("MSIE 4.5; Macintosh") > -1) {
		stupidMac = true;
	}

	var charsLeft = 200 - messageLength( obj.form )
	obj.form.charsleft.value = charsLeft;
	var allowKey = false;

	var keyCode = (navigator.appName == "Netscape") ? evt.which : evt.keyCode;
	if ((keyCode > 31 || keyCode == 10 || keyCode == 13) && obj.value.length < 200) {
		allowKey = true;
	}

	if (keyCode == 8) {
		allowKey = true;
	}

	if (allowKey == true) {
		return stupidMac == true ? keyCode : true;
	} else {
		return stupidMac == true ? 0 : false;
	}
}

function truncatefield(obj) {
	var charsLeft = 200 - messageLength( obj.form )
	if (charsLeft < 0) {
		obj.value = obj.value.substring(0, obj.value.length + charsLeft)
		charsLeft = 0
	}
	obj.form.charsleft.value = charsLeft;
}

//-->
</script>
