<?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">
var xmlHttp
function getSubscriber()
{
var path = document.adminForm.pathadmin.value;
var url=path+"administrator/components/com_ccnewsletter/assets/getSubscriberStatistic.php";
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
		alert ("Your browser does not support AJAX!");
		return;
}
xmlHttp.onreadystatechange= stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
var tmpstr="";
var	tmpstr_total="";
var	tmpstr_disable="";
function stateChanged()
{
	if (xmlHttp.readyState==4)
	{
		if (xmlHttp.status == 200)
		{
			var response = xmlHttp.responseText;
			tmpstr=response;
			tmpstr_total=tmpstr.substring(0,tmpstr.indexOf(","));
			tmpstr_disable=tmpstr.substring(tmpstr.lastIndexOf(",")+1);
			tmpstr_enable=tmpstr.substring(tmpstr.indexOf(",")+1,tmpstr.lastIndexOf(","));
			document.getElementById('ajaxdisplay').innerHTML = tmpstr_total;
			document.getElementById('ajaxdisplay').style.display='block';
			document.getElementById('textdiv').style.display='none';
			fadetext();
			setTimeout('tempEnable()',2000);

		}
	}
}

hex=255 // Initial color value.
function fadetext(){
  if(hex>0)
  {
	hex-=11;
	document.getElementById("ajaxdisplay").style.color="rgb("+hex+","+hex+","+hex+")";
	setTimeout("fadetext()",20);
  }
  else
  {
	hex=255
  }
}
function fadetext1(){
  if(hex>0)
  {
	hex-=11;
	document.getElementById("textdiv").style.color="rgb("+hex+","+hex+","+hex+")";
	setTimeout("fadetext1()",20);
  }
  else
  {
	hex=255
  }
}
function tempEnable()
{
	document.getElementById('ajaxdisplay').innerHTML = tmpstr_enable;
	clearTimeout();
	fadetext();
	setTimeout('tempDisable()',2000);
}
function tempDisable()
{
	document.getElementById('ajaxdisplay').innerHTML = tmpstr_disable;
	clearTimeout();
	fadetext();
	setTimeout("lastajaxdisplay()",2000);

}
function lastajaxdisplay()
{
	document.getElementById('ajaxdisplay').style.display='none';
	document.getElementById('textdiv').style.display='block';
	clearTimeout();
	fadetext1();
}
function changeText( op1, op2 )
{
	document.getElementById('userListArea').innerHTML =	op1;
	document.getElementById('userAssined').innerHTML =	op2;
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

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

function eraseFilter()
{
	document.getElementById('filter').value = '';
	submitform();
}
</script>
<form action="index.php" method="post" name="adminForm">
		<table>
		<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>
			<td nowrap="nowrap">
				<table>
					<tr>
						<td>
				<?php
				echo JHTML::_('select.genericlist',   $this->status, 'status', 'class="inputbox" size="1" onchange="submitform( );"', 'value', 'text',$this->viewstatus);
				?>
						</td>
						<td>
							<div class="batch_export" onclick="getSubscriber()" id="textdiv">
								<a onclick="getSubscriber()" href="javascript::void(0);"  style="text-decoration: underline;"><?php echo JText::_("CC_SUBSCRIBER_STATISTIC"); ?></a>
							</div>
							<div class="batch_export" style="display:none;" id="ajaxdisplay"></div>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		</table>
	<table class="adminlist">
	<thead>
		<tr align="center">
			<th width="5">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
			</th>
			<th >
				<?php echo JHTML::_('grid.sort',  JText::_( 'CC_SUBSCRIBER_NAME' ), 's.name', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
			<th>
				<?php echo JHTML::_('grid.sort',  JText::_( 'CC_SUBSCRIBER_USERNAME' ), 's.name', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
      		<th >
				<?php echo JHTML::_('grid.sort',  JText::_( 'CC_SUBSCRIBER_EMAIL' ), 's.email', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
      		<th >
				<?php echo JHTML::_('grid.sort',  JText::_( 'CC_SUBSCRIBER_DATE' ), 's.sdate', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
      		<th >
				<?php echo JHTML::_('grid.sort',  JText::_( 'CC_ACTION' ), 's.sdate', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
			</th>
		</tr>
	</thead>
				<tfoot>
				<tr>
					<td colspan="8">
						<?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];
		$checked 	= JHTML::_('grid.id',   $i, $row->id );
		$link 		= JRoute::_( 'index.php?option=com_ccnewsletter&controller=subscriber&task=edit&cid[]='. $row->id );
		$linkdel 		= JRoute::_( 'index.php?option=com_ccnewsletter&controller=subscriber&task=deletesubscriber&id='. $row->id );
		$row->published = $row->enabled;
		$db =& JFactory::getDBO();
		$query = "SELECT  * FROM #__users WHERE email = '".$row->email."' LIMIT 1"  ;
		$db->setQuery( $query );
		$subscriberdetail = $db->loadObject();
		$published		= JHTML::_('grid.published', $row, $i );
		?>
		<tr class="<?php echo "row$k"; ?>">

			<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 if($subscriberdetail){echo
$subscriberdetail->username; }?>

			</td>
   		   <td align="center">
				<a href="<?php echo $link; ?>"><?php echo $row->email; ?></a>
			</td>
   		   <!--<td align="center">
				<?php
				 //echo $published;
				  ?>
			</td>-->
   		   <td align="center">
				<?php
					if($row->sdate != '0000-00-00 00:00:00')
						echo JHTML::_('date',  $row->sdate, JText::_('DATE_FORMAT_LC3') )	;
					else
						echo "N/A";
				?>
			</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_SUBSCRIBER_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=subscriber&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_SUBSCRIBER_MSG"); ?>"></a></div>
							<?php }else{ ?>
								<div ><a style="text-decoration:none;" href="index.php?option=com_ccnewsletter&controller=subscriber&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_SUBSCRIBER_MSG"); ?>"></a></div>
							<?php } ?>
						</td>
						<td style="border:none;" align="center">
							<div ><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_SUBSCRIBER_ALTTXT"); ?>"></a></div>
						</td>
					</tr>
				</table>
			</td>

		</tr>
		<?php
		$k = 1 - $k;
	}
	?>
	</table>
<input type="hidden" name="option" value="com_ccnewsletter" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="path" id="pathadmin" value="<?php echo JURI::root();?>" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="controller" value="subscriber" />
<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" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<p class="copyright" style="text-align:center;" >
<?php
	if (isset($this->versionContent)) {
		echo $this->versionContent;
	}
?>
</p>
<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>
