<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: nspro.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.model');

class NsproModelNspro extends JModel {

    function __construct()
    {
        parent::__construct();

        $array = JRequest::getVar('cid',  0, '', 'array');
        $this->setId((int)$array[0]);
    }

    /**
     * Method to set the nssubs identifier
     *
     * @access  public
     * @param   int NsSubs identifier
     * @return  void
     */
    function setId($id)
    {
        // Set id and wipe data
        $this->_id      = $id;
        $this->_data    = null;
    }

    function getSub()
    {
        $db =& JFactory::getDBO();
        // Load the data
        if (empty( $this->_data )) {
            $query = ' SELECT * FROM #__nspro_subs '.
                    '  WHERE id = '.$this->_id;
            $db->setQuery( $query );
            $this->_data = $db->loadObject();
        }
        if (!$this->_data) {
            $this->_data = new stdClass();
            $this->_data->id = 0;
            $this->_data->name  = null;
            $this->_data->email = null;
            $this->_data->notes = null;
            $this->_data->datetime = null;
            $this->_data->confirmed = false;
            $this->_data->mailing_lists = null;            
        }
        return $this->_data;
    }

    function getSubs($limit, $limitstart) {
        $db =& JFactory::getDBO();

        $query = 'SELECT * FROM #__nspro_subs';

        $subs = $this->_getList( $query , $limitstart, $limit);

        return $subs;
    }

    function getSubsCount() {
        $db =& JFactory::getDBO();

        $query = 'SELECT COUNT(*) FROM #__nspro_subs';

        $db->setQuery( $query );
        $sCount = $db->loadResult();

        return $sCount;
    }
}
?>