<?php
/**
* @package ccNewsletter
* @version 1.0.9
* @author  Chill Creations <info@chillcreations.com>
* @link    http://www.chillcreations.com
* @copyright Copyright (C) 2008 - 2010 Chill Creations-All rights reserved
* @license GNU/GPL, see LICENSE.php for full license.
* See COPYRIGHT.php for more copyright notices and details.

This file is part of ccNewsletter.
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
of the License.

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.
**/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
?>
<script language="javascript">
function confirmationdel()
{
	if(confirm('<?php echo JText::_( 'CC_WARN_DELETE_NEWSLETTERS');?>'))
	{
		return true;
	}
	return false;
}
function submitbutton(pressbutton)
  {
     var form = document.adminForm;
      if(pressbutton == 'ccsendtesting')
      {
			if(form.boxchecked.value=='0')
			{
				alert('<?php echo JText::_( 'CC_SELECT_NEWSLETTER');?>');
			}
			else if((form.testEmail.value==""))
			{
				alert( "<?php echo JText::_( 'CC_SET_PARAMETER'); ?>" );
			}
			else
			{
				  submitform(pressbutton);
			}
      }
      else if(pressbutton == 'ccsend')
      {
			if(form.boxchecked.value=='0')
			{
				alert('<?php echo JText::_( 'CC_SELECT_NEWSLETTER');?>');
			}
			else if((form.emailbatch.value=="") || (form.batchinter.value=="") || (form.scripttimeout.value==""))
			{
				alert( "<?php echo JText::_( 'CC_SET_PARAMETER'); ?>" );
			}
			else
			{
				  submitform(pressbutton);
			}
      }
      else
      {
            submitform(pressbutton);
      }
 }

function createFilter(filter)
{
	document.getElementById('filter').value = filter;
	submitform();
}

