<?php

	class SpecialtyModel {

		public function getSpecialtyIdFromOldid( $oldid ) {
			$query = sprintf( "select specialty_id from specialties where oldid=%d" , $oldid );
			$row = FNTH_db_get_row( $query );
			if (!$row) return false;
			return $row["specialty_id"];
		}

		public function addSpecialty( $p ) {
			$ins = array();
			$ins["specialty_name"]=sprintf( "'%s'" , FNTH_db_addslashes( $p["specialty_name"] ) );
			if (isset( $p["oldid"] )) $ins["oldid"]=sprintf( "%d" , $p["oldid"] );
			FNTH_db_free_result( FNTH_db_query(  FNTH_db_generate_insert_query( "specialties" , $ins ) ) );

			$q = sprintf( "select currval('specialties_specialty_id_seq') as num" );
			$seq = FNTH_db_get_row( $q );
			$spec_id = $seq["num"];
			return $spec_id;
		}

		public function setSpecialtyLangdef( $specialty_id , $language_id , $name , $ordering ) {
			$query = sprintf( "select * from specialty_langdefs where specialty_id=%d and site_language_id=%d", $specialty_id , $language_id );
			$row = FNTH_db_get_row( $query );
			$p = array();
			$p["specialty_id"]=sprintf( "%d" , $specialty_id );
			$p["site_language_id"]=sprintf( "%d" , $language_id );
			$p["langdef_name"]=sprintf( "'%s'" , FNTH_db_addslashes( $name ) );
			$p["langdef_aliasname"]=sprintf( "'%s'" , FNTH_db_addslashes( fo3_generate_alias( $name ) ) );
			$p["langdef_ordering"]=sprintf( "%d" , $ordering );
			$query = ($row) ?
				FNTH_db_generate_update_query( "specialty_langdefs" , $p ,
					sprintf( "specialty_id=%d and site_language_id=%d" , $specialty_id , $language_id ) ) :
				FNTH_db_generate_insert_query( "specialty_langdefs", $p );
			FNTH_db_free_result( FNTH_db_query( $query ) );
		}
	}


?>
