<?php
/**
 * @version $Id$
 * @package    Contact_Enhanced
 * @subpackage Views
 * @author     Douglas Machado {@link http://ideal.fok.com.br}
 * @author     Created on 04-Dec-09
 * @license		GNU/GPL, see license.txt
 * Contact Enhanced  is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses. */

//-- No direct access
defined('_JEXEC') or die('=;)');

JHTML::_('behavior.tooltip');

?>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<table>
	<tr>
		<td align="left" width="100%">
			<?php echo JText::_( 'Filter' ); ?>:
			<input type="text" name="search" id="search" value="<?php echo $this->lists['search'];?>" class="text_area" onchange="document.adminForm.submit();" />
			<?php echo $this->lists['catid']; ?>
			<button onclick="$('task').value='';this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
			<button onclick="document.getElementById('search').value='';this.form.getElementById('filter_item').value='';this.form.submit();"><?php echo JText::_( 'Reset' ); ?></button>
		</td>
		<td nowrap="nowrap">
			<?php 
				if($this->filter_catid){
					echo  JHTML::_('link','#', JText::_('Export to CSV file'),'onclick="$(\'task\').value=\'exportToCSV\';$(\'adminForm\').submit();"');
					echo ' <small style="color:gray">('.JText::_('Requires PHP5').')</small>';
					echo ' <sup style="color:green">('.JText::_('New').')</sup>';
				}else{
					echo JText::_('Export to CSV file').': '.JText::_('Select a category first');
				}
			?>
		</td>
	</tr>
</table>
<div id="tablecell">
	<table class="adminlist">
	<thead>
		<tr>
			<th width="1%">
				<?php echo JText::_( 'NUM' ); ?>
			</th>
			<th width="1%">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
			<th width="1%" nowrap="nowrap">
				<?php echo JHTML::_('grid.sort',   'id', 'm.id', $this->lists['order_Dir'], $this->lists['order'] ); ?>
			</th>
			<?php $coloumnCount = 2; ?>
		
			<th>
				<?php echo JHTML::_('grid.sort', 'Name', 'm.from_name', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Email', 'm.from_email', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Subject', 'm.subject', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Published', 'm.published', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Replies', 'replies', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JText::_('Last reply by');?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Contact Form', 'm.contact_id', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Category', 'm.category_id', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Date', 'm.date', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort', 'Username', 'm.from_id', $this->lists['order_Dir'], $this->lists['order']);?>
			</th>
			
			<th width="5%">
				<?php echo JText::_('Has attachments');?>
			</th>
	<?php $coloumnCount += 11; ?>
	<?php 
 ?>
		</tr>
	</thead>
	
	<tbody>
	<?php
	$k = 0;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)
	{
		$row = &$this->items[$i];
		$link = JRoute::_( 'index.php?option=com_contact_enhanced&controller=messages&task=view&cid[]='. $row->id.'&catid='. $row->category_id);
		
		$checked 	= JHTML::_('grid.id',  $i, $row->id );

		$published 	= JHTML::_('grid.published', $row, $i );
	?>
		<tr class="<?php echo "row$k"; ?>">
			<td>
				<span class="editlinktip hasTip" title="<?php echo JText::_('View'); ?>">
					<a href="<?php echo $link; ?>">
						<?php echo $this->pagination->getRowOffset($i); ?>
					</a>
				</span>
			</td>
			<td>
				<?php echo $checked; ?>
			</td>
			<td align="center">
						<?php echo $row->id; ?>
			</td>
				
			<td><?php echo $row->from_name; ?></td>
			<td>
				<?php echo $row->from_email; ?>
			</td>
			<td>
				<span class="editlinktip hasTip" style="width:300px" title="<?php echo JText::_('View').': <br /><pre>'.$row->message.'</pre>'; ?>">
					<a href="<?php echo $link; ?>">
						<?php echo $row->subject; ?>
					</a>
				</span>
			</td>
			<td align="center">
				<?php echo $published ?>
			</td>
			
			<td>
				<?php echo $row->replies; ?>
			</td>
			<td>
				<?php 	if($row->replied_by){
							$lastReplier	= $user =& JFactory::getUser($row->replied_by);
							echo $lastReplier->name.' ('.$lastReplier->username.')';
						}else{
							echo JText::_('Never replied');
						} ?>
			</td>
			<td>
				<?php echo $row->contact_name; ?>
			</td>
			<td>
				<?php echo $row->category_name; ?>
			</td>
			<td>
				<?php 
					$date			=& JFactory::getDate($row->date);
					echo $date->toFormat(JText::_('DATE_FORMAT_LC2'));
				?>
			</td>
			<td>
				<?php if($row->from_id): ?>
					<span class="editlinktip hasTip" title="<?php echo JText::_('User').': '.$row->user_name.'<br />'.JText::_('User ID').': '.$row->from_id; ?>">
						<?php echo $row->username; ?>
					</span>
				<?php else: ?>
					<?php echo JText::_('User was not logged in'); ?>
				<?php endif; ?>
			</td>
			
			<td style="text-align:center">
				<?php if( $row->attachments ): ?>
					<span class="editlinktip hasTip" title="<?php echo $row->attachments; ?>">
						<?php echo JText::_('Yes'); ?>
					</span>
				<?php else: ?>
					<?php echo JText::_('No'); ?>
				<?php endif; ?>
			</td>

	<?php 
 ?>
			
		</tr>
		<?php
			$k = 1 - $k;
		}
		?>
	</tbody>
    <tfoot>
    <tr>
      <td colspan="<?php echo $coloumnCount + 1; ?>"><?php echo $this->pagination->getListFooter(); ?></td>
    </tr>
  </tfoot>
	</table>
</div>
	<input type="hidden" name="option" value="com_contact_enhanced" />
	<input type="hidden" name="task" id="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
	<input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
	<input type="hidden" name="controller" value="messages" />
	<input type="hidden" name="view" value="messages" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
