<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: view.html.php 2009-04-28 01:47:12 svn $
 * @author Christopher Mavros
 * @package Joomla
 * @subpackage NS Pro
 * @license GNU/GPL
 *
 * Pro Version of Newsletter Subscriber.
Provides:
Keep subscriptions in database
Unsubscription Page
Optional Confirmation on subscribe/unsubscribe
Subscription Manager
Send Newsletters
Newsletter Manager
Subscription Statistics
Unique Emails (does not allow duplicates)
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class NsproViewSubscribers extends JView {

    function display($tpl = null)
    {

        global $mainframe, $option;
        $model      =& $this->getModel();
        $limit      = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
        $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );

        JToolBarHelper::title(   JText::_( 'NS Pro Manager' ), 'generic.png' );
        JToolBarHelper::customX('resendconfirm', 'forward.png', 'forward.png', 'Re-Send Confirmation', true, true);
        JToolBarHelper::deleteList();
        JToolBarHelper::editListX();
        JToolBarHelper::addNewX();
        JToolBarHelper::preferences('com_nspro', 400);
        
        $filter_subs = 0;
        if ($_POST) {
          if ($_POST['select_list']) {
            $filter_subs = $_POST['select_list'];
          }
        }        

        jimport('joomla.html.pagination');
        $total = $model->getSubsCount();

        $pagination = new JPagination( $total, $limitstart, $limit );

        $this->assignRef('pagination',  $pagination);

        $subs = $model->getSubs($limit, $limitstart);
        
        if ($filter_subs == -1) {
          for($k = 0, $n=count( $subs ); $k < $n; $k++) {
            if ($subs[$k]->mailing_lists != '') {
              unset($subs[$k]);
            }
          }
          $subs = array_values($subs);
        }        
        if ($filter_subs > 0) {
          for($k = 0, $n=count( $subs ); $k < $n; $k++) {
            $mySubLists = explode(',', $subs[$k]->mailing_lists);
            $found = false;
            foreach ($mySubLists as $myList) {
              if ($myList == $filter_subs) {
                $found = true;
                break;
              }
            }    
            if (!$found) {
              unset($subs[$k]);
            }
          } 
          $subs = array_values($subs);
        }
        

        $this->assignRef('subs', $subs);

        $allSubs = $model->getAllSubs();

        $this->assignRef('allSubs', $allSubs);       
        
        $this->assignRef('filter_subs', $filter_subs);

        parent::display($tpl);
    }
}
?>