<?php
/**
 * goal_factory.php - GOAL  factory.
 *
 * @author $Author: dtong $
 * @version $Id: goal_factory.php,v 1.2 2010/08/16 11:24:08 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class goal_factory {
	//Gets config in the following order:
	//	function param, cms_adminmenu_template, cms_unit_org, am_default.php
   public static function factory($template=FALSE) {
   	if ( $template !== FALSE ) {
   		//Always use the one from function parameter if it exists
	   	if ( @include_once CMS_TEMPLATEPATH_GOAL . 'goal_' . $template . '.php') {
				return goal_config_data::get();
			}
   	}
   	$CI =& get_instance();
   	if ( ($template = $CI->config->item('cms_adminmenu_template')) !== FALSE ) {
   		//See if cms_adminmenu_template is defined
	   	if ( @include_once CMS_TEMPLATEPATH_GOAL . 'goal_' . $template . '.php') {
				return goal_config_data::get();
			}
   	}
   	if ( ($template = $CI->config->item('cms_unit_org')) !== FALSE ) {
   		//Use the main config if exists
	   	if ( @include_once CMS_TEMPLATEPATH_GOAL . 'goal_' . $template . '.php') {
				return goal_config_data::get();
			}
   	}
   	//Everything fails so use the default
		if ( include_once CMS_TEMPLATEPATH_GOAL . 'goal_ISB.php') {
			return goal_config_data::get();
		}
			return FALSE;
   }
}
?>