<?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;
	function tep_show_services_category($counter) {
		global $services_foo, $services_categories_string, $services_display_id,$template_html,$BOX_CONTENT_ICON,$INITIAL_WIDTH;
	
		if ($services_foo[$counter]['parent'] == 0) {
			$secPath_new = 'secPath=' . $counter;
		} else {
			$secPath_new = 'secPath=' . $services_foo[$counter]['path'];
		}
		$replace_string=$template_html;
		$replace_array["SPACE_WIDTH"]=($services_foo[$counter]['level']+1)*10;
		$replace_array["SPACER"]=$replace_array["SPACE_WIDTH"];
		$replace_array["LINK_1"] = tep_href_link(FILENAME_DEFAULT, $secPath_new);
		$replace_array["NAME"]= $services_foo[$counter]['name'];
		$replace_array["ICON"]=$BOX_CONTENT_ICON;
		$replace_array["INITIAL_WIDTH"]=$INITIAL_WIDTH;
		if(sizeof($services_display_id)>0)$selected[0] = $services_display_id[sizeof($services_display_id)-1];
		else $selected[0] = "";
		if ( ($services_display_id) && (in_array($counter, $selected)) ) {
			$replace_array["CLASS"]="infoBoxNavigationSelect";
		} else {
			if ($services_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);
		}
		$services_categories_string.=$replace_string;
		
		if ($services_foo[$counter]['next_id']) {
			tep_show_services_category($services_foo[$counter]['next_id']);
		}
	}
if(HIDE_FROM_BACKEND_MENU_SERVICES=='false') {
?>
<!-- service categories //-->
	<tr>
		<td>
		<table cellpadding="0" cellspacing="0" width="100%" border="0">
			<tr>
				<td width="100%">
					<?php
						if(!defined('BOX_HEADING_SERVICES'))define('BOX_HEADING_SERVICES', 'Services');
						$services_aa = 0;
						$info_box_contents = array();
						$info_box_contents[] = array('align' => 'left',
						'text'  => BOX_HEADING_SERVICES 
						);
						new infoBoxHeading($info_box_contents, true, true);
						$services_categories_string = '';
					
						$services_categories_query = tep_db_query("select sec.services_categories_id, secd.services_categories_name, sec.parent_id from " . TABLE_SERVICES_CATEGORIES . " sec, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " secd where sec.parent_id = '0' and sec.services_categories_id = secd.services_categories_id and secd.language_id='" . $languages_id ."' order by sort_order, secd.services_categories_name");
						while ($services_categories = tep_db_fetch_array($services_categories_query))  {
							$services_foo[$services_categories['services_categories_id']] = array(
							'name' => $services_categories['services_categories_name'],
							'parent' => $services_categories['parent_id'],
							'level' => 0,
							'path' => $services_categories['services_categories_id'],
							'next_id' => false
							);
					
							if (isset($services_prev_id)) {
								$services_foo[$services_prev_id]['next_id'] = $services_categories['services_categories_id'];
							}
					
							$services_prev_id = $services_categories['services_categories_id'];
							
							if (!isset($services_first_element)) {
								$services_first_element = $services_categories['services_categories_id'];
							}
						}
					
						//------------------------
						if ($secPath) {
							$services_new_path = '';
							$services_display_id = split('_', $secPath);
							reset($services_display_id);
							
							while (list($services_key, $services_value) = each($services_display_id)) {
								unset($services_prev_id);
								unset($services_first_id);
								$services_categories_query = tep_db_query("select suc.services_categories_id, sucd.services_categories_name, suc.parent_id from " . TABLE_SERVICES_CATEGORIES . " suc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '" . $services_value . "' and suc.services_categories_id = sucd.services_categories_id and sucd.language_id='" . $languages_id ."' order by sort_order, sucd.services_categories_name");
								$services_category_check = tep_db_num_rows($services_categories_query);
								
								if ($services_category_check > 0) {
									$services_new_path .= $services_value;
									while ($row = tep_db_fetch_array($services_categories_query)) {
										$services_foo[$row['services_categories_id']] = array(
										'name' => $row['services_categories_name'],
										'parent' => $row['parent_id'],
										'level' =>$services_key+1,
										'path' =>$services_new_path . '_' . $row['services_categories_id'],
										'next_id' => false
										);
									
										if (isset($services_prev_id)) {
											$services_foo[$services_prev_id]['next_id'] = $row['services_categories_id'];
										}
									
										$services_prev_id = $row['services_categories_id'];
									
										if (!isset($services_first_id)) {
											$services_first_id = $row['services_categories_id'];
										}
									
										$services_last_id = $row['services_categories_id'];
									}
									$services_foo[$services_last_id]['next_id'] = $services_foo[$services_value]['next_id'];
									$services_foo[$services_value]['next_id'] =$services_first_id;
									$services_new_path .= '_';
								} else {
									break;
								}
							}
						}
						tep_show_services_category($services_first_element);
						
						$info_box_contents = array();
						$info_box_contents[] = array('align' => 'left',
											   'text'  => '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr>' . $services_categories_string . '</tr></table>');
						new infoBox($info_box_contents);
						
						$info_box_contents = array();
						new infoboxFooter($info_box_contents, true, true);
?>
 				</td>
			</tr>
	     </table>
		</td>
   </tr>
<?php } ?> 
<!-- service categories_eof //-->
