<?php

class seas_user_Model {
	
	public function login($usr_name,$passwd,$usr_obj) {
		
		try  {
			$sql = 'select * from seas_user where logname="' . trim($usr_name) . '" and passwd = password("' . trim($passwd) . '")';
			$rslt = mysql_query($sql);
			$usr_array = array();
			
			if(mysql_num_rows($rslt) >0) {
				$usr_array = mysql_fetch_assoc($rslt);
				
				$usr_obj->set_user_id($usr_array['user_id']);
				$usr_obj->set_logname($usr_array['logname']);
				$usr_obj->set_fullname($usr_array['fullname']);
				$usr_obj->set_usertype($usr_array['usertype']);
				$usr_obj->set_date_expiry($usr_array['date_expiry']);
				$usr_obj->set_user_options($usr_array['user_options']);
						
				return true;
			}
			else {
				return false;
			}
			
			if(is_resource($rslt)) {
				mysql_free_result($rslt);
			}
			
		}
		catch (Exception $e) {
			return false;
		}
		
	} 
	
	
	public function get_user_priv($uid) {
		try  {
			
			// Survey Type
			$priv_srv_type=array();
			$sql = 'select distinct srv_type from seas_user_priv where user_id = ' . $uid;
			$rslt = mysql_query($sql);
			while($rw=mysql_fetch_assoc($rslt)) {
				$priv_srv_type[] = $rw['srv_type'];
			}

			// Survey market
			$priv_srv_market=array();
			$sql = 'select distinct market from seas_user_priv where user_id = ' . $uid;
			$rslt = mysql_query($sql);
			while($rw=mysql_fetch_assoc($rslt)) {
				$priv_srv_market[] = $rw['market'];
			}
			
			$user_priv = array();
			$user_priv["srv_type"]   = $priv_srv_type;
			$user_priv["srv_market"] = $priv_srv_market;
			
			return $user_priv;
			
			if(is_resource($rslt)) {
				mysql_free_result($rslt);
			}			
			
			
		}
		catch (Exception $e) {
			return false;
		}		
		
	}
}

?>