<?php
/*
	osCommerce, Open Source E-Commerce Solutions
	http://www.oscommerce.com
	
	Copyright (c) 2003 osCommerce
	
	osCommRes, Services Oline
	http://www.oscommres.com
	Copyright (c) 2005 osCommRes
	
	Freeway eCommerce
	http://www.zac-ware.com/freeway
	Copyright (c) 2007 ZacWare
	
	Released under the GNU General Public License
*/


// Set flag that this is a parent file
define( '_FEXEC', 1 );

  require('includes/application_top.php');  
 
 if ($GLOBALS["SEO_URL"]->enabled){
  if (isset($HTTP_GET_VARS['products_id'])){
	  require FILENAME_PRODUCT_INFO;
	  return;
  } else if (isset($HTTP_GET_VARS['events_id'])){
  	require FILENAME_SESSION_DETAILS;
	return;
  } else if (isset($HTTP_GET_VARS['subscription_id'])){
  	require FILENAME_SUBSCRIPTION_INFO;
	return;
  } else if (isset($HTTP_GET_VARS['service_id'])){
  	require FILENAME_SERVICES_INFO;
	return;
  }
  if (isset($HTTP_GET_VARS['ecPath'])){  
	if (strtolower(EVENTS_VIEW_STYLE)=="calendar") {
		$navi_view=(isset($HTTP_GET_VARS["set_view"])?strtolower(tep_db_prepare_input($HTTP_GET_VARS["set_view"])):strtolower(EVENTS_CALENDAR_STYLE));
		if ($navi_view=="month"){
			require FILENAME_EVENTS_MONTH_VIEW;
			return;
		} else if ($navi_view=="week"){
			require FILENAME_EVENTS_WEEK_VIEW;
			return;
		} else {
			require FILENAME_EVENTS_DAY_VIEW;
			return;
		}
	} else if (strtolower(EVENTS_VIEW_STYLE)=="view1") {
		require FILENAME_EVENTS_VIEW1;
		return;
	} else if(strtolower(EVENTS_VIEW_STYLE)=="view2") {
		require FILENAME_EVENTS_VIEW2;
		return;
	} else if(strtolower(EVENTS_VIEW_STYLE)=="view3") {
		require FILENAME_EVENTS_VIEW1;
		return;
	}
}
}
// the following cPath references come from application_top.php
  $category_depth = 'top';
  if (isset($cPath) && tep_not_null($cPath)) {  
    $categories_products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_TO_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
    $cateqories_products = tep_db_fetch_array($categories_products_query);
    if ($cateqories_products['total'] > 0) { 
      $category_depth = 'products'; // display products
    } else { 
      $category_parent_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$current_category_id . "'");
	  $category_parent = tep_db_fetch_array($category_parent_query);
      if ($category_parent['total'] > 0) {
        $category_depth = 'nested'; // navigate through the categories
      } else {
        $category_depth = 'products'; // category has no products, but display the 'no products' message
      }
    }
  }
  $events_category_depth = 'top';
  if (isset($ecPath) && tep_not_null($ecPath)) {
    $events_categories_events_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " where events_categories_id = '" . (int)$current_events_category_id . "'");
    $events_categories_events = tep_db_fetch_array($events_categories_events_query);
    if ($events_categories_events['total'] > 0) {
      $events_category_depth = 'events'; // display events
    } else {
      $events_category_parent_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_CATEGORIES . " where parent_id = '" . (int)$current_events_category_id . "'");
      $events_category_parent = tep_db_fetch_array($events_category_parent_query);
      if ($events_category_parent['total'] > 0) {
        $events_category_depth = 'nested'; // navigate through the categories
      } else {
        $events_category_depth = 'events'; // category has no events, but display the 'no events' message
      }
    }
  }
  $subscription_category_depth = 'top';
  if (isset($sucPath) && tep_not_null($sucPath)) {
    $subscription_categories_subscription_query = tep_db_query("select count(*) as total from " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " where subscription_categories_id = '" . (int)$current_subscription_category_id . "'");
    $subscription_categories_subscription = tep_db_fetch_array($subscription_categories_subscription_query);
    if ($subscription_categories_subscription['total'] > 0) {
      $subscription_category_depth = 'subscription'; // display subscriptions
	} else {
      $subscription_category_parent_query = tep_db_query("select count(*) as total from " . TABLE_SUBSCRIPTION_CATEGORIES . " where parent_id = '" . (int)$current_subscription_category_id . "'");
      $subscription_category_parent = tep_db_fetch_array($subscription_category_parent_query);
      if ($subscription_category_parent['total'] > 0) {
        $subscription_category_depth = 'nested'; // navigate through the categories
      } else {
        $subscription_category_depth = 'subscription'; // category has no events, but display the 'no events' message
      }
    }
  }
  
  
  $static_category_depth='top';
  if(isset($stcPath) && tep_not_null($stcPath)){
   $static_categories_static_query = tep_db_query("select count(*) as total from " . TABLE_MAINPAGE . " where parent_id = '" . (int)$current_static_category_id . "'");
    $static_categories_static = tep_db_fetch_array($static_categories_static_query);
    if ($static_categories_static['total'] > 0) {
      $static_category_depth = 'static'; // display static
	} else {
	
	
      $static_category_parent_query = tep_db_query("select * from " . TABLE_MAINPAGE . " where parent_id = '" . (int)$current_static_category_id . "'");
      $static_category_parent = tep_db_fetch_array($static_category_parent_query);
   
        $static_category_depth = 'nested'; // navigate through the categories
    
    }
	}
  
  $services_category_depth = 'top';
  if (isset($secPath) && tep_not_null($secPath)) {
    $services_categories_services_query = tep_db_query("select count(*) as total from " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " where services_categories_id = '" . (int)$current_services_category_id . "'");
    $services_categories_services = tep_db_fetch_array($services_categories_services_query);
    if ($services_categories_services['total'] > 0) {
      $services_category_depth = 'services'; // display services
	} else {
      $services_category_parent_query = tep_db_query("select count(*) as total from " . TABLE_SERVICES_CATEGORIES . " where parent_id = '" . (int)$current_services_category_id . "'");
      $services_category_parent = tep_db_fetch_array($services_category_parent_query);
      if ($services_category_parent['total'] > 0) {
        $services_category_depth = 'nested'; // navigate through the categories
      } else {
        $services_category_depth = 'services'; // category has no services, but display the 'no services' message
      }
    }
  }

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFAULT);
  
  if ($category_depth == 'nested') {
//Code change for Categories Description 1.5
//    $category_query = tep_db_query("select cd.categories_name, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
//Changed to the following
    $category_query = tep_db_query("select cd.categories_name, cd.categories_heading_title, cd.categories_description, c.categories_image from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . tep_db_input($current_category_id) . "' and cd.categories_id = '" . tep_db_input($current_category_id) . "' and cd.language_id = '" . tep_db_input($languages_id) . "'");
	
//End Categories Description 1.5

    $category = tep_db_fetch_array($category_query);
	
    $content = CONTENT_INDEX_NESTED;

  } elseif ($category_depth == 'products' || isset($HTTP_GET_VARS['manufacturers_id'])) {
// create column list
    $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL,
                         'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME,
                         'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER,
                         'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE,
                         'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY,
                         'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT,
                         'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE,
                         'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW,
						 'PRODUCT_LIST_DESCRIPTION'=>6
						 );
        
    asort($define_list);

    $column_list = array();
    reset($define_list);
    while (list($key, $value) = each($define_list)) {
      if ($value > 0) $column_list[] = $key;
    }

    $select_column_list = '';
    for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
      switch ($column_list[$i]) {
        case 'PRODUCT_LIST_MODEL':
          $select_column_list .= 'p.products_model, ';
          break;
        case 'PRODUCT_LIST_NAME':
          $select_column_list .= 'pd.products_name, ';
          break;
        case 'PRODUCT_LIST_MANUFACTURER':
          $select_column_list .= 'm.manufacturers_name, ';
          break;
        case 'PRODUCT_LIST_QUANTITY':
          $select_column_list .= 'p.products_quantity, ';
          break;
        case 'PRODUCT_LIST_IMAGE':
          $select_column_list .= 'p.products_image_1,p.products_title_1, ';
          break;
        case 'PRODUCT_LIST_WEIGHT':
          $select_column_list .= 'p.products_weight, ';
          break;
        case 'PRODUCT_LIST_DESCRIPTION':
          $select_column_list .= 'pd.products_description, ';
          break;

      }
    }
	// cgdis start
 // Get the category name and description
   $customer_group_id=0;
   $check_restrict_customer="";
   if($customer_id>0) $customer_group_id=get_customer_group_id();
   $check_restrict_customer=" and ((p.restrict_to_customers='' OR ISNULL(p.restrict_to_customers)) AND (p.restrict_to_groups='' OR ISNULL(p.restrict_to_groups)))";     
   if($customer_id>0 ) $check_restrict_customer=substr($check_restrict_customer,0,-1)." OR (p.restrict_to_customers like '%".tep_db_input($customer_id)."%' OR p.restrict_to_groups like '%".tep_db_input($customer_group_id)."%'))";
