<?php
/**
 * @version		$Id: mod_communitysurvey.php 01 2011-11-08 11:37:09Z maverick $
 * @package		CoreJoomla.Surveys
 * @subpackage	Modules.site
 * @copyright	Copyright (C) 2009 - 2012 corejoomla.com, Inc. All rights reserved.
 * @author		Maverick
 * @link		http://www.corejoomla.com/
 * @license		License GNU General Public License version 2 or later
 */
//don't allow other scripts to grab and execute our file
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

defined('S_APP_NAME') or define('S_APP_NAME', 'com_communitysurveys');

// include the helper file
require_once(dirname(__FILE__).'/helper.php');
require_once(JPATH_SITE.'/components/com_communitysurveys/router.php');
require_once(JPATH_SITE.'/components/com_communitysurveys/helpers/constants.php');
require_once(JPATH_SITE.'/components/com_communitysurveys/helpers/helper.php');

// CJLib includes
$cjlib = JPATH_ROOT.'/components/com_cjlib/framework.php';

if(file_exists($cjlib)){

	require_once $cjlib;
}else{

	die('CJLib (CoreJoomla API Library) component not found. Please download and install it to continue.');
}
CJLib::import('corejoomla.framework.core');

// Get the properties
$show_latest = intval($params->get('show_latest','1'));
$show_popular = intval($params->get('show_most_popular','1'));
$show_tabs = intval($params->get('show_tabs','1'));
$tab_order = trim($params->get('tab_order', 'L,M'));

// Get the item id for community answers
$itemid = CJFunctions::get_active_menu_id(true, 'index.php?option='.S_APP_NAME.'&view=survey');
$document = JFactory::getDocument();
$document->addStyleSheet(JURI::base(true).'/modules/mod_communitysurveys/assets/communitysurveys.css');

// get the items to display from the helper
$order = explode(',', $tab_order);

if($show_tabs == 1){

	CJLib::import('corejoomla.ui.bootstrap', true);

	echo  '<div id="cj-wrapper">';
	echo  '<ul class="nav nav-tabs" data-tabs="tabs">';

	foreach ($order as $i=>$tab){

		if((strcmp($tab, "L") == 0) && $show_latest){
			
			echo '<li'.($i == 0 ? ' class="active"' : '').'><a href="#cstab-1" data-toggle="tab">'.JText::_('LBL_LATEST_SURVEYS').'</a></li>';
		}

		if((strcmp($tab, 'M') == 0) && $show_popular){
			
			echo '<li'.($i == 0 ? ' class="active"' : '').'><a href="#cstab-2" data-toggle="tab">'.JText::_('LBL_MOST_POPULAR_SURVEYS').'</a></li>';
		}
	}

	echo '</ul>';

	foreach ($order as $i=>$tab){

		if((strcmp($tab,'L') == 0) && $show_latest){
				
			$latest_surveys = modCommunitySurveysHelper::getLatestSurveys($params);
				
			echo '<div id="cstab-1" class="tab-pane fade'.($i == 0 ? ' in active' : '').'">';
			require(JModuleHelper::getLayoutPath('mod_communitysurveys','latest_surveys'));
			echo '</div>';
		}

		if((strcmp($tab,'M') == 0) && $show_popular){
				
			$popular_surveys = modCommunitySurveysHelper::getMostPopularSurveys($params);
				
			echo '<div id="cstab-2" class="tab-pane fade'.($i == 0 ? ' in active' : '').'">';
			require(JModuleHelper::getLayoutPath('mod_communitysurveys','most_popular'));
			echo '</div>';
		}
	}

	echo '</div>';
}else{

	foreach ($order as $tab){

		if((strcmp($tab,'L') == 0) && $show_latest){
				
			$latest_surveys = modCommunitySurveysHelper::getLatestSurveys($params);
			require(JModuleHelper::getLayoutPath('mod_communitysurveys','latest_surveys'));
		}

		if((strcmp($tab,'M') == 0) && $show_popular){
				
			$popular_surveys = modCommunitySurveysHelper::getMostPopularSurveys($params);
			require(JModuleHelper::getLayoutPath('mod_communitysurveys','most_popular'));
		}
	}
}
?>
