<?php
	fo3_model( "Cache" );

	class ServiceTypesModel {
		public static function getServiceTypeOptions( $choose = true ) {
			$mc = CacheModel::getCacheNameOnParams( "servicetype_options" ,
				array( "lang" => $GLOBALS["language"], "choose" => $choose ) );
			$retval = CacheModel::getCacheValueOnString( $mc );
			if (is_array( $retval )) return $retval;
			$retval = array();
			if ($choose) $retval[0]=__("Choose");
			$query = sprintf( "select servicetype_id,servicetype_name from servicetypes" );
			$data = FNTH_db_get_resultset( $query );
			foreach ($data as $row)
				$retval[$row["servicetype_id"]]=__( $row["servicetype_name"] , "attr" );
			CacheModel::cacheValueOnString( $mc , $retval );
			return $retval;
		}
		
		public static function getServiceTypeUnitOptions( $choose = true ) {
			$mc = CacheModel::getCacheNameOnParams( "servicetype_unit_options" ,
				array( "lang" => $GLOBALS["language"], "choose" => $choose ) );
			$retval = CacheModel::getCacheValueOnString( $mc );
			if (is_array( $retval )) return $retval;
			$retval = array();
			if ($choose) $retval[0]=__("Choose");
			$query = sprintf( "select servicetype_unit_id,servicetype_unit_name from servicetype_units" );
			$data = FNTH_db_get_resultset( $query );
			foreach ($data as $row)
				$retval[$row["servicetype_unit_id"]]=__( $row["servicetype_unit_name"] , "attr" );
			CacheModel::cacheValueOnString( $mc , $retval );
			return $retval;
		}

		public static function getServiceTypeUnitMinimalLengths( $choose = true ) {
			$mc = CacheModel::getCacheNameOnParams( "servicetype_unit_min_q" ,
				array( "lang" => $GLOBALS["language"], "choose" => $choose ) );
			$retval = CacheModel::getCacheValueOnString( $mc );
			if (is_array( $retval )) return $retval;
			$retval = array();
			if ($choose) $retval[0]=__("Choose");
			$query = sprintf( "select servicetype_unit_id,servicetype_unit_min_q from servicetype_units" );
			$data = FNTH_db_get_resultset( $query );
			foreach ($data as $row)
				$retval[$row["servicetype_unit_id"]]=$row["servicetype_unit_min_q"];
			CacheModel::cacheValueOnString( $mc , $retval );
			return $retval;
		}

	

		public function getServiceTypeUnits( ) {
			$retval = array();
			$query = sprintf( "select * from xref_servicetype_units" );
			$ds = FNTH_db_get_resultset( $query );
			foreach ($ds as $row) {
				$stid=$row["servicetype_id"];
				if (!isset( $retval[$stid] )) $retval[$stid]=array();
				$retval[$stid][]=$row["servicetype_unit_id"];
			}
			return $retval;
		}
	}

?>