// show the products of a specified manufacturer
    if (isset($HTTP_GET_VARS['manufacturers_id'])) {
      if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only a specific category
		$listing_sql="select " . $select_column_list . " date_format(p.products_date_available,'%Y-%m-%d') as products_date_available, p.products_id, p.manufacturers_id, p.products_price,p.products_status, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_date_available<='" . getServerDate() . "'".tep_db_input($check_restrict_customer);     
	  } else {
// We show them all
		$listing_sql="select " . $select_column_list . " date_format(p.products_date_available,'%Y-%m-%d') as products_date_available, p.products_id, p.manufacturers_id, p.products_price,p.products_status, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' and p.products_date_available<='" . getServerDate() . "'".tep_db_input($check_restrict_customer);
	  }
    } else {
// show the products in a given categorie
      if (isset($HTTP_GET_VARS['filter_id']) && tep_not_null($HTTP_GET_VARS['filter_id'])) {
// We are asked to show only specific catgeory
      	$listing_sql = "select " . $select_column_list . " date_format(p.products_date_available,'%Y-%m-%d') as products_date_available, p.products_id, p.manufacturers_id, p.products_price,p.products_status, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['filter_id'] . "' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "' and p.products_date_available<='" . getServerDate() . "'".tep_db_input($check_restrict_customer);
	  } else {
// We show them all
      	$listing_sql = "select " . $select_column_list . " date_format(p.products_date_available,'%Y-%m-%d') as products_date_available, p.products_id, p.manufacturers_id, p.products_price,p.products_status, p.products_tax_class_id from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, "  . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "' and p.products_date_available<='" . getServerDate() . "'".$check_restrict_customer;
		}
    }
	
	//echo $listing_sql;
