<?php
/*

  osCommRes, Services Online 
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
 // Check to ensure this file is included in Freeway!
defined('_FEXEC') or die(); 

function tep_get_service_output_tree($parent_id = '0',&$content,$default,$service_category_id=0) {
    global $languages_id,$selected_name,$login_id,$login_groups_type;

	// iterate with nested category

	$service_where = '';
	if($service_category_id>0)$service_where = " and sc.services_categories_id='" . $service_category_id . "'";

	$service_category_query = tep_db_query("select sc.services_categories_id, scd.services_categories_name, sc.parent_id from " . TABLE_SERVICES_CATEGORIES . " sc, " . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " scd where sc.services_categories_id = scd.services_categories_id and scd.language_id = '" . (int)$languages_id . "' and sc.parent_id = '" . (int)$parent_id . "' " . $service_where . " order by sc.sort_order, scd.services_categories_name");
	
	while ($service_category = tep_db_fetch_array($service_category_query)) {
		$content.= '<optgroup style="color:#0000FF" label="' . write_services_category_space($service_category['services_categories_id']) . tep_output_string($service_category['services_categories_name'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '">';
		// select the list of service of particular category
		$service_query=tep_db_query("select sed.service_name,sed.service_id from " . TABLE_SERVICES . ' se, ' . TABLE_SERVICES_DESCRIPTION . " sed, " . TABLE_SERVICES_TO_SERVICES_CATEGORIES . " scd where scd.services_categories_id='" . $service_category['services_categories_id'] . "' and sed.language_id = " . (int)$languages_id . " " . SERVICES_CONDITION_STATUS. " and se.service_id=scd.service_id and se.service_id=sed.service_id order by sed.service_name");
		while ($service=tep_db_fetch_array($service_query))
		{
			$content .= '<option style="color:#000000" value="' . tep_output_string($service['service_id']) . '"';
			if ($default == $service['service_id']){
				$selected_name=$service['service_name'];
				$content .= ' SELECTED';
			}
			$content .= '>' . tep_output_string($service['service_name'], array('"' => '&quot;', '\'' => '&#039;', '<' => '&lt;', '>' => '&gt;')) . '</option>';
		}    
		tep_get_service_output_tree($service_category['services_categories_id'], $content,$default);
		$content.='</optgroup>';
	}

}
	function write_services_category_space($category_id){
	    global $languages_id,$selected_name,$login_id,$login_groups_type;
		$sql = "select parent_id,sc.services_categories_id,services_categories_name from " . TABLE_SERVICES_CATEGORIES . " sc," . TABLE_SERVICES_CATEGORIES_DESCRIPTION . " scd where sc.services_categories_id=scd.services_categories_id and scd.language_id = '" . (int)$languages_id . "' and sc.services_categories_id=" . $category_id;
		$query = tep_db_query($sql);
		$result = tep_db_fetch_array($query);
		if($result['parent_id']>0){
			return "&nbsp;&nbsp;" . write_services_category_space($result['parent_id']);
		}else{
			return "";
		}
	}
	// Output a form pull down menu
	function tep_draw_service_select_menu($name, $values, $default = '', $parameters = '', $required = false,$initial_category_id=0,$need_all=true,$initial_parent_id=0) {
		global $selected_name;
		$field = '<select name="' . tep_output_string($name) . '"';
	
		if (tep_not_null($parameters)) $field .= ' ' . $parameters;
		$field.=' class="inputNormal" onBlur="javascript:toggle_focus(this,1);" onFocus="javascript:toggle_focus(this,2);"';
	
		$field .= '>';
		if($need_all=='true')
		$field .= '<option style="color:#000000" value="-1">' . TEXT_ALL_SERVICES . '</option>';
		else if($need_all=='1')
		$field .= '<option style="color:#000000" value="-1">' . TEXT_SELECT . '</option>';
		
		if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);
	
		$content="";
		tep_get_service_output_tree($initial_parent_id,$content,$default,$initial_category_id);
		$field.=$content;
	$field .= '</select>';
	
	if ($required == true) $field .= TEXT_FIELD_REQUIRED;
	
	return $field;
	}
	// get the list of category and events in a tree view
	function tep_get_service_display_tree_grouped($parent_id = '0', $spacing = 0, $exclude = '', $service_category_tree_array = '', $include_itself = false) {
		global $languages_id,$login_id,$login_groups_type;
	
		$login_option="";
		if ($login_groups_type==TEXT_SERVICES_ENTRY){
			$login_option=" and s.provider=" . $login_id;
		}
		if (!is_array($service_category_tree_array)) $service_category_tree_array = array();
		//if ( (sizeof($events_category_tree_array) < 1) && ($exclude != '0') ) $events_category_tree_array[] = array('id' => '0', 'text' => TEXT_TOP,'type'=>'C','spacing'=>$spacing);
	
		if ($include_itself) {
		  $service_category_query = tep_db_query("select service_name from " . TABLE_SERVICES_DESCRIPTION . " where language_id = '" . (int)$languages_id );
		  $service_category = tep_db_fetch_array($service_category_query);
		  $service_category_tree_array[] = array('id' => $parent_id, 'text' => $service_category['service_name'],'type'=>'C','spacing'=>$spacing);
		}
		$service_categories_query = tep_db_query("select service_id, service_name from " . TABLE_SERVICES . " language_id = '" . (int)$languages_id . "' and order by service_name");
		while ($service_categories = tep_db_fetch_array($service_categories_query)) {
		  if ($exclude != $service_categories['service_id']) $service_category_tree_array[] = array('id' => $service_categories['service_id'], 'text' =>$service_categories['service_name'],'type'=>'C','spacing'=>$spacing);
		  $service_category_tree_array = tep_get_service_display_tree_grouped($service_categories['services_categories_id'], $spacing+1, $exclude, $service_category_tree_array);
		}
	
		$service_query=tep_db_query("select service_name,service_id from " . TABLE_SERVICES_DESCRIPTION  . " order by service_name");
		while ($service=tep_db_fetch_array($service_query))
		{
			$service_category_tree_array[] = array('id' => $service['service_id'], 'text' =>$service['service_name'],'type'=>'E','spacing'=>$spacing);
		}
		return $service_category_tree_array;
	}
	// service tree
	function tep_get_service_array_single($first=''){
		global $languages_id;
		$service_array=array();
		$service_query=tep_db_query("SELECT se.service_id,sed.service_name from " . TABLE_SERVICES . " se, " . TABLE_SERVICES_DESCRIPTION . " sed where se.service_id=sed.service_id and language_id='" . $languages_id . "' " . SERVICES_CONDITION_STATUS . " order by sed.service_name");
		while($service_result=tep_db_fetch_array($service_query)){
			$service_array[]=array('id'=>$service_result['service_id'],'text'=>$service_result['service_name']);
		}
		return $service_array;
	} 
	
function tep_get_services_instructor_array_single($first=''){
		global $languages_id,$login_groups_type,$login_id;
		$services_array=array();
		$services_option="";
		if ($login_groups_type==TEXT_SERVICES_ENTRY) $services_option=" and se.provider='" . $login_id . "'";
		$services_query=tep_db_query("SELECT se.service_id,sed.service_name from " . TABLE_SERVICES . " se, " . TABLE_SERVICES_DESCRIPTION . " sed where se.service_id=sed.service_id " . SERVICES_CONDITION_STATUS . $services_option . " and language_id='" . $languages_id. "' order by sed.service_name");
			while($services_result=tep_db_fetch_array($services_query)){
			$services_array[]=array('id'=>$services_result['service_id'],'text'=>$services_result['service_name']);
		}
		return $services_array;
	} 
?>
