<?php
/*

 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 
*/
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
$template_html=$MASTER_BOX_HTML;
	if(!defined('BOX_HEADING_SUBSCRIPTION'))define('BOX_HEADING_SUBSCRIPTION','Subscriptions');
	function tep_show_subscription_category($counter) {
		global $subscription_foo, $subscription_categories_string, $subscription_display_id, $template_html,$BOX_CONTENT_ICON,$INITIAL_WIDTH;
	
		if ($subscription_foo[$counter]['parent'] == 0) {
			$sucPath_new = 'sucPath=' . $counter;
		} else {
			$sucPath_new = 'sucPath=' . $subscription_foo[$counter]['path'];
		}
		
		$replace_string=$template_html;

		$replace_array["SPACE_WIDTH"]=($subscription_foo[$counter]['level']+1)*10;
		$replace_array["SPACER"]=$replace_array["SPACE_WIDTH"];
		$replace_array["LINK_1"] = tep_href_link(FILENAME_DEFAULT, $sucPath_new);		
		$replace_array["NAME"]=$subscription_foo[$counter]['name'];
		$replace_array["ICON"]=$BOX_CONTENT_ICON;
		$replace_array["INITIAL_WIDTH"]=$INITIAL_WIDTH;
		if(sizeof($subscription_display_id)>0)$selected[0] = $subscription_display_id[sizeof($subscription_display_id)-1];
		else $selected[0] = "";
		if ($subscription_display_id && in_array($counter, $selected)) {
			$replace_array["CLASS"]="infoBoxNavigationSelect";
		} else {
			if ($subscription_foo[$counter]['parent'] != 0) {
				$replace_array["CLASS"]="infoBoxNavigationSub";
			} else {
				$replace_array["CLASS"]="infoBoxNavigation";
			}
		}
		reset($replace_array);
		while(list($key,)=each($replace_array)){
			$replace_string=str_replace("{{" . $key . "}}",$replace_array[$key],$replace_string);
		}
		$subscription_categories_string.=$replace_string;
		
		if ($subscription_foo[$counter]['next_id']) {
			tep_show_subscription_category($subscription_foo[$counter]['next_id']);
		}
	}
	if(HIDE_FROM_BACKEND_MENU_SUBSCRIPTIONS=='false'){
?>
<!-- subscription categories //-->
	<tr>
		<td align="left">      
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td align="left" valign="top">
				<?php
					$subscription_aa = 0;
					$info_box_contents = array();
					$info_box_contents[] = array('align' => 'left',
											'text'  => BOX_HEADING_SUBSCRIPTION
											   );
					new infoBoxHeading($info_box_contents, true, true);
					$subscription_categories_string = '';
					$subscription_categories_query = tep_db_query("select suc.subscription_categories_id, sucd.subscription_categories_name, suc.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '0' and suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id='" . $languages_id ."' order by sort_order, sucd.subscription_categories_name");
					while ($subscription_categories = tep_db_fetch_array($subscription_categories_query))  {
						$subscription_foo[$subscription_categories['subscription_categories_id']] = array(
																								'name' => $subscription_categories['subscription_categories_name'],
																								'parent' => $subscription_categories['parent_id'],
																								'level' => 0,
																								'path' => $subscription_categories['subscription_categories_id'],
																								'next_id' => false
																								);
						
						if (isset($subscription_prev_id)) {
							$subscription_foo[$subscription_prev_id]['next_id'] = $subscription_categories['subscription_categories_id'];
						}
						
						$subscription_prev_id = $subscription_categories['subscription_categories_id'];
						
						if (!isset($subscription_first_element)) {
							$subscription_first_element = $subscription_categories['subscription_categories_id'];
						}
					}

					//------------------------
					if ($sucPath) {
						$subscription_new_path = '';
						$subscription_display_id = split('_', $sucPath);
						reset($subscription_display_id);
						
						while (list($subscription_key, $subscription_value) = each($subscription_display_id)) {
							unset($subscription_prev_id);
							unset($subscription_first_id);
							$subscription_categories_query = tep_db_query("select suc.subscription_categories_id, sucd.subscription_categories_name, suc.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '" . $subscription_value . "' and suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id='" . $languages_id ."' order by sort_order, sucd.subscription_categories_name");
							$subscription_category_check = tep_db_num_rows($subscription_categories_query);
					
							if ($subscription_category_check > 0) {
								$subscription_new_path .= $subscription_value;
								while ($row = tep_db_fetch_array($subscription_categories_query)) {
									$subscription_foo[$row['subscription_categories_id']] = array(
									'name' => $row['subscription_categories_name'],
									'parent' => $row['parent_id'],
									'level' =>$subscription_key+1,
									'path' =>$subscription_new_path . '_' . $row['subscription_categories_id'],
									'next_id' => false
									);
						
									if (isset($subscription_prev_id)) {
										$subscription_foo[$subscription_prev_id]['next_id'] = $row['subscription_categories_id'];
									}
									$subscription_prev_id = $row['subscription_categories_id'];
						
									if (!isset($subscription_first_id)) {
										$subscription_first_id = $row['subscription_categories_id'];
									}
						
									$subscription_last_id = $row['subscription_categories_id'];
								}
								$subscription_foo[$subscription_last_id]['next_id'] = $subscription_foo[$subscription_value]['next_id'];
								$subscription_foo[$subscription_value]['next_id'] =$subscription_first_id;
								$subscription_new_path .= '_';
							} else {
								break;
							}
						}
					}
					tep_show_subscription_category($subscription_first_element);
					
					$info_box_contents = array();
					$info_box_contents[] = array('align' => 'left',
											   'text'  =>'<table border="0" cellpadding="0" cellspacing="0" width="100%">' . $subscription_categories_string . '</table>');
					new infoBox($info_box_contents);
					
					$info_box_contents = array();
					$info_box_contents[] = array('align' => 'left',
					'text'  => tep_draw_separator('pixel_trans.gif', '100%', '1')
											  );
					new infoboxFooter($info_box_contents, true, true);

?> 
				
					   </td>
			       </tr>
			  </table>
		  </td>
	</tr>
 <?PHP } ?>
<!-- categories_eof //-->