//CGDiscountSpecials end

    if ( (!isset($HTTP_GET_VARS['sort'])) || (!ereg('[1-8][ad]', $HTTP_GET_VARS['sort'])) || (substr($HTTP_GET_VARS['sort'], 0, 1) > sizeof($column_list)) ) {
      for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
        if ($column_list[$i] == 'PRODUCT_LIST_NAME') {
          $HTTP_GET_VARS['sort'] = $i+1 . 'a';
          $listing_sql .= " order by p.products_sort_order";
          break;
        }
      }
    } else {

      $sort_col = substr(tep_db_prepare_input($HTTP_GET_VARS['sort']), 0 , 1);
      $sort_order = substr(tep_db_prepare_input($HTTP_GET_VARS['sort']), 1);
      $listing_sql .= ' order by ';
      switch ($column_list[$sort_col-1]) {
        case 'PRODUCT_LIST_MODEL':
          $listing_sql .= "p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
        case 'PRODUCT_LIST_NAME':
          //$listing_sql .= "pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
          $listing_sql .= "p.products_sort_order " . ($sort_order == 'd' ? 'desc' : '');
          break;
        case 'PRODUCT_LIST_MANUFACTURER':
          $listing_sql .= "m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
        case 'PRODUCT_LIST_QUANTITY':
          $listing_sql .= "p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
        case 'PRODUCT_LIST_IMAGE':
          $listing_sql .= "pd.products_name";
          break;
        case 'PRODUCT_LIST_WEIGHT':
          $listing_sql .= "p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
        case 'PRODUCT_LIST_DESCRIPTION':
          $listing_sql .= "pd.products_description " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
		 //cgdis start
        case 'PRODUCT_LIST_PRICE':
          $listing_sql .= "p.products_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
          break;
		//cgdis end
      }
    }
		$temp_listing_sql=$listing_sql;
		$temp_listing_query=tep_db_query($temp_listing_sql);
		if(tep_db_num_rows($temp_listing_query)==1) {
			$temp_listing_result=tep_db_fetch_array($temp_listing_query);
			tep_redirect(tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $temp_listing_result['products_id']));
		}


    $content = CONTENT_INDEX_PRODUCTS;
  
  } 
  else { // default page
    $content = CONTENT_INDEX_DEFAULT;
  }
  