function eraseFilter()
{
	document.getElementById('filter').value = '';
	submitform();
}
Joomla.submitbutton = function(task)
{
	var form = document.adminForm;
	if(task=="ccsendtesting" || task=="ccsend")
	{
	if(form.boxchecked.value=="0")
	{
		alert('<?php echo JText::_( 'CC_SELECT_NEWSLETTER');?>');
	}
	else if((form.emailbatch.value=="") || (form.batchinter.value=="") || (form.scripttimeout.value=="") || (form.testEmail.value==""))
	{
		alert( "<?php echo JText::_( 'CC_SET_PARAMETER'); ?>" );
	}
	else
	{
		Joomla.submitform(task);
		return true;
	}
}
	else
	{
			Joomla.submitform(task);
			return true;
	}
}
</script>
<?php
$params = array('size'=>array('x'=>100, 'y'=>100));
JHTML::_('behavior.modal', 'a.modal', $params);
?>
<form action="index.php" method="post" name="adminForm" id="adminForm" >
	<table width="100%">
	<tr>
		<td align="left" width="100%">
			<?php echo JText::_( 'Filter' ); ?>:
			<input type="text" name="newsletter_filter" id="newsletter_filter" onchange="createFilter(document.getElementById('newsletter_filter').value);" class="text_area" value="<?php echo $this->lists['search'];?>"/>
			<input type="button" value="<?php echo JText::_('Go'); ?>" onclick="createFilter(document.getElementById('newsletter_filter').value);return false;" />
			<input type="button" onclick="eraseFilter();" value="<?php echo JText::_('Filter Reset'); ?> " />
		</td>
	</tr>
	</table>

	<table width="100%">
	<tr>
	<td width="35%"  style="vertical-align:top;">
		<table class="adminlist" width="100%" >
	<thead>
		<tr>
			<th width="5">
				<?php echo JText::_( 'CC_ID' ); ?>
			</th>
			<th width="20">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
			<th>
			<?php echo JHTML::_('grid.sort',  JText::_( 'CC_NEWSLETTER_NAME' ), 'n.name', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
			<th>
			<?php echo JHTML::_('grid.sort',  JText::_( 'CC_NEWSLETTER_LAST_SENT_DATE' ), 'n.lastsentdate', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
			<th>
			<?php echo JHTML::_('grid.sort',  JText::_( 'CC_NEWSLETTER_TOTAL_SUBSCRIBER' ), 'n.totalsubscriber', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
			<th>
			<a href="#"><?php echo JText::_( 'CC_ACTION' ); ?></a>
			</th>
		</tr>
	</thead>
	<tfoot>
		<tr>
			<td colspan="6">
				<?php echo $this->pageNav->getListFooter(); ?>
			</td>
		</tr>
	</tfoot>
	<?php
	$k = 0;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)
	{
		$row = &$this->items[$i];
		if($row->lastsentdate =='0000-00-00' || $row->lastsentdate == '')
		{
			$datevalue='';
		} else if($row->lastsentdate != '0000-00-00')
		{
			$datevalue=strftime($this->date_format, strtotime($row->lastsentdate));
		}
		$checked 	= JHTML::_('grid.id',   $i, $row->id );
		$link 		= JRoute::_( 'index.php?option=com_ccnewsletter&controller=newsletter&task=edit&cid[]='. $row->id );
		$linkdel 		= JRoute::_( 'index.php?option=com_ccnewsletter&controller=newsletter&task=deletesubscriber&id='. $row->id );
			$row->published = $row->enabled;
			$published		= JHTML::_('grid.published', $row, $i );

			$latestNewsletter = $this->latestNewsletter->id;
			if($row->id)
			{
				$newsletterid= $row->id;
			}
			else
			{
				$newsletterid = $latestNewsletter;
			}
                        ?>
		<tr class="<?php echo "row$k"; ?>">
			<td align="center">
					<?php echo $this->pageNav->getRowOffset( $i ); ?>
			</td>
			<td align="center">
				<?php echo $checked; ?>
			</td>
			<td align="center">
					<a href="<?php echo $link; ?>"><?php echo $row->name; ?></a>
				</td>
				<td align="center">
						<?php echo $datevalue; ?>
				</td>
				<td align="center">
						<?php echo $row->totalsubscriber; ?>
				</td>
				<td align="center">
					<table>
						<tr>
							<td style="border:none;" align="center">
								<div ><a style="text-decoration:none;" href="<?php echo $link; ?>"><img src="<?php echo JURI::base();?>/components/com_ccnewsletter/assets/edit.png" title="<?php echo JText::_("CC_EDIT_NEWSLETTER_ALTTXT"); ?>"></a></div>
							</td>
							<td style="border:none;" align="center">
								<?php if($row->enabled=="1"){ ?>
									<div ><a style="text-decoration:none;" href="index.php?option=com_ccnewsletter&controller=newsletter&task=desableenable&id=<?php echo $row->id; ?>"><img src="<?php echo JURI::base();?>/components/com_ccnewsletter/assets/subscriber_enabled.png" title="<?php echo JText::_("CC_ENABLE_NEWSLETTER_MSG"); ?>"></a></div>
								<?php }else{ ?>
									<div ><a style="text-decoration:none;" href="index.php?option=com_ccnewsletter&controller=newsletter&task=desableenable&status=1&id=<?php echo $row->id; ?>"><img src="<?php echo JURI::base();?>/components/com_ccnewsletter/assets/subscriber_disabled.png" title="<?php echo JText::_("CC_DISABLE_NEWSLETTER_MSG"); ?>"></a></div>
								<?php } ?>
							</td>
							<td style="border:none;" align="center">
								<div ><a  style="text-decoration:none;" class="modal"  rel="{handler: 'iframe', size: {x: 900, y: 500}}"  href="index.php?option=com_ccnewsletter&controller=newsletter&task=ajaxpreview&id=<?php echo $row->id; ?>"><img src="<?php echo JURI::base();?>/components/com_ccnewsletter/assets/view.png" title="<?php echo JText::_("CC_PREVIEW_NEWSLETTER_ALTTXT"); ?>"></a></div>
							</td>
							<td style="border:none;" align="center">
								<div onclick="return confirmationdel()"><a style="text-decoration:none;" href="<?php echo $linkdel; ?>"><img src="<?php echo JURI::base();?>/components/com_ccnewsletter/assets/delete.png" title="<?php echo JText::_("CC_REMOVE_NEWSLETTER_ALTTXT"); ?>"></a></div>
							</td>
						</tr>
					</table>
				</td>
		</tr>
		<?php
		$k = 1 - $k;
	}
	?>
	</table>
	</td>
	</tr>
</table>
<input type="hidden" name="option" value="com_ccnewsletter" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="newsletter" />
<input type="hidden" name="path" id="path" value="<?php echo JURI::base();?>" />
<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="newsletter_filter" value="" id="filter" />

<input type="hidden" name="emailbatch" id="emailbatch" value="<?php echo $this->emailbatch ?>" />
<input type="hidden" name="batchinter" id="batchinter" value="<?php echo $this->batchinter ?>" />
<input type="hidden" name="scripttimeout" id="scripttimeout" value="<?php echo $this->scripttimeout ?>" />
<input type="hidden" name="testEmail" value="<?php echo $this->testEmail;?>" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<br/>
<p class="copyright" style="text-align:center;" >
<?php echo $this->name; ?>&nbsp;<?php echo $this->version; ?>. Copyright (C) 2006 - <?php echo $curYear = date('Y'); ?>  Chill Creations<br/>Joomla! component by <a href="http://www.chillcreations.com" target="_blank">Chill Creations</a>
</p>
