<?php
	require_once( $GLOBALS["site_root"] . "/includes/models/Globals.inc.php" );

	class UsersModel {

		public function getLastRegisteredUsers( $limit = 5 ) {
			switch ($GLOBALS["model_version"]) {
			case 2.0:
				$query = sprintf( "select * from fo_user where current_status in %s order by id desc limit %d",
					GlobalsModel::statuses( array( STATUS_ACTIVE , STATUS_HAS_TO_PAY_2W , STATUS_HAS_TO_PAY_4W ) ),
					$limit );
				return FNTH_db_get_resultset( $query );
				break;
			case 3.0:
				// FIXME
				break;
			}
		}

		public function getMembersFromUserIds( $user_ids , $public = true , $lang = "hu" ) {
			if (empty( $user_ids )) return array();
			$query = sprintf( "select members.member_id,users.user_id,users.user_name as user_name,members.member_aliasname,members.member_type,members.expires_tstamp from users left outer join members on (members.user_id=users.user_id) where users.user_id in (%s)",
				implode( "," , $user_ids ) );
			$retval = FNTH_db_get_resultset( $query );
			if ($lang!="hu") {
				require_once( $GLOBALS["site_root"]."/includes/models/ExtendedProperties.inc.php" );
				$epm = new ExtendedPropertiesModel();
				$lang_id = $GLOBALS["languages"][$lang];
				$eprop_id = $epm->getEPropIdFromName( "langsite_name" );
				$query = sprintf( "select member_id,value from member_extended_properties where member_id in (select member_id from members where user_id in (%s)) and language_id=%d and extended_property_id=%d",
					implode( "," , $user_ids ),
					$lang_id ,
					$eprop_id );
				$extend = FNTH_db_get_associative( $query , "member_id" , "value" );
				foreach ($retval as $id => $row) {
					if (isset( $extend[ $row["member_id"] ] ))
						$retval[$id]["user_name"]=$extend[ $row["member_id"] ];
				}
			}	
			return $retval;
		}
		
		public function getMembersFromMemberIds( $member_ids , $public = true , $lang = "hu" ) {
			if (empty( $member_ids )) return array();
			$query = sprintf( "select members.member_id,users.user_id,users.user_name as user_name,members.member_aliasname,members.member_type,members.expires_tstamp from users left outer join members on (members.user_id=users.user_id) where members.member_id in (%s)",
				implode( "," , $member_ids ) );
			$retval = FNTH_db_get_resultset( $query );
			return $retval;
		}
	}

?>