//for events added 

	if ($events_category_depth == 'nested') {
		$events_category_query = tep_db_query("SELECT ecd.events_categories_name, ecd.events_categories_heading_title, ecd.events_categories_description, ec.events_categories_image from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.events_categories_id=ecd.events_categories_id and ec.events_categories_id = '" . tep_db_input($current_events_category_id) . "' and ecd.language_id = '" . tep_db_input($languages_id) . "'");
	
	
		$events_category = tep_db_fetch_array($events_category_query);
	
		$content = CONTENT_INDEX_EVENTS_NESTED;
	
	} elseif ($events_category_depth == 'events') {

	    $define_events_list = array(	'EVENT_LIST_IMAGE' => EVENT_LIST_IMAGE,
    								 	'EVENT_LIST_NAME' => EVENT_LIST_NAME,
										'EVENT_LIST_FEES'=>EVENT_LIST_FEES,
										'EVENT_LIST_MAX_REGT' => EVENT_LIST_MAX_REGT,
										'EVENT_LIST_MAX_RES' => EVENT_LIST_MAX_RES,
										'EVENT_LIST_SESSIONS' => EVENT_LIST_SESSIONS,
										'EVENT_LIST_DESCRIPTION' => EVENT_LIST_DESCRIPTION
										);


		$column_events_list = array();
		reset($define_events_list);
		while (list($events_key, $events_value) = each($define_events_list)) {
			if ($events_value > 0) $t=10;$column_events_list[] = $events_key;
		}

		$select_events_column_list = '';
		
		for ($i=0, $n=sizeof($column_events_list); $i<$n; $i++) {
			switch ($column_events_list[$i]) {
				case 'EVENT_LIST_NAME':
					$select_events_column_list .= 'ed.events_name, ';
					break;
				case 'EVENT_LIST_FEES':
					$select_events_column_list .= 'e.events_fees, ';
					break;
				case 'EVENT_LIST_IMAGE':
					$select_events_column_list .= 'e.events_image, ';
					break;
				case 'EVENT_LIST_MAX_RES':
					$select_events_column_list .= 'e.events_max_reserve, ';
					break;
				case 'EVENT_LIST_DESCRIPTION':
					$select_events_column_list .= 'ed.events_description, ';
					break;
			}
		}
		if (tep_not_null($current_events_category_id)) {
			$listing_sql = "SELECT " . $select_events_column_list . " e.events_id,e.events_tax_class_id from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_DESCRIPTION . " ed, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c where e.events_status = '1' and e.events_id = e2c.events_id and ed.events_id = e2c.events_id and ed.language_id = '" . (int)$languages_id . "' " . EVENTS_CONDITION_STATUS . " and e2c.events_categories_id = '" . (int)$current_events_category_id . "'";
		} else {
			$listing_sql = "SELECT " . $select_events_column_list . " e.events_id,e.events_tax_class_id from " . TABLE_EVENTS . " e," . TABLE_EVENTS_DESCRIPTION . " ed where ed.events_id = e.events_id and ed.language_id = '" . (int)$languages_id . "' " . EVENTS_CONDITION_STATUS;      
		}
	 // Get the events_category name and description
		$events_category_query = tep_db_query("select ecd.events_categories_name, ecd.events_categories_heading_title, ecd.events_categories_description, ec.events_categories_image from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.events_categories_id = '" . tep_db_input($current_events_category_id) . "' and ecd.events_categories_id = '" . tep_db_input($current_events_category_id) . "' and ecd.language_id = '" . tep_db_input($languages_id) . "'");
		$events_category = tep_db_fetch_array($events_category_query);

		$listing_sql .= ' order by events_sort_order ';
		
		$temp_listing_sql=$listing_sql;
		$temp_listing_query=tep_db_query($temp_listing_sql);
		if(tep_db_num_rows($temp_listing_query)==1) {
			$temp_listing_result=tep_db_fetch_array($temp_listing_query);
			tep_redirect(tep_href_link(FILENAME_SESSION_DETAILS, ($ecPath ? 'ecPath=' . $ecPath . '&' : '') . 'events_id=' . tep_db_input($temp_listing_result['events_id'])));
		}
		
		$content = CONTENT_INDEX_EVENTS;
	} 


	if ($subscription_category_depth == 'nested') {
		$subs_category_sql = "SELECT sucd.subscription_categories_name, sucd.subscription_categories_heading_title, sucd.subscription_categories_description, suc.subscription_categories_image from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id=sucd.subscription_categories_id and suc.subscription_categories_id = '" . tep_db_input($current_subscription_category_id) . "' and sucd.language_id = '" . tep_db_input($languages_id) . "'";
	    $subs_category_query = tep_db_query($subs_category_sql);
    	$subs_category = tep_db_fetch_array($subs_category_query);

	    $content = CONTENT_INDEX_SUBSCRIPTIONS_NESTED;

  	} else if ($subscription_category_depth=="subscription") {

		$define_subscription_list = array(	'SUBSCRIPTION_LIST_IMAGE' => SUBSCRIPTION_LIST_IMAGE,
											'SUBSCRIPTION_LIST_NAME' => SUBSCRIPTION_LIST_NAME,
											'SUBSCRIPTION_LIST_COSTS'=>SUBSCRIPTION_LIST_COSTS,
											'SUBSCRIPTION_LIST_PERIOD' => SUBSCRIPTION_LIST_PERIOD,
											'SUBSCRIPTION_LIST_BUY_NOW' => SUBSCRIPTION_LIST_BUY_NOW);

    
		$column_subscription_list = array();

		reset($define_subscription_list);
		while (list($subscription_key, $subscription_value) = each($define_subscription_list)) {
			if ($subscription_value > 0) $t=10;$column_subscription_list[] = $subscription_key;
		}

		$select_subscription_column_list = '';
		for ($i=0, $n=sizeof($column_subscription_list); $i<$n; $i++) {
			switch ($column_subscription_list[$i]) {
				case 'SUBSCRIPTION_LIST_NAME':
					$select_subscription_column_list .= 'sud.subscription_name, ';
					break;
				case 'SUBSCRIPTION_LIST_COSTS':
					$select_subscription_column_list .= 'su.subscription_costs, ';
					break;
				case 'SUBSCRIPTION_LIST_IMAGE':
					$select_subscription_column_list .= 'su.subscription_image, ';
					break;
				case 'SUBSCRIPTION_LIST_PERIOD':
					$select_subscription_column_list .= 'su.subscription_period, ';
					break;
			}
		}
		//Support Pack
		if (tep_not_null($current_subscription_category_id)) {
			$listing_sql = "SELECT  " . $select_subscription_column_list . "subscription_tax_class_id,su.subscription_id,sud.subscription_description from " . TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud, " . TABLE_SUBSCRIPTION_TO_SUBSCRIPTION_CATEGORIES . " su2c where su.subscription_id = su2c.subscription_id and sud.subscription_id = su2c.subscription_id and su.subscription_type!='P' and su.subscription_type!='M' and sud.language_id = '" . (int)$languages_id . "' and su2c.subscription_categories_id = '" . (int)$current_subscription_category_id . "' " .  SUBSCRIPTION_CONDITION_STATUS;
		} else {
		 	$listing_sql = "SELECT " . $select_subscription_column_list . "subscription_tax_class_id,su.subscription_id,sud.subscription_description from " . TABLE_SUBSCRIPTIONS . " su," . TABLE_SUBSCRIPTIONS_DESCRIPTION . " sud where sud.subscription_id = su.subscription_id and su.subscription_type!='P' and su.subscription_type!='M' and sud.language_id = '" . (int)$languages_id . "' " . SUBSCRIPTION_CONDITION_STATUS;
		}

		// Get the events_category name and description
		$subscription_category_query = tep_db_query("select sucd.subscription_categories_name, sucd.subscription_categories_heading_title, sucd.subscription_categories_description, suc.subscription_categories_image from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = '" . tep_db_input($current_subscription_category_id) . "' and sucd.subscription_categories_id = '" . tep_db_input($current_subscription_category_id) . "' and sucd.language_id = '" . tep_db_input($languages_id) . "'");
		$subscription_category = tep_db_fetch_array($subscription_category_query);
		
		$listing_sql .= ' order by subscriptions_sort_order ';
		
		$temp_listing_sql=$listing_sql;
		$temp_listing_query=tep_db_query($temp_listing_sql);
		if(tep_db_num_rows($temp_listing_query)==1) {
			$temp_listing_result=tep_db_fetch_array($temp_listing_query);
			tep_redirect(tep_href_link(FILENAME_SUBSCRIPTION_INFO, ($sucPath ? 'sucPath=' . $sucPath . '&' : '') . 'subscription_id=' . $temp_listing_result['subscription_id']));
		}
		
		$content = CONTENT_INDEX_SUBSCRIPTIONS;
	}
	if ($static_category_depth == 'nested') {

	    $static_category_query = tep_db_query("SELECT mp.page_id, mp.parent_id, mp.sort_order, mp.page_status from " . TABLE_MAINPAGE . " mp, " . TABLE_MAINPAGE_DESCRIPTIONS . " mpc where mpc.page_id=mp.page_id and mp.page_id = '" . tep_db_input($spl_stcid[1]) . "' and mpc.language_id = '" . tep_db_input($languages_id) . "'");
    	$static_category = tep_db_fetch_array($static_category_query);
	    $content = CONTENT_INDEX_STATIC;
  	} else if ($static_category_depth=="static") {
		$static_category_query = tep_db_query("SELECT mp.page_id, mp.parent_id, mp.sort_order, mp.page_status from " . TABLE_MAINPAGE . " mp, " . TABLE_MAINPAGE_DESCRIPTIONS . " mpc where mpc.page_id=mp.page_id and mp.page_id = '" . tep_db_input($current_static_category_id) . "'  and mpc.language_id = '" . tep_db_input($languages_id) . "'");
    	$static_category = tep_db_fetch_array($static_category_query);
		$content = CONTENT_INDEX_STATIC;
		}
	//services
	if ($services_category_depth == 'nested') {
	    $sers_category_query = tep_db_query("SELECT sucd.services_categories_name, sucd.services_categories_heading_title, sucd.services_categories_description, suc.services_categories_image from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " sucd where suc.services_categories_id=sucd.services_categories_id and suc.services_categories_id = '" . tep_db_input($current_services_category_id) . "' and sucd.language_id = '" . tep_db_input($languages_id) . "'");


    	$sers_category = tep_db_fetch_array($sers_category_query);

	    $content = CONTENT_INDEX_SERVICES_NESTED;

  	} else if ($services_category_depth=="services") {
  
		$define_services_list = array('SERVICES_LIST_IMAGE' => SERVICES_LIST_IMAGE,
											'SERVICES_LIST_NAME' => SERVICES_LIST_NAME,
											'SERVICES_LIST_COSTS'=>SERVICES_LIST_COSTS,
											
											'SERVICES_LIST_BUY_NOW' => SERVICES_LIST_BUY_NOW);

    
		$column_services_list = array();

		reset($define_services_list);
		while (list($services_key, $services_value) = each($define_services_list)) {
			if ($services_value > 0) $t=10;$column_services_list[] = $services_key;
		}
		$select_services_column_list = '';
		
		for ($i=0, $n=sizeof($column_services_list); $i<$n; $i++) {
			switch ($column_services_list[$i]) {
				case 'SERVICES_LIST_NAME':
					$select_services_column_list .= 'sed.service_name, ';
					break;
				case 'SERVICES_LIST_COSTS':
					$select_services_column_list .= 'se.service_costs, ';
					break;
				case 'SERVICES_LIST_IMAGE':
					$select_services_column_list .= 'se.service_image,sed.service_description, ';
					break;
			}
		}
		
		if (tep_not_null($current_services_category_id)) {
			$listing_sql = "SELECT  " . $select_services_column_list . " se.include_resource,se.include_resource_price,se.service_tax_class_id,se.service_id from " . TABLE_SERVICES . " se, " . TABLE_SERVICES_DESCRIPTION . " sed, " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " se2c where se.service_id = se2c.service_id and sed.service_id = se2c.service_id and sed.language_id = '" . (int)$languages_id . "' and se2c.services_categories_id = '" . (int)$current_services_category_id . "' " .  SERVICES_CONDITION_STATUS;
		} else {
		 	$listing_sql = "SELECT " . $select_services_column_list . "se.service_tax_class_id,se.service_id from " . TABLE_SERVICES . " se," . TABLE_SERVICES_DESCRIPTION . " sed where vd.service_id = v.service_id and vd.language_id = '" . (int)$languages_id . "' " . SERVICES_CONDITION_STATUS;
		}
		// Get the events_category name and description
		$services_category_query = tep_db_query("select secd.services_categories_name, secd.services_categories_heading_title, secd.services_categories_description, sec.services_categories_image from " . TABLE_SERVICES_CATEGORIES . " sec, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " secd where sec.services_categories_id = '" . tep_db_input($current_services_category_id) . "' and secd.services_categories_id = '" . tep_db_input($current_services_category_id) . "' and secd.language_id = '" . tep_db_input($languages_id) . "'");
		$services_category = tep_db_fetch_array($services_category_query);
		$listing_sql .= ' order by services_sort_order ';
		$temp_listing_sql=$listing_sql;
		$temp_listing_query=tep_db_query($temp_listing_sql);
		if(tep_db_num_rows($temp_listing_query)==1) {
			$temp_listing_result=tep_db_fetch_array($temp_listing_query);
			tep_redirect(tep_href_link(FILENAME_SERVICES_INFO, ($secPath ? 'secPath=' . $secPath . '&' : '') . 'service_id=' . $temp_listing_result['service_id']));
		}
		
		$content = CONTENT_INDEX_SERVICES;
	}
  require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_MAIN_PAGE);
  require(DIR_WS_INCLUDES . 'application_bottom.php');
  
?>