<?php 
  
 /**
 * @package Form Maker
 * @author Web-Dorado
 * @copyright (C) 2011 Web-Dorado. All rights reserved.
 * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 **/

defined('_JEXEC') or die('Restricted access'); 
jimport( 'joomla.application.component.model' );
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
class formmakerModelstats extends JModelLegacy
{	
	function show_stats()
	{
		$input_get 	= JFactory::getApplication()->input;
		$db			= JFactory::getDBO();
		
		$form_id 	= $db->escape((int) $input_get->getString('form_id'));
		$id 		= $db->escape((int)$input_get->getString('id'));
		$from 		= $db->escape($input_get->getString('from'));
		$to 		= $db->escape($input_get->getString('to'));
		
		$where=' AND form_id='.$form_id;
		
		if($from!='')
			$where.=" AND `date`>='".$from." 00:00:00' ";
		if($to!='')
			$where.=" AND `date`<='".$to." 23:59:59' ";

		$query = "SELECT element_value FROM #__formmaker_submits WHERE element_label='".$id."'".$where;
		$db->setQuery( $query);
		$choices = $db->loadObjectList();

		if($db->getErrorNum()){
			echo $db->stderr();
			return false;}

		return array($choices);
	}

}
	?>
