<?php

/*

Project Name: Jnannys

File Name: commonpages_model.php. Model File

Description: The file contains common pages related functions.

*/



require_once './lib/simplemvcwf/model_base.php';

require_once './utility/guid_utility.php';



// Encapsulates all common pages database table access. This method of encapsulation uses the singleton design pattern.

class MembersModel extends ModelBase {

    private static $MembersModel = NULL;

    

    private function __construct() {

    }

    

    // The create function is necessary to ensure there is only one instance of common pages table being used at any one time (eg. singleton)

    static function create() {

        if (NULL == self::$MembersModel) {

           self::$MembersModel = new MembersModel();

        }

        return self::$MembersModel;

    }

    

    // Retrieves a common page row by its id    

    public function selectPagesByPageId($pageId) {

		

		global $MyPdodb;		        

		$pageId = (int) $pageId;

		$sql = "SELECT * FROM hi_members WHERE id = :id  LIMIT 1";        		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':id', $pageId, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);			

			return $results[0];		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}



    }

	public function selectPagesByPageId_family($pageId) {

		

		global $MyPdodb;		        

		$pageId = (int) $pageId;

		$sql = "SELECT * FROM hi_family WHERE id = :id  LIMIT 1";        		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':id', $pageId, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);			

			return $results[0];		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}



    }

	

	 // Retrieves a common page row by its pagename    

    public function selectPagesByPageName($pageName) {

		

		global $MyPdodb;		        		

		$sql = "SELECT * FROM hi_members WHERE url = :url  LIMIT 1";        		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':url', $pageName, PDO::PARAM_STR);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);			

			return $results[0];				

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function getBirthday() {

		

		global $MyPdodb;		        		

		//$sql = "SELECT *,DAY(dob) as d FROM hi_members WHERE DAY(dob) < DAY(CURDATE())+15 and DAY(dob) >= DAY(CURDATE()) AND MONTH(dob) = MONTH(CURDATE()) order by d desc";

		/*$sql = "SELECT id,fullname,simage,gender,DAY(dob) as d,dob FROM hi_members WHERE DATE_ADD(dob, INTERVAL YEAR(CURDATE())-YEAR(dob) YEAR) 

            BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) union SELECT id,fam_fullname as fullname,fam_simage as simage,fam_gender as gender,DAY(fam_dob) as d,fam_dob FROM hi_family WHERE DATE_ADD(fam_dob, INTERVAL YEAR(CURDATE())-YEAR(fam_dob) YEAR) 

            BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) order by d asc";   */ 

			$sql = "SELECT id,fam_fullname as fullname,fam_simage as simage,fam_gender as gender,DAY(fam_dob) as d,fam_dob,familyno FROM hi_family WHERE DATE_ADD(fam_dob, INTERVAL YEAR(CURDATE())-YEAR(fam_dob) YEAR) BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) order by d asc";     		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':url', $pageName, PDO::PARAM_STR);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			foreach($results as $result){

				$sql = "select count(id) as wishcount from hi_birthdaywishes where birthday_id='".$result->id."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$wishcount = $res->wishcount;

					//array_push($arrres,$totalsubsec);

					$results[$i]->wishcount = $wishcount;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}					

			return $results;				

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function getBirthdayDetail($postvars) {

		

		global $MyPdodb;

		$birthday = $postvars['birthday_id'];		        		

		$sql = "SELECT * FROM hi_family WHERE id=:birthdayid";        		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':birthdayid', $birthday, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			return $results[0];				

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	

	public function getMissyou() {

		

		global $MyPdodb;		        		

		//$sql = "SELECT *,DAY(expirydate) as d FROM hi_members WHERE DAY(expirydate) < DAY(CURDATE())+15 and DAY(expirydate) >= DAY(CURDATE()) AND MONTH(expirydate) = MONTH(CURDATE()) order by d desc";        		

		//$sql = "SELECT *,DAY(expirydate) as d FROM hi_members WHERE DATE_ADD(expirydate, INTERVAL YEAR(CURDATE())-YEAR(expirydate) YEAR) 

          //  BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) order by d desc";

		 /* $sql = "SELECT id,fullname,simage,gender,DAY(expirydate) as d,expirydate FROM hi_members WHERE DATE_ADD(expirydate, INTERVAL YEAR(CURDATE())-YEAR(expirydate) YEAR) 

            BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) union SELECT id,fam_fullname as fullname,fam_simage as simage,fam_gender as gender,DAY(fam_expirydate) as d,fam_expirydate FROM hi_family WHERE DATE_ADD(fam_expirydate, INTERVAL YEAR(CURDATE())-YEAR(fam_expirydate) YEAR) 

            BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) order by d asc";*/

			$sql = "SELECT id,fam_fullname as fullname,fam_simage as simage,fam_gender as gender,DAY(fam_expirydate) as d,fam_expirydate,familyno FROM hi_family WHERE DATE_ADD(fam_expirydate, INTERVAL YEAR(CURDATE())-YEAR(fam_expirydate) YEAR) BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 15 DAY) order by d asc";

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':url', $pageName, PDO::PARAM_STR);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			foreach($results as $result){

				$sql = "select count(id) as wishcount from hi_missyoumsgs where missyou_id='".$result->id."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$wishcount = $res->wishcount;

					//array_push($arrres,$totalsubsec);

					$results[$i]->wishcount = $wishcount;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}				

			return $results;				

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

    public function getMissyouDetail($postvars) {

		

		global $MyPdodb;

		$missyou = $postvars['missyou_id'];		        		

		$sql = "SELECT * FROM hi_family WHERE id=:missyou";        		

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':missyou', $missyou, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			return $results[0];				

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

    // Retrieves all pages

    public function selectPages($start=0,$limit) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));		

		$sql = "SELECT * FROM hi_members";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				$sql = "select name as cityname from hi_cities where id='".$result->city."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$cityname = $res->cityname;

					//array_push($arrres,$totalsubsec);

					$results[$i]->cityname = $cityname;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	

	public function selectMembers($postvars) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));	

		$sql_count = "SELECT count(id) as cnt FROM hi_members where status=1 ";

	    try {

				$stm  = $MyPdodb->prepare($sql_count);      		

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

		    }	

				

		$totalCounts = $results[0]->cnt;			

	    $_REQUEST["totalres"] = $totalCounts;

		$_REQUEST["nume"] = $totalCounts;		

		$sql = "SELECT * FROM hi_members where status=1 order by fullname asc LIMIT ?, ?";  

		try{

			$stm  = $MyPdodb->prepare($sql); 

			$BindArr[] =(int) $postvars["eu"];

			$BindArr[] =(int) $postvars["limit"];	     		

			$stm->execute($BindArr);

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				$sql = "select name as cityname from hi_cities where id='".$result->city."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$cityname = $res->cityname;

					//array_push($arrres,$totalsubsec);

					$results[$i]->cityname = $cityname;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}	

			$i=0;

			foreach($results as $result){

				$sql = "select count(id) as familymembers from hi_family where memberid='".$result->id."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$familymembers = $res->familymembers;

					//array_push($arrres,$totalsubsec);

					$results[$i]->familymembers = $familymembers;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function listfamily($postvars) {

		

		global $MyPdodb;

		if($postvars["member_id"]!=''){

			$memberid = $postvars["member_id"];

		}else{

			$memberid = $_SESSION["member_id"];

		}

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));	

		$sql_count = "SELECT count(id) as cnt FROM hi_family where memberid = '".$memberid."' and fam_status=1 ";

	    try {

				$stm  = $MyPdodb->prepare($sql_count);      		

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

		    }	

				

		$totalCounts = $results[0]->cnt;			

	    $_REQUEST["totalres"] = $totalCounts;

		$_REQUEST["nume"] = $totalCounts;

		$sql = "SELECT * FROM hi_family where memberid = '".$memberid."' order by fam_fullname asc LIMIT ?, ?";  

		try{

			$stm  = $MyPdodb->prepare($sql); 

			$BindArr[] =(int) $postvars["eu"];

			$BindArr[] =(int) $postvars["limit"];	     		

			$stm->execute($BindArr);

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				$sql = "select name as cityname from hi_cities where id='".$result->city."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$cityname = $res->cityname;

					//array_push($arrres,$totalsubsec);

					$results[$i]->cityname = $cityname;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}	

			$i=0;

			foreach($results as $result){

			if($result->ismainmember==1){

				$sql = "select simage from hi_members where id='".$result->memberid."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$simage = $res->simage;

					//array_push($arrres,$totalsubsec);

					$results[$i]->fam_simage = $simage;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			}

			$i++;

			}	

			

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function selectMembers_search($postvars) {

		
		global $MyPdodb;

		$active = 1;

		$eu = $postvars["eu"]*1;

		$limit = $postvars["limit"]*1;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));	

		$nativeplace = $postvars["nativeplace"];

		$bus_nameofcompany = $postvars["bus_nameofcompany"];

		$bus_nature = $postvars["bus_nature"];

		if($nativeplace==''){
		

			$fname = $postvars["fname"];

			if($fname!=''){

				$subsql = " fam_fullname like ?";

				$BindArr[]="%".$fname."%";

			}		

			

			$gender = $postvars["gender"];

			if($gender!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " fam_gender = ?";

				$BindArr[]=$gender;

			}

			$maritalstatus = $postvars["maritalstatus"];

			if($maritalstatus!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " fam_maritalstatus = ?";

				$BindArr[]=$maritalstatus;

			}

			if($bus_nameofcompany!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " fam_nameofcompany like ?";

				$BindArr[]="%".$bus_nameofcompany."%";

				

			}

			if($bus_nature!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " bus_nature like ?";

				$BindArr[]="%".$bus_nature."%";

				

			}

			$bloodgroup = $postvars["blood"];

			if($bloodgroup!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " fam_bloodgroup = ?";

				$BindArr[]=$bloodgroup;

			}
						
			if($subsql!=''){

				$subsql .= " and ";

			}

				$subsql .= " fam_status = ?";

				$BindArr[] =(int) $active;
				
			
			$sql_count = "SELECT count(id) as cnt FROM hi_family where $subsql ";

			try {

					$stm  = $MyPdodb->prepare($sql_count);

					$stm->execute($BindArr);

					$results = $stm->fetchAll(PDO::FETCH_CLASS);

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}	

					

			$totalCounts = $results[0]->cnt;			

			$_REQUEST["totalres"] = $totalCounts;

			$_REQUEST["nume"] = $totalCounts;	

			

			$sql = "SELECT id,fam_simage as simage, fam_fullname as fullname, fam_gender as gender, fam_city as city, familyno, fam_email as email, memberid FROM hi_family where $subsql order by familyno LIMIT ?, ? ";  

			try{

				$stm  = $MyPdodb->prepare($sql); 

				$BindArr[] =(int) $postvars["eu"];

				$BindArr[] =(int) $postvars["limit"];	

					

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

					

				return $results ;		

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

			}

		}else{
						
			$fname = $postvars["fname"];

			if($fname!=''){

				$subsql = " fullname like ?";

				$BindArr[]="%".$fname."%";

			}		

			$gender = $postvars["gender"];

			if($gender!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " gender = ?";

				$BindArr[]=$gender;

			}
			
			$area = $postvars["area"];

			if($area!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " area like ?";

				$BindArr[]="%".$area."%";

			}

			$maritalstatus = $postvars["maritalstatus"];

			if($maritalstatus!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " maritalstatus = ?";

				$BindArr[]=$maritalstatus;

			}

			$bloodgroup = $postvars["blood"];

			if($bloodgroup!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " bloodgroup = ?";

				$BindArr[]=$bloodgroup;

			}

			if($nativeplace!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " nativeplace like ?";

				$BindArr[]="%".$nativeplace."%";

				

			}

			if($bus_nameofcompany!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " bus_nameofcompany like ?";

				$BindArr[]="%".$bus_nameofcompany."%";

				

			}

			if($bus_nature!=''){

				if($subsql!='')

					$subsql .= " and ";

				$subsql .= " bus_nature like ?";

				$BindArr[]="%".$bus_nature."%";

				

			}
			
			$about_business = $postvars["about_business"];
			if($about_business!=''){
				if($subsql!='')
					$subsql .= " and ";
				$subsql .= " about_business LIKE ?";
				$BindArr[]="%".$about_business."%";
			}	

			if($subsql!=''){

				$subsql .= " and ";

			}

				$subsql .= "status = ?";

				$BindArr[] =(int) $active;

			

			$sql_count = "SELECT count(id) as cnt FROM hi_members where $subsql ";

			try {

					$stm  = $MyPdodb->prepare($sql_count);

					$stm->execute($BindArr);

					$results = $stm->fetchAll(PDO::FETCH_CLASS);

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}	

					

			$totalCounts = $results[0]->cnt;			

			$_REQUEST["totalres"] = $totalCounts;

			$_REQUEST["nume"] = $totalCounts;	

			

			$sql = "SELECT * FROM hi_members where $subsql order by familyno LIMIT ?, ? ";  

			try{

				$stm  = $MyPdodb->prepare($sql); 

				$BindArr[] =(int) $postvars["eu"];

				$BindArr[] =(int) $postvars["limit"];	

					

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

					

				return $results ;		

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

			}	

		}

		

		

    }

	// Retrieves total count of common pages

    public function selectCount() {

       global $MyPdodb;

       $sql = "SELECT count(id) as cnt FROM hi_members";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function getSectionName($secid) {

       global $MyPdodb;

       $sql = "SELECT name FROM hi_members where id = $secid";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function selectSectionName($section_id) {

       global $MyPdodb;

       $sql = "SELECT name FROM hi_members where id=:section_id";        	       	  

	   $stm  = $MyPdodb->prepare($sql);      		

		$stm->bindParam(':section_id', $section_id, PDO::PARAM_INT);

		$stm->execute();       

	  	$results = $stm->fetchAll(PDO::FETCH_CLASS);	

		$section_name = $results[0];		

		return $section_name->name;  

    }

	

	// Change disaply Status

    public function changeStatus($postvars) {

        global $MyPdodb;

		   $recId = $postvars["member_id"];

		   $recStatus = $postvars["recStatus"];	   

		   if($recStatus == 1) { $recStatus=0; } else { $recStatus = 1; }	

			$sql = "UPDATE hi_members set status = :status where id = :id ";

			try {

						$stm  = $MyPdodb->prepare($sql);      		

						$stm->bindParam(':status', $recStatus, PDO::PARAM_INT);		

						$stm->bindParam(':id', $recId, PDO::PARAM_INT);

						$stm->execute();       

						$msg=CommonModel::create()->getSettings('MEMBER_STATUS_MSG');					

				}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

				}

			return $msg;

		

    }

	

	// Change disaply Status

    public function changeStatus_family($postvars) {

        global $MyPdodb;

		   $recId = $postvars["id"];

		   $recStatus = $postvars["recStatus"];	   

		   if($recStatus == 1) { $recStatus=0; } else { $recStatus = 1; }	

		  // echo $recId;

		   //exit;

			$sql = "UPDATE hi_family set fam_status = :status where id = :id ";

			try {

						$stm  = $MyPdodb->prepare($sql);      		

						$stm->bindParam(':status', $recStatus, PDO::PARAM_INT);		

						$stm->bindParam(':id', $recId, PDO::PARAM_INT);

						$stm->execute();       

						$msg=CommonModel::create()->getSettings('MEMBER_STATUS_MSG');					

				}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

				}

			return $msg;

		

    }

	public function changeStatus_request($postvars) {

        global $MyPdodb;

		   $recId = $postvars["member_id"];

		   $recStatus = $postvars["recStatus"];	   

		   if($recStatus == 1) { $recStatus=0; } else { $recStatus = 1; }	

			$sql = "UPDATE hi_memberrequest set status = :status where id = :id ";

			try {

						$stm  = $MyPdodb->prepare($sql);      		

						$stm->bindParam(':status', $recStatus, PDO::PARAM_INT);		

						$stm->bindParam(':id', $recId, PDO::PARAM_INT);

						$stm->execute();       

						$msg=CommonModel::create()->getSettings('MEMBER_STATUS_MSG');					

				}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

				}

			return $msg;

		

    }

    

	public function delete($recId) {

       global $MyPdodb;		        

	    $sql = "Delete from hi_members where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       		

			$msg=CommonModel::create()->getSettings('MEMBER_DELETE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function deletefamily($recId) {

       global $MyPdodb;	

	   $sql = "Delete from hi_family where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       		

			$msg=CommonModel::create()->getSettings('MEMBER_DELETE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function approve($recId) {

       global $MyPdodb;		        

	    $sql = "update hi_members set approved=1 where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute(); 

			$sql = "SELECT fullname,email FROM hi_members where id=:id";        	       	  

		   $stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$fullname = $results[0]->fullname;		      		

			$email = $results[0]->email;

			$subject = "JPC Membership Approved";

								$TO=$email;

								$URL = 'http://jpc.arihantseo.in/login';

								$adminMail = FrontpagesModel::create()->getSettings('MAIL_SEND_FROM_EMAIL');

								$BODY='<table width="619" border="1">

							  <tr>

								<td width="609">Dear '.$fullname.', Your Membership is approved by JPC now you can login. </td>

							  </tr>

							  

							  <tr>

								<td>URL:<a href="'.$URL.'">'.$URL.'</a></td>

							  </tr>

							  <tr>

								<td>Thank you, JPC Vadodara</td>

							  </tr>

							</table>

							';

								$header="MIME-Version: 1.0\r\n";

								$header.="Content-type: text/html \r\n";

								$header .= "From: ".$adminMail." \r\n";

								

								$fname = "JPC Vadodara";

								

								

								//echo $BODY;

								@mail($TO,$subject,$BODY,$header);

			$msg=CommonModel::create()->getSettings('MEMBER_APPROVE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function delete_request($recId) {

       global $MyPdodb;		        

	    $sql = "Delete from hi_memberrequest where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       		

			$msg=CommonModel::create()->getSettings('MEMBER_DELETE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	

	

	

	// Update a common page row into the table and returns confirmation message

    public function editRecord($postvars,$filevars) {

       global $MyPdodb;

	   	$id = $postvars['member_id'];

		$familyno =$postvars['familyno'];

		$oldfamilyno = $postvars['oldfamilyno'];

		$fullname =$postvars['fullname'];

		$gender =$postvars['gender'];

		$bloodgroup =$postvars['bloodgroup'];

		$dob =$postvars['dob'];

		$expirydate =$postvars['expirydate'];

		$nativeplace =$postvars['nativeplace'];

		$address1 =$postvars['address1'];

		$address2 =$postvars['address2'];

		$area =$postvars['area'];

		$city =$postvars['city'];

		$state =$postvars['state'];

		$country =$postvars['country'];

		$zipcode =$postvars['zipcode'];

		$phone =$postvars['phone'];

		$mobile =$postvars['mobile'];

		$email =$postvars['email'];

		$maritalstatus =$postvars['maritalstatus'];

		$education =$postvars['education'];

		$occupation =$postvars['occupation'];

		$bus_nameofcompany =$postvars['bus_nameofcompany'];

		$bus_designation =$postvars['bus_designation'];

		$bus_address1 =$postvars['bus_address1'];

		$bus_address2 =$postvars['bus_address2'];

		$bus_city =$postvars['bus_city'];

		$bus_state =$postvars['bus_state'];

		$bus_country =$postvars['bus_country'];

		$bus_zip =$postvars['bus_zip'];

		$bus_phone =$postvars['bus_phone'];

		$bus_website =$postvars['bus_website'];

		$bus_email =$postvars['bus_email'];

		$bus_nature =$postvars['bus_nature'];

		$nooffamilymembers =$postvars['nooffamilymembers'];

		$showcontactinfo =$postvars['showcontactinfo'];
		$about_business =$postvars['about_business'];

			$sql = "SELECT id FROM hi_members where familyno=:familyno and id!=:id";        	       	  

		   	$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

			$stm->bindParam(':id', $id, PDO::PARAM_INT);

			$stm->execute();       

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$chkemail = $results[0];		

			if($chkemail->id==''){

						$password =$postvars['password'];

						$username =$postvars['username'];

						

						$status =$postvars['status'];

						if($status==''){

							$status=1;

						}

						

						$simage =$postvars['simage'];

						$approved =$postvars['approved'];

						$tdate = date("Y-m-d");	   

						$udate = date("Y-m-d");

						$simage = $filevars['simage'];

						$thumbFolder = UPLOADDIR_MEMBERS;

						$validExtArr = explode(",",VALID_EXT_MEMBERS);

						$recId = rand(1000,10000);

						$homebanner_image_old = $postvars['homebanner_image_old'];

						

					   

					   

						 if(!empty($filevars['simage']['name'])){

						   $file = explode('.',basename($filevars['simage']['name']));

						   $ext = ".".$file[count($file)-1];

							if(!in_array($ext,$validExtArr))

							{

								 $parentMsg=INVALID_PHOTO_MSG;

								 $product_image_name = "";

							}

							else{	

								$homebanner_name = $recId.".".$file[count($file)-1];

								$new_file = $thumbFolder."/".$homebanner_name;		

								$copied = copy($filevars['simage']['tmp_name'], $new_file);

								@unlink($thumbFolder."/".$product_image_old);

							}

					   }else{

						   $homebanner_name=$homebanner_image_old;

					   }

								

						

						$sql = "UPDATE hi_members SET ";

						$sql .= " familyno = :familyno, ";

						$sql .= " fullname = :fullname, ";

						$sql .= " gender = :gender, ";

						$sql .= " bloodgroup = :bloodgroup, ";

						$sql .= " dob = :dob, ";

						$sql .= " expirydate = :expirydate, ";

						$sql .= " nativeplace = :nativeplace, ";

						$sql .= " maritalstatus = :maritalstatus, ";

						$sql .= " education = :education, ";

						$sql .= " occupation = :occupation, ";

						$sql .= " address1 = :address1, ";

						$sql .= " address2 = :address2, ";

						$sql .= " area = :area, ";

						$sql .= " city = :city, ";

						$sql .= " state = :state, ";

						$sql .= " country = :country, ";

						$sql .= " zip = :zip, ";

						$sql .= " phone = :phone, ";

						$sql .= " mobile = :mobile, ";

						$sql .= " email = :email, ";

						$sql .= " password = :password, ";

						$sql .= " simage = :simage, ";

						$sql .= " bus_nameofcompany = :bus_nameofcompany, ";

						$sql .= " bus_designation = :bus_designation, ";

						$sql .= " bus_address1 = :bus_address1, ";

						$sql .= " bus_address2 = :bus_address2, ";

						$sql .= " bus_city = :bus_city, ";

						$sql .= " bus_state = :bus_state, ";

						$sql .= " bus_country = :bus_country, ";

						$sql .= " bus_zip = :bus_zip, ";

						$sql .= " bus_phone = :bus_phone, ";

						$sql .= " bus_website = :bus_website, ";

						$sql .= " bus_email = :bus_email, ";

						$sql .= " bus_nature = :bus_nature, ";

						$sql .= " nooffamilymembers = :nooffamilymembers, ";

						$sql .= " showcontactinfo = :showcontactinfo, ";

						$sql .= " username = :username, ";
						
						$sql .= " about_business = :about_business, ";

						$sql .= " status = :status ";

						$sql .= " Where id= :id";

						

						try{

							$stm  = $MyPdodb->prepare($sql);				

							$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

							$stm->bindParam(":fullname", $fullname, PDO::PARAM_STR);

							$stm->bindParam(":gender", $gender, PDO::PARAM_STR);

							$stm->bindParam(":bloodgroup", $bloodgroup, PDO::PARAM_STR);

							$stm->bindParam(":dob", $dob, PDO::PARAM_STR);

							$stm->bindParam(":expirydate", $expirydate, PDO::PARAM_STR);

							$stm->bindParam(":nativeplace", $nativeplace, PDO::PARAM_STR);

							$stm->bindParam(":maritalstatus", $maritalstatus, PDO::PARAM_STR);

							$stm->bindParam(":education", $education, PDO::PARAM_STR);

							$stm->bindParam(":occupation", $occupation, PDO::PARAM_STR);

							$stm->bindParam(":address1", $address1, PDO::PARAM_STR);

							$stm->bindParam(":address2", $address2, PDO::PARAM_STR);

							$stm->bindParam(":area", $area, PDO::PARAM_STR);

							$stm->bindParam(":city", $city, PDO::PARAM_STR);

							$stm->bindParam(":state", $state, PDO::PARAM_STR);

							$stm->bindParam(":country", $country, PDO::PARAM_STR);

							$stm->bindParam(":zip", $zipcode, PDO::PARAM_STR);

							$stm->bindParam(":phone", $phone, PDO::PARAM_STR);

							$stm->bindParam(":mobile", $mobile, PDO::PARAM_STR);

							$stm->bindParam(":email", $email, PDO::PARAM_STR);

							$stm->bindParam(":password", $password, PDO::PARAM_STR);

							$stm->bindParam(":simage", $homebanner_name, PDO::PARAM_STR);

							$stm->bindParam(":bus_nameofcompany", $bus_nameofcompany, PDO::PARAM_STR);

							$stm->bindParam(":bus_designation", $bus_designation, PDO::PARAM_STR);

							$stm->bindParam(":bus_address1", $bus_address1, PDO::PARAM_STR);

							$stm->bindParam(":bus_address2", $bus_address2, PDO::PARAM_STR);

							$stm->bindParam(":bus_city", $bus_city, PDO::PARAM_STR);

							$stm->bindParam(":bus_state", $bus_state, PDO::PARAM_STR);

							$stm->bindParam(":bus_country", $bus_country, PDO::PARAM_STR);

							$stm->bindParam(":bus_zip", $bus_zip, PDO::PARAM_STR);

							$stm->bindParam(":bus_phone", $bus_phone, PDO::PARAM_STR);

							$stm->bindParam(":bus_website", $bus_website, PDO::PARAM_STR);

							$stm->bindParam(":bus_email", $bus_email, PDO::PARAM_STR);

							$stm->bindParam(":bus_nature", $bus_nature, PDO::PARAM_STR);

							$stm->bindParam(":nooffamilymembers", $nooffamilymembers, PDO::PARAM_STR);

							$stm->bindParam(":showcontactinfo", $showcontactinfo, PDO::PARAM_STR);

							$stm->bindParam(":username", $username, PDO::PARAM_STR);
							$stm->bindParam(":about_business", $about_business, PDO::PARAM_STR);

							$stm->bindParam(":status", $status, PDO::PARAM_STR);

							

							$stm->bindParam(":id", $id, PDO::PARAM_INT);		

							if($stm->execute()){

									if($familyno!=$oldfamilyno){

										$sql = "update hi_family set familyno=:familyno where memberid=:id";

										try{

											$stm  = $MyPdodb->prepare($sql);				

											$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

											$stm->bindParam(":id", $id, PDO::PARAM_STR);

											$stm->execute();

										}catch(PDOException $e){

											Logger::newMessage($e);

											logger::customErrorMsg();

										}

									}

									if($approved==1){

										$subject = "JPC Membership Approved";

												$TO=$email;

												$URL = 'http://jpc.arihantseo.com/login';

												$adminMail = FrontpagesModel::create()->getSettings('MAIL_SEND_FROM_EMAIL');

												$BODY='<table width="619" border="1">

											  <tr>

												<td width="609">Dear '.$fullname.', Your Membership is approved by JPC now you can login. </td>

											  </tr>

											  

											  <tr>

												<td>URL:<a href="'.$URL.'">'.$URL.'</a></td>

											  </tr>

											  <tr>

												<td>Thank you, JPC</td>

											  </tr>

											</table>

											';

												$header="MIME-Version: 1.0\r\n";

												$header.="Content-type: text/html \r\n";

												$header .= "From: ".$adminMail." \r\n";

												

												$fname = "JPC";

												

												

												//echo $BODY;

												mail($TO,$subject,$BODY,$header);

									}

										

								$msg =CommonModel::create()->getSettings('MEMBER_EDIT_MSG');

							}else{

								$msg =CommonModel::create()->getSettings('MEMBER_EDIT_ERROR_MSG');

							}			

							

							return $msg;

						}catch(PDOException $e){

							Logger::newMessage($e);

							logger::customErrorMsg();

						}

			}else{

				$msg = 'Family Number already exists';

				return $msg;

			}

    }

	public function editRecord_family($postvars,$filevars) {

       global $MyPdodb;

	   	$id = $postvars['family_id'];

		$memberid =$postvars['member_id'];

		$fam_fullname =$postvars['fam_fullname'];

		$fam_gender =$postvars['fam_gender'];

		$fam_bloodgroup =$postvars['fam_bloodgroup'];

		$fam_dob =$postvars['fam_dob'];

		$fam_expirydate =$postvars['fam_expirydate'];

		$fam_relationwithmember =$postvars['fam_relationwithmember'];

		

		$fam_maritalstatus =$postvars['fam_maritalstatus'];

		$fam_education =$postvars['fam_education'];

		$fam_occupation =$postvars['fam_occupation'];

		$fam_nameofcompany =$postvars['fam_nameofcompany'];

		$fam_designation =$postvars['fam_designation'];

		$fam_address1 =$postvars['fam_address1'];

		$fam_address2 =$postvars['fam_address2'];

		$fam_city =$postvars['fam_city'];

		$fam_state =$postvars['fam_state'];

		$fam_country =$postvars['fam_country'];

		$fam_zip =$postvars['fam_zip'];

		$fam_phone =$postvars['fam_phone'];

		$fam_website =$postvars['fam_website'];

		$fam_email =$postvars['fam_email'];

		$fam_simage =$postvars['fam_simage'];

		$bus_nature =$postvars['bus_nature'];

		$familyno =$postvars['familyno'];

		

		

						$fam_status =$postvars['fam_status'];

						if($fam_status==''){

							$fam_status=1;

						}

						$simage =$postvars['fam_simage'];

						$tdate = date("Y-m-d");	   

						$udate = date("Y-m-d");

						$simage = $filevars['fam_simage'];

						$thumbFolder = UPLOADDIR_MEMBERS;

						$validExtArr = explode(",",VALID_EXT_MEMBERS);

						$recId = rand(1000,10000);

						$homebanner_image_old = $postvars['homebanner_image_old'];

						

					   

					   

						 if(!empty($filevars['fam_simage']['name'])){

						   $file = explode('.',basename($filevars['fam_simage']['name']));

						   $ext = ".".$file[count($file)-1];

							if(!in_array($ext,$validExtArr))

							{

								 $parentMsg=INVALID_PHOTO_MSG;

								 $product_image_name = "";

							}else{	

								$homebanner_name = "member_".$recId.".".$file[count($file)-1];

								$new_file = $thumbFolder."/".$homebanner_name;		

								$copied = copy($filevars['fam_simage']['tmp_name'], $new_file);

								@unlink($thumbFolder."/".$product_image_old);

							}

					   }else{

						   $homebanner_name=$homebanner_image_old;

					   }

								

						

						$sql = "UPDATE hi_family SET ";

						$sql .= " fam_fullname = :fam_fullname, ";

						$sql .= " fam_gender = :fam_gender, ";

						$sql .= " fam_bloodgroup = :fam_bloodgroup, ";

						$sql .= " fam_dob = :fam_dob, ";

						$sql .= " fam_relationwithmember = :fam_relationwithmember, ";

						$sql .= " fam_maritalstatus = :fam_maritalstatus, ";

						$sql .= " fam_education = :fam_education, ";

						$sql .= " fam_occupation = :fam_occupation, ";

						$sql .= " fam_nameofcompany = :fam_nameofcompany, ";

						$sql .= " fam_designation = :fam_designation, ";

						$sql .= " fam_address1 = :fam_address1, ";

						$sql .= " fam_address2 = :fam_address2, ";

						$sql .= " fam_city = :fam_city, ";

						$sql .= " fam_state = :fam_state, ";

						$sql .= " fam_country = :fam_country, ";

						$sql .= " fam_zip = :fam_zip, ";

						$sql .= " fam_phone = :fam_phone, ";

						$sql .= " fam_website = :fam_website, ";

						$sql .= " fam_email = :fam_email, ";

						$sql .= " fam_simage = :fam_simage, ";

						$sql .= " fam_expirydate = :fam_expirydate, ";

						$sql .= " bus_nature = :bus_nature, ";

						$sql .= " familyno = :familyno, ";

							$sql .= " fam_status = :fam_status ";

						$sql .= " Where id= :id";

						

						try{

							$stm  = $MyPdodb->prepare($sql);				

							$stm->bindParam(":fam_fullname", $fam_fullname, PDO::PARAM_STR);

							$stm->bindParam(":fam_gender", $fam_gender, PDO::PARAM_STR);

							$stm->bindParam(":fam_bloodgroup", $fam_bloodgroup, PDO::PARAM_STR);

							$stm->bindParam(":fam_dob", $fam_dob, PDO::PARAM_STR);

							$stm->bindParam(":fam_relationwithmember", $fam_relationwithmember, PDO::PARAM_STR);

							$stm->bindParam(":fam_maritalstatus", $fam_maritalstatus, PDO::PARAM_STR);

							$stm->bindParam(":fam_education", $fam_education, PDO::PARAM_STR);

							$stm->bindParam(":fam_occupation", $fam_occupation, PDO::PARAM_STR);

							$stm->bindParam(":fam_nameofcompany", $fam_nameofcompany, PDO::PARAM_STR);

							$stm->bindParam(":fam_designation", $fam_designation, PDO::PARAM_STR);

							$stm->bindParam(":fam_address1", $fam_address1, PDO::PARAM_STR);

							$stm->bindParam(":fam_address2", $fam_address2, PDO::PARAM_STR);

							$stm->bindParam(":fam_city", $fam_city, PDO::PARAM_STR);

							$stm->bindParam(":fam_state", $fam_state, PDO::PARAM_STR);

							$stm->bindParam(":fam_country", $fam_country, PDO::PARAM_STR);

							$stm->bindParam(":fam_zip", $fam_zip, PDO::PARAM_STR);

							$stm->bindParam(":fam_phone", $fam_phone, PDO::PARAM_STR);

							$stm->bindParam(":fam_website", $fam_website, PDO::PARAM_STR);

							$stm->bindParam(":fam_email", $fam_email, PDO::PARAM_STR);

							$stm->bindParam(":fam_simage", $homebanner_name, PDO::PARAM_STR);

							$stm->bindParam(":fam_expirydate", $fam_expirydate, PDO::PARAM_STR);

							$stm->bindParam(":bus_nature", $bus_nature, PDO::PARAM_STR);

							

							$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

							$stm->bindParam(":fam_status", $fam_status, PDO::PARAM_STR);

							

							$stm->bindParam(":id", $id, PDO::PARAM_INT);		

							if($stm->execute()){

										

								$msg =CommonModel::create()->getSettings('FAMILY_EDIT_MSG');

							}else{

								$msg =CommonModel::create()->getSettings('FAMILY_EDIT_ERROR_MSG');

							}			

							

							return $msg;

						}catch(PDOException $e){

							Logger::newMessage($e);

							logger::customErrorMsg();

						}

    }

	public function insertRecord($postvars,$filevars){

		global $MyPdodb;

		$fullname =$postvars['fullname'];

		$familyno =$postvars['familyno'];

		$gender =$postvars['gender'];

		$bloodgroup =$postvars['bloodgroup'];

		$dob =$postvars['dob'];

		if($dob==''){$dob='';}

		$expirydate =$postvars['expirydate'];

		if($expirydate==''){$expirydate='';}

		$nativeplace =$postvars['nativeplace'];

		$address1 =$postvars['address1'];

		$address2 =$postvars['address2'];

		$area =$postvars['area'];

		$city =$postvars['city'];

		$state =$postvars['state'];

		$country =$postvars['country'];

		$zipcode =$postvars['zipcode'];

		$phone =$postvars['phone'];

		$mobile =$postvars['mobile'];

		$email =$postvars['email'];

		$maritalstatus =$postvars['maritalstatus'];

		$education =$postvars['education'];

		$occupation =$postvars['occupation'];

		$bus_nameofcompany =$postvars['bus_nameofcompany'];

		$bus_designation =$postvars['bus_designation'];

		$bus_address1 =$postvars['bus_address1'];

		$bus_address2 =$postvars['bus_address2'];

		$bus_city =$postvars['bus_city'];

		$bus_state =$postvars['bus_state'];

		$bus_country =$postvars['bus_country'];

		$bus_zip =$postvars['bus_zip'];

		$bus_phone =$postvars['bus_phone'];

		$bus_website =$postvars['bus_website'];

		$bus_email =$postvars['bus_email'];

		$bus_nature =$postvars['bus_nature'];

		$nooffamilymembers =$postvars['nooffamilymembers'];

		$username =$postvars['username'];

		$renew_date =$postvars['renew_date'];
		$about_business =$postvars['about_business'];

		

		

		

			$sql = "SELECT id FROM hi_members where familyno=:familyno";        	       	  

		   	$stm  = $MyPdodb->prepare($sql);      		

			$stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

			$stm->execute();       

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$chkemail = $results[0];		

			if($chkemail->id==''){

		

						$password =$postvars['password'];

						

						$status =$postvars['status'];

						if($status==''){

							$status=0;

						}

						$simage =$postvars['simage'];

						$tdate = date("Y-m-d");	   

						$udate = date("Y-m-d");

						$simage = $filevars['simage'];

						$thumbFolder = UPLOADDIR_MEMBERS;

						$validExtArr = explode(",",VALID_EXT_MEMBERS);

						/*$recId = rand(1000,10000);*/

						if(!empty($filevars['simage']['name'])){

						   $file = explode('.',basename($filevars['simage']['name']));

						   $ext = ".".$file[count($file)-1];

							if(!in_array($ext,$validExtArr))

							{

								 $parentMsg=INVALID_PHOTO_MSG;

								 $member_name = "";

							}else{	

								$member_name = $file[count($file)-1];

								$new_file = $thumbFolder."/".$member_name;		

								$copied = copy($filevars['simage']['tmp_name'], $new_file);

							}

					   }else{

						   $member_name="";

					   }

						

						$sql = "insert into hi_members (fullname, gender, bloodgroup, dob, nativeplace, maritalstatus, education, occupation, address1, address2, area, city, state, country, zip, phone, mobile, email, password, simage, bus_nameofcompany, bus_designation, bus_address1, bus_address2, bus_city, bus_state, bus_country, bus_zip, bus_phone, bus_website, bus_email, bus_nature, status, expirydate, nooffamilymembers, username, familyno,renew_date,about_business) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						try{

							$stm  = $MyPdodb->prepare($sql);

									

							$stm->bindParam(1, $fullname, PDO::PARAM_STR);

							$stm->bindParam(2, $gender, PDO::PARAM_STR);

							$stm->bindParam(3, $bloodgroup, PDO::PARAM_STR);

							$stm->bindParam(4, $dob, PDO::PARAM_STR);

							$stm->bindParam(5, $nativeplace, PDO::PARAM_STR);

							$stm->bindParam(6, $maritalstatus, PDO::PARAM_STR);

							$stm->bindParam(7, $education, PDO::PARAM_STR);

							$stm->bindParam(8, $occupation, PDO::PARAM_STR);

							$stm->bindParam(9, $address1, PDO::PARAM_STR);

							$stm->bindParam(10, $address2, PDO::PARAM_STR);

							$stm->bindParam(11, $area, PDO::PARAM_STR);

							$stm->bindParam(12, $city, PDO::PARAM_STR);

							$stm->bindParam(13, $state, PDO::PARAM_STR);

							$stm->bindParam(14, $country, PDO::PARAM_STR);

							$stm->bindParam(15, $zipcode, PDO::PARAM_STR);

							$stm->bindParam(16, $phone, PDO::PARAM_STR);

							$stm->bindParam(17, $mobile, PDO::PARAM_STR);

							$stm->bindParam(18, $email, PDO::PARAM_STR);

							$stm->bindParam(19, $password, PDO::PARAM_STR);

							$stm->bindParam(20, $member_name, PDO::PARAM_STR);

							$stm->bindParam(21, $bus_nameofcompany, PDO::PARAM_STR);

							$stm->bindParam(22, $bus_designation, PDO::PARAM_STR);

							$stm->bindParam(23, $bus_address1, PDO::PARAM_STR);

							$stm->bindParam(24, $bus_address2, PDO::PARAM_STR);

							$stm->bindParam(25, $bus_city, PDO::PARAM_STR);

							$stm->bindParam(26, $bus_state, PDO::PARAM_STR);

							$stm->bindParam(27, $bus_country, PDO::PARAM_STR);

							$stm->bindParam(28, $bus_zip, PDO::PARAM_STR);

							$stm->bindParam(29, $bus_phone, PDO::PARAM_STR);

							$stm->bindParam(30, $bus_website, PDO::PARAM_STR);

							$stm->bindParam(31, $bus_email, PDO::PARAM_STR);

							$stm->bindParam(32, $bus_nature, PDO::PARAM_STR);

							$stm->bindParam(33, $status, PDO::PARAM_INT);

							$stm->bindParam(34, $expirydate, PDO::PARAM_STR);

							$stm->bindParam(35, $nooffamilymembers, PDO::PARAM_STR);

							$stm->bindParam(36, $username, PDO::PARAM_STR);

							$stm->bindParam(37, $familyno, PDO::PARAM_STR);

							$stm->bindParam(38, $renew_date, PDO::PARAM_STR);
							$stm->bindParam(39, $about_business, PDO::PARAM_STR);

							

								if($stm->execute()){

								$id = $MyPdodb->lastInsertId();

								$ismainmember=1;

								$fam_status=$status;

									$sql = "insert into hi_family (memberid, fam_fullname, fam_gender, fam_bloodgroup, fam_dob,  fam_maritalstatus, fam_education, fam_occupation, fam_nameofcompany, fam_designation, fam_address1, fam_address2, fam_city, fam_state, fam_country, fam_zip, fam_status, fam_phone, fam_website, fam_email, fam_simage, familyno, ismainmember,fam_expirydate) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

																	try{

																		$stm  = $MyPdodb->prepare($sql);

																				

																		$stm->bindParam(1, $id, PDO::PARAM_STR);

																		$stm->bindParam(2, $fullname, PDO::PARAM_STR);

																		$stm->bindParam(3, $gender, PDO::PARAM_STR);

																		$stm->bindParam(4, $bloodgroup, PDO::PARAM_STR);

																		$stm->bindParam(5, $dob, PDO::PARAM_STR);

																		$stm->bindParam(6, $maritalstatus, PDO::PARAM_STR);

																		$stm->bindParam(7, $education, PDO::PARAM_STR);

																		$stm->bindParam(8, $occupation, PDO::PARAM_STR);

																		$stm->bindParam(9, $bus_nameofcompany, PDO::PARAM_STR);

																		$stm->bindParam(10, $bus_designation, PDO::PARAM_STR);

																		$stm->bindParam(11, $bus_address1, PDO::PARAM_STR);

																		$stm->bindParam(12, $bus_address2, PDO::PARAM_STR);

																		$stm->bindParam(13, $bus_city, PDO::PARAM_STR);

																		$stm->bindParam(14, $bus_state, PDO::PARAM_STR);

																		$stm->bindParam(15, $bus_country, PDO::PARAM_STR);

																		$stm->bindParam(16, $bus_zip, PDO::PARAM_STR);

																		$stm->bindParam(17, $fam_status, PDO::PARAM_STR);

																		$stm->bindParam(18, $bus_phone, PDO::PARAM_STR);

																		$stm->bindParam(19, $bus_website, PDO::PARAM_STR);

																		$stm->bindParam(20, $bus_email, PDO::PARAM_STR);

																		$stm->bindParam(21, $simage, PDO::PARAM_STR);

																		$stm->bindParam(22, $familyno, PDO::PARAM_STR);

																		$stm->bindParam(23, $ismainmember, PDO::PARAM_STR);

																		$stm->bindParam(24, $expirydate, PDO::PARAM_STR);

																		

																		

																			if($stm->execute()){

																				

																				$msg =CommonModel::create()->getSettings('FAMILY_INSERT_MSG');

																			}else{

																				$msg =CommonModel::create()->getSettings('FAMILY_INSERT_ERROR_MSG');

																			}	

																	}catch(PDOException $e){

																				Logger::newMessage($e);

																				logger::customErrorMsg();

																	}

									$msg =CommonModel::create()->getSettings('MEMBER_INSERT_MSG');

								}else{

									$msg =CommonModel::create()->getSettings('MEMBER_INSERT_ERROR_MSG');

								}	

								return $msg;

						}catch(PDOException $e){

									Logger::newMessage($e);

									logger::customErrorMsg();

						}

		}else{

			$msg = 'Family Number already exists';

			return $msg;

		}

	}

	public function insertRecord_family($postvars,$filevars){

		global $MyPdodb;

		$memberid =$postvars['member_id'];

		if($memberid==''){

			$memberid = $_SESSION["member_id"];

		}

		$fam_fullname =$postvars['fam_fullname'];

		$fam_gender =$postvars['fam_gender'];

		$fam_bloodgroup =$postvars['fam_bloodgroup'];

		$fam_dob =$postvars['fam_dob'];

		$fam_expirydate =$postvars['fam_expirydate'];

		$fam_relationwithmember =$postvars['fam_relationwithmember'];

		

		$fam_maritalstatus =$postvars['fam_maritalstatus'];

		$fam_education =$postvars['fam_education'];

		$fam_occupation =$postvars['fam_occupation'];

		$fam_nameofcompany =$postvars['fam_nameofcompany'];

		$fam_designation =$postvars['fam_designation'];

		$fam_address1 =$postvars['fam_address1'];

		$fam_address2 =$postvars['fam_address2'];

		$fam_city =$postvars['fam_city'];

		$fam_state =$postvars['fam_state'];

		$fam_country =$postvars['fam_country'];

		$fam_zip =$postvars['fam_zip'];

		$fam_phone =$postvars['fam_phone'];

		$fam_website =$postvars['fam_website'];

		$fam_email =$postvars['fam_email'];

		$fam_simage =$postvars['fam_simage'];

		$bus_nature =$postvars['bus_nature'];

		$familyno =$postvars['familyno'];

		

		

						$fam_status =$postvars['fam_status'];

						if($fam_status==''){

							$fam_status=0;

						}

						$tdate = date("Y-m-d");	   

						$udate = date("Y-m-d");

						$simage = $filevars['fam_simage'];

						$thumbFolder = UPLOADDIR_MEMBERS;

						$validExtArr = explode(",",VALID_EXT_MEMBERS);

						$recId = rand(1000,10000);

						if(!empty($filevars['fam_simage']['name'])){

						   $file = explode('.',basename($filevars['fam_simage']['name']));

						   $ext = ".".$file[count($file)-1];

							if(!in_array($ext,$validExtArr))

							{

								 $parentMsg=INVALID_PHOTO_MSG;

								 $member_name = "";

							}else{	

								$member_name = "member_".$recId.".".$file[count($file)-1];

								$new_file = $thumbFolder."/".$member_name;		

								$copied = copy($filevars['fam_simage']['tmp_name'], $new_file);

							}

					   }else{

						   $member_name="";

					   }

						

						$sql = "insert into hi_family (memberid, fam_fullname, fam_gender, fam_bloodgroup, fam_dob, fam_relationwithmember, fam_maritalstatus, fam_education, fam_occupation, fam_nameofcompany, fam_designation, fam_address1, fam_address2, fam_city, fam_state, fam_country, fam_zip, fam_phone, fam_website, fam_email, fam_simage, fam_status,fam_expirydate, bus_nature,familyno) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

						try{

							$stm  = $MyPdodb->prepare($sql);

									

							$stm->bindParam(1, $memberid, PDO::PARAM_STR);

							$stm->bindParam(2, $fam_fullname, PDO::PARAM_STR);

							$stm->bindParam(3, $fam_gender, PDO::PARAM_STR);

							$stm->bindParam(4, $fam_bloodgroup, PDO::PARAM_STR);

							$stm->bindParam(5, $fam_dob, PDO::PARAM_STR);

							$stm->bindParam(6, $fam_relationwithmember, PDO::PARAM_STR);

							$stm->bindParam(7, $fam_maritalstatus, PDO::PARAM_STR);

							$stm->bindParam(8, $fam_education, PDO::PARAM_STR);

							$stm->bindParam(9, $fam_occupation, PDO::PARAM_STR);

							$stm->bindParam(10, $fam_nameofcompany, PDO::PARAM_STR);

							$stm->bindParam(11, $fam_designation, PDO::PARAM_STR);

							$stm->bindParam(12, $fam_address1, PDO::PARAM_STR);

							$stm->bindParam(13, $fam_address2, PDO::PARAM_STR);

							$stm->bindParam(14, $fam_city, PDO::PARAM_STR);

							$stm->bindParam(15, $fam_state, PDO::PARAM_STR);

							$stm->bindParam(16, $fam_country, PDO::PARAM_STR);

							$stm->bindParam(17, $fam_zip, PDO::PARAM_STR);

							$stm->bindParam(18, $fam_phone, PDO::PARAM_STR);

							$stm->bindParam(19, $fam_website, PDO::PARAM_STR);

							$stm->bindParam(20, $fam_email, PDO::PARAM_STR);

							$stm->bindParam(21, $member_name, PDO::PARAM_STR);

							$stm->bindParam(22, $fam_status, PDO::PARAM_STR);

							$stm->bindParam(23, $fam_expirydate, PDO::PARAM_STR);

							$stm->bindParam(24, $bus_nature, PDO::PARAM_STR);

							$stm->bindParam(27, $familyno, PDO::PARAM_STR);

							

							

								if($stm->execute()){

									$msg =CommonModel::create()->getSettings('FAMILY_INSERT_MSG');

								}else{

									$msg =CommonModel::create()->getSettings('FAMILY_INSERT_ERROR_MSG');

								}	

								return $msg;

						}catch(PDOException $e){

									Logger::newMessage($e);

									logger::customErrorMsg();

						}

	}

	public function importRecord(){

		global $MyPdodb;

		$file_nm = $_FILES['ufile']['name'];	

		$thumbFolder = UPLOADDIR_MEMBERS_IMPORT;

		$validExtArr = explode(",",VALID_EXT_MEMBERS_IMPORT);

		$new_file = $thumbFolder."/".$member_name;

		$filepath='./xls_file/'.$file_nm;

		

		$file = explode('.',basename($_FILES['ufile']['name']));

		   $ext = ".".$file[count($file)-1];

			if(!in_array($ext,$validExtArr))

			{

			 	 $parentMsg=INVALID_PHOTO_MSG;

				 $member_name = "";

			}else{	

				$member_name = "member_".$recId.".".$file[count($file)-1];

				$new_file = $thumbFolder."/".$member_name;		

				$copied = copy($_FILES['ufile']['tmp_name'], $new_file);

				require_once 'utility/reader.php';

				$data = new Spreadsheet_Excel_Reader();

				$data->read($new_file); 

				$k=0;

				for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) 

				{

						$familyno = trim($data->sheets[0]['cells'][$i][1],' ');

						$fullname = trim($data->sheets[0]['cells'][$i][2],' ');

						$gender = trim($data->sheets[0]['cells'][$i][3],' ');

						if($gender=="M"){

							$gender = "Male";

						}else if($gender=="F"){

							$gender = "Female";

						}

						$bloodgroup =trim($data->sheets[0]['cells'][$i][4],' ');

						if($data->sheets[0]['cells'][$i][5]!=''){

							$dob =date('Y-m-d',strtotime($data->sheets[0]['cells'][$i][5]));

						}else{

							$dob = '';

						}

						$nativeplace = trim($data->sheets[0]['cells'][$i][6],' ');

						$maritalstatus = trim($data->sheets[0]['cells'][$i][7],' ');

						

						$address1 = trim($data->sheets[0]['cells'][$i][8],' ');

						$address2 = trim($data->sheets[0]['cells'][$i][9],' ');

						$area = trim($data->sheets[0]['cells'][$i][10],' ');

						$city = trim($data->sheets[0]['cells'][$i][11],' ');

						$state = trim($data->sheets[0]['cells'][$i][12],' ');

						if($fullname!=''){

						$country = trim($data->sheets[0]['cells'][$i][13],' ');

						if(trim($country,' ')!=''){

							$sql = "SELECT id,name FROM hi_countries where name=:name";        	       	  

							   $stm  = $MyPdodb->prepare($sql);      		

								$stm->bindParam(':name', $country, PDO::PARAM_STR);

								$stm->execute();       

								$results = $stm->fetchAll(PDO::FETCH_CLASS);	

								$countryname = $results[0];		

								$countryid=$countryname->id;

								$status=1;

								if($countryname->name==''){

									$sql = "insert into hi_countries (name, status) values (?,?)";

										try{

											$stm  = $MyPdodb->prepare($sql);

													

											$stm->bindParam(1, $country, PDO::PARAM_STR);

											$stm->bindParam(2, $status, PDO::PARAM_INT);

												if($stm->execute()){

													$countryid = $MyPdodb->lastInsertId();

												}

										}catch(PDOException $e){

													Logger::newMessage($e);

													logger::customErrorMsg();

										}

								}

						}else{

							$countryid = 0;

						}

						$zip =trim($data->sheets[0]['cells'][$i][14],' ');

						$phone =trim($data->sheets[0]['cells'][$i][15],' ');

						$mobile =trim($data->sheets[0]['cells'][$i][16],' ');

						

						

						$email =trim($data->sheets[0]['cells'][$i][17],' ');

						$simage =trim($data->sheets[0]['cells'][$i][18],' ');

						$education = trim($data->sheets[0]['cells'][$i][19],' ');

						$occupation = trim($data->sheets[0]['cells'][$i][20],' ');

						$bus_nameofcompany =trim($data->sheets[0]['cells'][$i][21],' ');

						$bus_designation =trim($data->sheets[0]['cells'][$i][22],' ');

						$bus_address1 =trim($data->sheets[0]['cells'][$i][23],' ');

						$bus_address2 =trim($data->sheets[0]['cells'][$i][24],' ');

						$bus_city =trim($data->sheets[0]['cells'][$i][25],' ');

						$bus_state =trim($data->sheets[0]['cells'][$i][26],' ');

						$bus_country =trim($data->sheets[0]['cells'][$i][27],' ');

						$bus_zip =trim($data->sheets[0]['cells'][$i][28],' ');

						$bus_phone =trim($data->sheets[0]['cells'][$i][29],' ');

						$bus_website =trim($data->sheets[0]['cells'][$i][30],' ');

						$bus_email =trim($data->sheets[0]['cells'][$i][31],' ');

						$bus_nature =trim($data->sheets[0]['cells'][$i][32],' ');

						

						$nooffamilymembers =trim($data->sheets[0]['cells'][$i][33],' ');

						$expirydate =trim($data->sheets[0]['cells'][$i][34],' ');

						$renew_date =trim($data->sheets[0]['cells'][$i][35],' ');

						//$status = 1;

						$status = trim($data->sheets[0]['cells'][$i][36],' ');

						$sql = "SELECT id FROM hi_members where familyno= :familyno";   

						 try{

								 $stm  = $MyPdodb->prepare($sql);      		  

								 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

								 

								$stm->execute();

								$results = $stm->fetchAll(PDO::FETCH_CLASS);

								$id = $results[0]->id;	

								

								

								 if($id!=''){

									 	$sql = "UPDATE hi_members SET ";

										$sql .= " familyno = :familyno, ";

										$sql .= " fullname = :fullname, ";

										$sql .= " gender = :gender, ";

										$sql .= " bloodgroup = :bloodgroup, ";

										$sql .= " dob = :dob, ";

										$sql .= " expirydate = :expirydate, ";

										$sql .= " nativeplace = :nativeplace, ";

										$sql .= " maritalstatus = :maritalstatus, ";

										$sql .= " education = :education, ";

										$sql .= " occupation = :occupation, ";

										$sql .= " address1 = :address1, ";

										$sql .= " address2 = :address2, ";

										$sql .= " area = :area, ";

										$sql .= " city = :city, ";

										$sql .= " state = :state, ";

										$sql .= " country = :country, ";

										$sql .= " zip = :zip, ";

										$sql .= " phone = :phone, ";

										$sql .= " mobile = :mobile, ";

										$sql .= " email = :email, ";

										$sql .= " simage = :simage, ";

										$sql .= " bus_nameofcompany = :bus_nameofcompany, ";

										$sql .= " bus_designation = :bus_designation, ";

										$sql .= " bus_address1 = :bus_address1, ";

										$sql .= " bus_address2 = :bus_address2, ";

										$sql .= " bus_city = :bus_city, ";

										$sql .= " bus_state = :bus_state, ";

										$sql .= " bus_country = :bus_country, ";

										$sql .= " bus_zip = :bus_zip, ";

										$sql .= " bus_phone = :bus_phone, ";

										$sql .= " bus_website = :bus_website, ";

										$sql .= " bus_email = :bus_email, ";

										$sql .= " bus_nature = :bus_nature, ";

										$sql .= " nooffamilymembers = :nooffamilymembers, ";

										$sql .= " renew_date = :renew_date, ";

										$sql .= " status = :status ";

										$sql .= " Where id= :id";

										

										try{

											$stm  = $MyPdodb->prepare($sql);				

											$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

											$stm->bindParam(":fullname", $fullname, PDO::PARAM_STR);

											$stm->bindParam(":gender", $gender, PDO::PARAM_STR);

											$stm->bindParam(":bloodgroup", $bloodgroup, PDO::PARAM_STR);

											$stm->bindParam(":dob", $dob, PDO::PARAM_STR);

											$stm->bindParam(":expirydate", $expirydate, PDO::PARAM_STR);

											$stm->bindParam(":nativeplace", $nativeplace, PDO::PARAM_STR);

											$stm->bindParam(":maritalstatus", $maritalstatus, PDO::PARAM_STR);

											$stm->bindParam(":education", $education, PDO::PARAM_STR);

											$stm->bindParam(":occupation", $occupation, PDO::PARAM_STR);

											$stm->bindParam(":address1", $address1, PDO::PARAM_STR);

											$stm->bindParam(":address2", $address2, PDO::PARAM_STR);

											$stm->bindParam(":area", $area, PDO::PARAM_STR);

											$stm->bindParam(":city", $city, PDO::PARAM_STR);

											$stm->bindParam(":state", $state, PDO::PARAM_STR);

											$stm->bindParam(":country", $country, PDO::PARAM_STR);

											$stm->bindParam(":zip", $zip, PDO::PARAM_STR);

											$stm->bindParam(":phone", $phone, PDO::PARAM_STR);

											$stm->bindParam(":mobile", $mobile, PDO::PARAM_STR);

											$stm->bindParam(":email", $email, PDO::PARAM_STR);

											$stm->bindParam(":simage", $simage, PDO::PARAM_STR);

											$stm->bindParam(":bus_nameofcompany", $bus_nameofcompany, PDO::PARAM_STR);

											$stm->bindParam(":bus_designation", $bus_designation, PDO::PARAM_STR);

											$stm->bindParam(":bus_address1", $bus_address1, PDO::PARAM_STR);

											$stm->bindParam(":bus_address2", $bus_address2, PDO::PARAM_STR);

											$stm->bindParam(":bus_city", $bus_city, PDO::PARAM_STR);

											$stm->bindParam(":bus_state", $bus_state, PDO::PARAM_STR);

											$stm->bindParam(":bus_country", $bus_country, PDO::PARAM_STR);

											$stm->bindParam(":bus_zip", $bus_zip, PDO::PARAM_STR);

											$stm->bindParam(":bus_phone", $bus_phone, PDO::PARAM_STR);

											$stm->bindParam(":bus_website", $bus_website, PDO::PARAM_STR);

											$stm->bindParam(":bus_email", $bus_email, PDO::PARAM_STR);

											$stm->bindParam(":bus_nature", $bus_nature, PDO::PARAM_STR);

											$stm->bindParam(":nooffamilymembers", $nooffamilymembers, PDO::PARAM_STR);

											$stm->bindParam(":renew_date", $renew_date, PDO::PARAM_STR);

											$stm->bindParam(":status", $status, PDO::PARAM_STR);

											$stm->bindParam(":id", $id, PDO::PARAM_INT);		

											if($stm->execute()){

												

												//insert or update in family for this member

												$fam_status = 1;

												$sql = "SELECT id FROM hi_family where fam_fullname= :fam_fullname and familyno=:familyno";   

												 try{

														 $stm  = $MyPdodb->prepare($sql);      		  

														 $stm->bindParam(':fam_fullname', $fullname, PDO::PARAM_STR);

														 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

														 

														$stm->execute();

														$results = $stm->fetchAll(PDO::FETCH_CLASS);

														$familyid = $results[0]->id;	

														$relationwithmember = "Self";

														$ismainmember = 1;	

														 if($familyid!=''){

																$sql = "UPDATE hi_family SET ";

																$sql .= " memberid = :memberid, ";

																$sql .= " fam_fullname = :fam_fullname, ";

																$sql .= " fam_gender = :fam_gender, ";

																$sql .= " fam_bloodgroup = :fam_bloodgroup, ";

																$sql .= " fam_dob = :fam_dob, ";

																$sql .= " fam_relationwithmember = :fam_relationwithmember, ";

																$sql .= " fam_maritalstatus = :fam_maritalstatus, ";

																$sql .= " fam_education = :fam_education, ";

																$sql .= " fam_occupation = :fam_occupation, ";

																$sql .= " fam_nameofcompany = :fam_nameofcompany, ";

																$sql .= " fam_designation = :fam_designation, ";

																$sql .= " fam_address1 = :fam_address1, ";

																$sql .= " fam_address2 = :fam_address2, ";

																$sql .= " fam_city = :fam_city, ";

																$sql .= " fam_state = :fam_state, ";

																$sql .= " fam_country = :fam_country, ";

																$sql .= " fam_zip = :fam_zip, ";

																$sql .= " fam_phone = :fam_phone, ";

																$sql .= " fam_website = :fam_website, ";

																$sql .= " fam_email = :fam_email, ";

																$sql .= " fam_simage = :fam_simage, ";

																$sql .= " familyno = :familyno, ";

																$sql .= " ismainmember = :ismainmember, ";

																

																	$sql .= " fam_status = :fam_status ";

																$sql .= " Where id= :id";

																

																try{

																

																	$stm  = $MyPdodb->prepare($sql);				

																	$stm->bindParam(":memberid", $id, PDO::PARAM_STR);

																	$stm->bindParam(":fam_fullname", $fullname, PDO::PARAM_STR);

																	$stm->bindParam(":fam_gender", $gender, PDO::PARAM_STR);

																	$stm->bindParam(":fam_bloodgroup", $bloodgroup, PDO::PARAM_STR);

																	$stm->bindParam(":fam_dob", $dob, PDO::PARAM_STR);

																	$stm->bindParam(":fam_relationwithmember", $relationwithmember, PDO::PARAM_STR);

																	$stm->bindParam(":fam_maritalstatus", $maritalstatus, PDO::PARAM_STR);

																	$stm->bindParam(":fam_education", $education, PDO::PARAM_STR);

																	$stm->bindParam(":fam_occupation", $occupation, PDO::PARAM_STR);

																	$stm->bindParam(":fam_nameofcompany", $bus_nameofcompany, PDO::PARAM_STR);

																	$stm->bindParam(":fam_designation", $bus_designation, PDO::PARAM_STR);

																	$stm->bindParam(":fam_address1", $bus_address1, PDO::PARAM_STR);

																	$stm->bindParam(":fam_address2", $bus_address2, PDO::PARAM_STR);

																	$stm->bindParam(":fam_city", $bus_city, PDO::PARAM_STR);

																	$stm->bindParam(":fam_state", $bus_state, PDO::PARAM_STR);

																	$stm->bindParam(":fam_country", $bus_country, PDO::PARAM_STR);

																	$stm->bindParam(":fam_zip", $bus_zip, PDO::PARAM_STR);

																	$stm->bindParam(":fam_phone", $bus_phone, PDO::PARAM_STR);

																	$stm->bindParam(":fam_website", $bus_website, PDO::PARAM_STR);

																	$stm->bindParam(":fam_email", $bus_email, PDO::PARAM_STR);

																	$stm->bindParam(":fam_simage", $simage, PDO::PARAM_STR);

																	$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

																	$stm->bindParam(":fam_status", $fam_status, PDO::PARAM_STR);

																	$stm->bindParam(":ismainmember", $ismainmember, PDO::PARAM_STR);

																	$stm->bindParam(":id", $familyid, PDO::PARAM_INT);		

																	if($stm->execute()){

																		$sql = "update hi_family set ismainmember=0 where familyno=:familyno and id!=:familyid";

																		$stm  = $MyPdodb->prepare($sql);      		  

																		 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

																		 $stm->bindParam(':familyid', $familyid, PDO::PARAM_STR);

																		 

																		 $stm->execute();

																				

																		$msg =CommonModel::create()->getSettings('FAMILY_EDIT_MSG');

																	}else{

																		$msg =CommonModel::create()->getSettings('FAMILY_EDIT_ERROR_MSG');

																	}	

																	}catch(PDOException $e){

																				Logger::newMessage($e);

																				logger::customErrorMsg();

																	}

														 }else{

																

																	$sql = "insert into hi_family (memberid, fam_fullname, fam_gender, fam_bloodgroup, fam_dob, fam_relationwithmember, fam_maritalstatus, fam_education, fam_occupation, fam_nameofcompany, fam_designation, fam_address1, fam_address2, fam_city, fam_state, fam_country, fam_zip, fam_status, fam_phone, fam_website, fam_email, fam_simage, familyno, ismainmember) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

																	try{

																		$stm  = $MyPdodb->prepare($sql);

																				

																		$stm->bindParam(1, $id, PDO::PARAM_STR);

																		$stm->bindParam(2, $fullname, PDO::PARAM_STR);

																		$stm->bindParam(3, $gender, PDO::PARAM_STR);

																		$stm->bindParam(4, $bloodgroup, PDO::PARAM_STR);

																		$stm->bindParam(5, $dob, PDO::PARAM_STR);

																		$stm->bindParam(6, $relationwithmember, PDO::PARAM_STR);

																		$stm->bindParam(7, $maritalstatus, PDO::PARAM_STR);

																		$stm->bindParam(8, $education, PDO::PARAM_STR);

																		$stm->bindParam(9, $occupation, PDO::PARAM_STR);

																		$stm->bindParam(10, $bus_nameofcompany, PDO::PARAM_STR);

																		$stm->bindParam(11, $bus_designation, PDO::PARAM_STR);

																		$stm->bindParam(12, $bus_address1, PDO::PARAM_STR);

																		$stm->bindParam(13, $bus_address2, PDO::PARAM_STR);

																		$stm->bindParam(14, $bus_city, PDO::PARAM_STR);

																		$stm->bindParam(15, $bus_state, PDO::PARAM_STR);

																		$stm->bindParam(16, $bus_country, PDO::PARAM_STR);

																		$stm->bindParam(17, $bus_zip, PDO::PARAM_STR);

																		$stm->bindParam(18, $fam_status, PDO::PARAM_STR);

																		$stm->bindParam(19, $bus_phone, PDO::PARAM_STR);

																		$stm->bindParam(20, $bus_website, PDO::PARAM_STR);

																		$stm->bindParam(21, $bus_email, PDO::PARAM_STR);

																		$stm->bindParam(22, $simage, PDO::PARAM_STR);

																		$stm->bindParam(23, $familyno, PDO::PARAM_STR);

																		$stm->bindParam(24, $ismainmember, PDO::PARAM_STR);

																		

																		

																			if($stm->execute()){

																				$familyid = $MyPdodb->lastInsertId();

																				$sql = "update hi_family set ismainmember=0 where familyno=:familyno and id!=:familyid";

																				$stm  = $MyPdodb->prepare($sql);      		  

																				 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

																				 $stm->bindParam(':familyid', $familyid, PDO::PARAM_STR);

																				 

																				 $stm->execute();

																				$msg =CommonModel::create()->getSettings('FAMILY_INSERT_MSG');

																			}else{

																				$msg =CommonModel::create()->getSettings('FAMILY_INSERT_ERROR_MSG');

																			}	

																	}catch(PDOException $e){

																				Logger::newMessage($e);

																				logger::customErrorMsg();

																	}

														 }

														$msg = 'Members Imported';		

													}catch(PDOException $e){

															Logger::newMessage($e);

															logger::customErrorMsg();

													}

												//insert or update in family for this member

												

														

												$msg =CommonModel::create()->getSettings('MEMBER_EDIT_MSG');

											}else{

												$msg =CommonModel::create()->getSettings('MEMBER_EDIT_ERROR_MSG');

											}	

											}catch(PDOException $e){

														Logger::newMessage($e);

														logger::customErrorMsg();

											}

								 }else{

										$username = $this->randomuser();

										$password = $this->randompassword();

										$relationwithmember = "Self";

										$ismainmember = 1;	

											$sql = "insert into hi_members (fullname, gender, bloodgroup, dob, nativeplace, maritalstatus, education, occupation, address1, address2, area, city, state, country, zip, phone, mobile, email, simage, bus_nameofcompany, bus_designation, bus_address1, bus_address2, bus_city, bus_state, bus_country, bus_zip, bus_phone, bus_website, bus_email, bus_nature, status, expirydate, nooffamilymembers, username, password, familyno,renew_date) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

											try{

												$stm  = $MyPdodb->prepare($sql);

														

												$stm->bindParam(1, $fullname, PDO::PARAM_STR);

												$stm->bindParam(2, $gender, PDO::PARAM_STR);

												$stm->bindParam(3, $bloodgroup, PDO::PARAM_STR);

												$stm->bindParam(4, $dob, PDO::PARAM_STR);

												$stm->bindParam(5, $nativeplace, PDO::PARAM_STR);

												$stm->bindParam(6, $maritalstatus, PDO::PARAM_STR);

												$stm->bindParam(7, $education, PDO::PARAM_STR);

												$stm->bindParam(8, $occupation, PDO::PARAM_STR);

												$stm->bindParam(9, $address1, PDO::PARAM_STR);

												$stm->bindParam(10, $address2, PDO::PARAM_STR);

												$stm->bindParam(11, $area, PDO::PARAM_STR);

												$stm->bindParam(12, $city, PDO::PARAM_STR);

												$stm->bindParam(13, $state, PDO::PARAM_STR);

												$stm->bindParam(14, $country, PDO::PARAM_STR);

												$stm->bindParam(15, $zip, PDO::PARAM_STR);

												$stm->bindParam(16, $phone, PDO::PARAM_STR);

												$stm->bindParam(17, $mobile, PDO::PARAM_STR);

												$stm->bindParam(18, $email, PDO::PARAM_STR);

												$stm->bindParam(19, $simage, PDO::PARAM_STR);

												$stm->bindParam(20, $bus_nameofcompany, PDO::PARAM_STR);

												$stm->bindParam(21, $bus_designation, PDO::PARAM_STR);

												$stm->bindParam(22, $bus_address1, PDO::PARAM_STR);

												$stm->bindParam(23, $bus_address2, PDO::PARAM_STR);

												$stm->bindParam(24, $bus_city, PDO::PARAM_STR);

												$stm->bindParam(25, $bus_state, PDO::PARAM_STR);

												$stm->bindParam(26, $bus_country, PDO::PARAM_STR);

												$stm->bindParam(27, $bus_zip, PDO::PARAM_STR);

												$stm->bindParam(28, $bus_phone, PDO::PARAM_STR);

												$stm->bindParam(29, $bus_website, PDO::PARAM_STR);

												$stm->bindParam(30, $bus_email, PDO::PARAM_STR);

												$stm->bindParam(31, $bus_nature, PDO::PARAM_STR);

												$stm->bindParam(32, $status, PDO::PARAM_INT);

												$stm->bindParam(33, $expirydate, PDO::PARAM_STR);

												$stm->bindParam(34, $nooffamilymembers, PDO::PARAM_STR);

												$stm->bindParam(35, $username, PDO::PARAM_STR);

												$stm->bindParam(36, $password, PDO::PARAM_STR);

												$stm->bindParam(37, $familyno, PDO::PARAM_STR);

												$stm->bindParam(38, $renew_date, PDO::PARAM_STR);

												

													if($stm->execute()){

														$id = $MyPdodb->lastInsertId();

														//insert or update in family for this member

														$fam_status = 1;

														$sql = "SELECT id FROM hi_family where fam_fullname= :fam_fullname and familyno=:familyno";   

														 try{

																 $stm  = $MyPdodb->prepare($sql);      		  

																 $stm->bindParam(':fam_fullname', $fullname, PDO::PARAM_STR);

																 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

																 

																$stm->execute();

																$results = $stm->fetchAll(PDO::FETCH_CLASS);

																$familyid = $results[0]->id;	

																$relationwithmember = "Self";

																$ismainmember = 1;	

																 if($familyid!=''){

																		$sql = "UPDATE hi_family SET ";

																		$sql .= " memberid = :memberid, ";

																		$sql .= " fam_fullname = :fam_fullname, ";

																		$sql .= " fam_gender = :fam_gender, ";

																		$sql .= " fam_bloodgroup = :fam_bloodgroup, ";

																		$sql .= " fam_dob = :fam_dob, ";

																		$sql .= " fam_relationwithmember = :fam_relationwithmember, ";

																		$sql .= " fam_maritalstatus = :fam_maritalstatus, ";

																		$sql .= " fam_education = :fam_education, ";

																		$sql .= " fam_occupation = :fam_occupation, ";

																		$sql .= " fam_nameofcompany = :fam_nameofcompany, ";

																		$sql .= " fam_designation = :fam_designation, ";

																		$sql .= " fam_address1 = :fam_address1, ";

																		$sql .= " fam_address2 = :fam_address2, ";

																		$sql .= " fam_city = :fam_city, ";

																		$sql .= " fam_state = :fam_state, ";

																		$sql .= " fam_country = :fam_country, ";

																		$sql .= " fam_zip = :fam_zip, ";

																		$sql .= " fam_phone = :fam_phone, ";

																		$sql .= " fam_website = :fam_website, ";

																		$sql .= " fam_email = :fam_email, ";

																		$sql .= " fam_simage = :fam_simage, ";

																		$sql .= " familyno = :familyno, ";

																		$sql .= " ismainmember = :ismainmember, ";

																		

																			$sql .= " fam_status = :fam_status ";

																		$sql .= " Where id= :id";

																		

																		try{

																		

																			$stm  = $MyPdodb->prepare($sql);				

																			$stm->bindParam(":memberid", $id, PDO::PARAM_STR);

																			$stm->bindParam(":fam_fullname", $fullname, PDO::PARAM_STR);

																			$stm->bindParam(":fam_gender", $gender, PDO::PARAM_STR);

																			$stm->bindParam(":fam_bloodgroup", $bloodgroup, PDO::PARAM_STR);

																			$stm->bindParam(":fam_dob", $dob, PDO::PARAM_STR);

																			$stm->bindParam(":fam_relationwithmember", $relationwithmember, PDO::PARAM_STR);

																			$stm->bindParam(":fam_maritalstatus", $maritalstatus, PDO::PARAM_STR);

																			$stm->bindParam(":fam_education", $education, PDO::PARAM_STR);

																			$stm->bindParam(":fam_occupation", $occupation, PDO::PARAM_STR);

																			$stm->bindParam(":fam_nameofcompany", $bus_nameofcompany, PDO::PARAM_STR);

																			$stm->bindParam(":fam_designation", $bus_designation, PDO::PARAM_STR);

																			$stm->bindParam(":fam_address1", $bus_address1, PDO::PARAM_STR);

																			$stm->bindParam(":fam_address2", $bus_address2, PDO::PARAM_STR);

																			$stm->bindParam(":fam_city", $bus_city, PDO::PARAM_STR);

																			$stm->bindParam(":fam_state", $bus_state, PDO::PARAM_STR);

																			$stm->bindParam(":fam_country", $bus_country, PDO::PARAM_STR);

																			$stm->bindParam(":fam_zip", $bus_zip, PDO::PARAM_STR);

																			$stm->bindParam(":fam_phone", $bus_phone, PDO::PARAM_STR);

																			$stm->bindParam(":fam_website", $bus_website, PDO::PARAM_STR);

																			$stm->bindParam(":fam_email", $bus_email, PDO::PARAM_STR);

																			$stm->bindParam(":fam_simage", $simage, PDO::PARAM_STR);

																			$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

																			$stm->bindParam(":fam_status", $fam_status, PDO::PARAM_STR);

																			$stm->bindParam(":ismainmember", $ismainmember, PDO::PARAM_STR);

																			$stm->bindParam(":id", $familyid, PDO::PARAM_INT);		

																			if($stm->execute()){

																				

																						

																				$msg =CommonModel::create()->getSettings('FAMILY_EDIT_MSG');

																			}else{

																				$msg =CommonModel::create()->getSettings('FAMILY_EDIT_ERROR_MSG');

																			}	

																			}catch(PDOException $e){

																						Logger::newMessage($e);

																						logger::customErrorMsg();

																			}

																 }else{

																		

																			$sql = "insert into hi_family (memberid, fam_fullname, fam_gender, fam_bloodgroup, fam_dob, fam_relationwithmember, fam_maritalstatus, fam_education, fam_occupation, fam_nameofcompany, fam_designation, fam_address1, fam_address2, fam_city, fam_state, fam_country, fam_zip, fam_status, fam_phone, fam_website, fam_email, fam_simage, familyno, ismainmember) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

																			try{

																				$stm  = $MyPdodb->prepare($sql);

																						

																				$stm->bindParam(1, $id, PDO::PARAM_STR);

																				$stm->bindParam(2, $fullname, PDO::PARAM_STR);

																				$stm->bindParam(3, $gender, PDO::PARAM_STR);

																				$stm->bindParam(4, $bloodgroup, PDO::PARAM_STR);

																				$stm->bindParam(5, $dob, PDO::PARAM_STR);

																				$stm->bindParam(6, $relationwithmember, PDO::PARAM_STR);

																				$stm->bindParam(7, $maritalstatus, PDO::PARAM_STR);

																				$stm->bindParam(8, $education, PDO::PARAM_STR);

																				$stm->bindParam(9, $occupation, PDO::PARAM_STR);

																				$stm->bindParam(10, $bus_nameofcompany, PDO::PARAM_STR);

																				$stm->bindParam(11, $bus_designation, PDO::PARAM_STR);

																				$stm->bindParam(12, $bus_address1, PDO::PARAM_STR);

																				$stm->bindParam(13, $bus_address2, PDO::PARAM_STR);

																				$stm->bindParam(14, $bus_city, PDO::PARAM_STR);

																				$stm->bindParam(15, $bus_state, PDO::PARAM_STR);

																				$stm->bindParam(16, $bus_country, PDO::PARAM_STR);

																				$stm->bindParam(17, $bus_zip, PDO::PARAM_STR);

																				$stm->bindParam(18, $fam_status, PDO::PARAM_STR);

																				$stm->bindParam(19, $bus_phone, PDO::PARAM_STR);

																				$stm->bindParam(20, $bus_website, PDO::PARAM_STR);

																				$stm->bindParam(21, $bus_email, PDO::PARAM_STR);

																				$stm->bindParam(22, $simage, PDO::PARAM_STR);

																				$stm->bindParam(23, $familyno, PDO::PARAM_STR);

																				$stm->bindParam(24, $ismainmember, PDO::PARAM_STR);

																				

																				

																					if($stm->execute()){

																						$msg =CommonModel::create()->getSettings('FAMILY_INSERT_MSG');

																					}else{

																						$msg =CommonModel::create()->getSettings('FAMILY_INSERT_ERROR_MSG');

																					}	

																			}catch(PDOException $e){

																						Logger::newMessage($e);

																						logger::customErrorMsg();

																			}

																 }

																$msg = 'Members Imported';		

															}catch(PDOException $e){

																	Logger::newMessage($e);

																	logger::customErrorMsg();

															}

														//insert or update in family for this member

														

														$msg =CommonModel::create()->getSettings('MEMBER_INSERT_MSG');

													}else{

														$msg =CommonModel::create()->getSettings('MEMBER_INSERT_ERROR_MSG');

													}	

											}catch(PDOException $e){

														Logger::newMessage($e);

														logger::customErrorMsg();

											}

								 }

								$msg = 'Members Imported';		

							}catch(PDOException $e){

									Logger::newMessage($e);

									logger::customErrorMsg();

							}

					}

						$k++;

			}

			}return $msg;

		

			

	}

	public function randomuser()

	{

		global $MyPdodb;

		   $user = '';

		   $lchar = 0;

		   $char = 0;

		   $len = 6;

		   for($i = 0; $i < $len; $i++)

		   {

			   while($char == $lchar)

			   {

				   $char = rand(48, 109);

				   if($char > 57) $char += 7;

				   if($char > 90) $char += 6;

			   }

			   $user .= chr($char);

			   $lchar = $char;

		   }

		$user = strtoupper($user);

		/*

		Example of use:

		$newuser=randomuser(10);

		*/



		$sql = "SELECT id FROM hi_members where username= '".$user."'";   

		 try{

				$stm  = $MyPdodb->prepare($sql);      		  

				$stm->execute();

				$results = $stm->fetchAll(PDO::FETCH_CLASS);	

				$username = $results[0];		

				if($username!=''){

					$this->randomuser();

				}else{

					return $user;

				}

			}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

			}

	}

	public function randompassword()

	{

		global $MyPdodb;

		   $user = '';

		   $lchar = 0;

		   $char = 0;

		   $len = 6;

		   for($i = 0; $i < $len; $i++)

		   {

			   while($char == $lchar)

			   {

				   $char = rand(48, 109);

				   if($char > 57) $char += 7;

				   if($char > 90) $char += 6;

			   }

			   $user .= chr($char);

			   $lchar = $char;

		   }

		$password = strtoupper($user);

		return $password;

	}

	public function importRecord_family(){

		global $MyPdodb;

		$file_nm = $_FILES['ufile']['name'];	

		$thumbFolder = UPLOADDIR_MEMBERS_IMPORT;

		$validExtArr = explode(",",VALID_EXT_MEMBERS_IMPORT);

		$new_file = $thumbFolder."/".$member_name;

		$filepath='./xls_file/'.$file_nm;

		

		$file = explode('.',basename($_FILES['ufile']['name']));

		   $ext = ".".$file[count($file)-1];

			if(!in_array($ext,$validExtArr))

			{

			 	 $parentMsg=INVALID_PHOTO_MSG;

				 $member_name = "";

			}else{	

				$member_name = "family_".$recId.".".$file[count($file)-1];

				$new_file = $thumbFolder."/".$member_name;		

				$copied = copy($_FILES['ufile']['tmp_name'], $new_file);

				require_once 'utility/reader.php';

				$data = new Spreadsheet_Excel_Reader();

				$data->read($new_file); 

				$k=0;

				for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) 

				{

						$memberid = trim($data->sheets[0]['cells'][$i][1],' ');

						$familyno = trim($data->sheets[0]['cells'][$i][2],' ');

						$fam_fullname = trim($data->sheets[0]['cells'][$i][4],' ');

						$fam_gender = trim($data->sheets[0]['cells'][$i][5],' ');

						if($fam_gender=="M"){

							$fam_gender = "Male";

						}else if($fam_gender=="F"){

							$fam_gender = "Female";

						}

						$fam_bloodgroup =trim($data->sheets[0]['cells'][$i][6],' ');

						if($data->sheets[0]['cells'][$i][7]!=''){

							$fam_dob =date('Y-m-d',strtotime($data->sheets[0]['cells'][$i][7]));

						}else{

							$fam_dob = '';

						}

						$fam_relationwithmember = trim($data->sheets[0]['cells'][$i][8],' ');

						$fam_maritalstatus = trim($data->sheets[0]['cells'][$i][9],' ');

						

						$fam_education = trim($data->sheets[0]['cells'][$i][10],' ');

						$fam_occupation = trim($data->sheets[0]['cells'][$i][11],' ');

						$fam_nameofcompany = trim($data->sheets[0]['cells'][$i][12],' ');

						$fam_designation = trim($data->sheets[0]['cells'][$i][13],' ');

						

						$fam_address1 = trim($data->sheets[0]['cells'][$i][14],' ');

						$fam_address2 = trim($data->sheets[0]['cells'][$i][15],' ');

						$fam_city = trim($data->sheets[0]['cells'][$i][16],' ');

						$fam_state = trim($data->sheets[0]['cells'][$i][17],' ');

						$fam_country = trim($data->sheets[0]['cells'][$i][18],' ');

						$fam_zip = trim($data->sheets[0]['cells'][$i][19],' ');

						if(trim($fam_country,' ')!=''){

							$sql = "SELECT id,name FROM hi_countries where name=:name";        	       	  

							   $stm  = $MyPdodb->prepare($sql);      		

								$stm->bindParam(':name', $country, PDO::PARAM_STR);

								$stm->execute();       

								$results = $stm->fetchAll(PDO::FETCH_CLASS);	

								$countryname = $results[0];		

								$countryid=$countryname->id;

								$fam_status=1;

								if($countryname->name==''){

									$sql = "insert into hi_countries (name, status) values (?,?)";

										try{

											$stm  = $MyPdodb->prepare($sql);

													

											$stm->bindParam(1, $fam_country, PDO::PARAM_STR);

											$stm->bindParam(2, $fam_status, PDO::PARAM_INT);

												if($stm->execute()){

													$countryid = $MyPdodb->lastInsertId();

												}

										}catch(PDOException $e){

													Logger::newMessage($e);

													logger::customErrorMsg();

										}

								}

						}else{

							$countryid = 0;

						}

						$fam_phone =trim($data->sheets[0]['cells'][$i][20],' ');

						$fam_website =trim($data->sheets[0]['cells'][$i][21],' ');

						

						

						$fam_email =trim($data->sheets[0]['cells'][$i][22],' ');

						$fam_simage =trim($data->sheets[0]['cells'][$i][23],' ');

						if($fam_fullname!='' or $fam_email!='' or $fam_phone!=''){

							$fam_status = 1;

							$sql = "SELECT id FROM hi_family where fam_fullname= :fam_fullname and familyno=:familyno";   

							 try{

									 $stm  = $MyPdodb->prepare($sql);      		  

									 $stm->bindParam(':fam_fullname', $fam_fullname, PDO::PARAM_STR);

									 $stm->bindParam(':familyno', $familyno, PDO::PARAM_STR);

									 

									$stm->execute();

									$results = $stm->fetchAll(PDO::FETCH_CLASS);

									$id = $results[0]->id;		

									 if($id!=''){

											$sql = "UPDATE hi_family SET ";

											$sql .= " memberid = :memberid, ";

											$sql .= " fam_fullname = :fam_fullname, ";

											$sql .= " fam_gender = :fam_gender, ";

											$sql .= " fam_bloodgroup = :fam_bloodgroup, ";

											$sql .= " fam_dob = :fam_dob, ";

											$sql .= " fam_relationwithmember = :fam_relationwithmember, ";

											$sql .= " fam_maritalstatus = :fam_maritalstatus, ";

											$sql .= " fam_education = :fam_education, ";

											$sql .= " fam_occupation = :fam_occupation, ";

											$sql .= " fam_nameofcompany = :fam_nameofcompany, ";

											$sql .= " fam_designation = :fam_designation, ";

											$sql .= " fam_address1 = :fam_address1, ";

											$sql .= " fam_address2 = :fam_address2, ";

											$sql .= " fam_city = :fam_city, ";

											$sql .= " fam_state = :fam_state, ";

											$sql .= " fam_country = :fam_country, ";

											$sql .= " fam_zip = :fam_zip, ";

											$sql .= " fam_phone = :fam_phone, ";

											$sql .= " fam_website = :fam_website, ";

											$sql .= " fam_email = :fam_email, ";

											$sql .= " familyno = :familyno, ";

											

												$sql .= " fam_status = :fam_status ";

											$sql .= " Where id= :id";

											

											try{

												$stm  = $MyPdodb->prepare($sql);				

												$stm->bindParam(":memberid", $memberid, PDO::PARAM_STR);

												$stm->bindParam(":fam_fullname", $fam_fullname, PDO::PARAM_STR);

												$stm->bindParam(":fam_gender", $fam_gender, PDO::PARAM_STR);

												$stm->bindParam(":fam_bloodgroup", $fam_bloodgroup, PDO::PARAM_STR);

												$stm->bindParam(":fam_dob", $fam_dob, PDO::PARAM_STR);

												$stm->bindParam(":fam_relationwithmember", $fam_relationwithmember, PDO::PARAM_STR);

												$stm->bindParam(":fam_maritalstatus", $fam_maritalstatus, PDO::PARAM_STR);

												$stm->bindParam(":fam_education", $fam_education, PDO::PARAM_STR);

												$stm->bindParam(":fam_occupation", $fam_occupation, PDO::PARAM_STR);

												$stm->bindParam(":fam_nameofcompany", $fam_nameofcompany, PDO::PARAM_STR);

												$stm->bindParam(":fam_designation", $fam_designation, PDO::PARAM_STR);

												$stm->bindParam(":fam_address1", $fam_address1, PDO::PARAM_STR);

												$stm->bindParam(":fam_address2", $fam_address2, PDO::PARAM_STR);

												$stm->bindParam(":fam_city", $fam_city, PDO::PARAM_STR);

												$stm->bindParam(":fam_state", $fam_state, PDO::PARAM_STR);

												$stm->bindParam(":fam_country", $fam_country, PDO::PARAM_STR);

												$stm->bindParam(":fam_zip", $fam_zip, PDO::PARAM_STR);

												$stm->bindParam(":fam_phone", $fam_phone, PDO::PARAM_STR);

												$stm->bindParam(":fam_website", $fam_website, PDO::PARAM_STR);

												$stm->bindParam(":fam_email", $fam_email, PDO::PARAM_STR);

												$stm->bindParam(":familyno", $familyno, PDO::PARAM_STR);

												$stm->bindParam(":fam_status", $fam_status, PDO::PARAM_STR);

												$stm->bindParam(":id", $id, PDO::PARAM_INT);		

												if($stm->execute()){

													

															

													$msg =CommonModel::create()->getSettings('FAMILY_EDIT_MSG');

												}else{

													$msg =CommonModel::create()->getSettings('FAMILY_EDIT_ERROR_MSG');

												}	

												}catch(PDOException $e){

															Logger::newMessage($e);

															logger::customErrorMsg();

												}

									 }else{

											

												$sql = "insert into hi_family (memberid, fam_fullname, fam_gender, fam_bloodgroup, fam_dob, fam_relationwithmember, fam_maritalstatus, fam_education, fam_occupation, fam_nameofcompany, fam_designation, fam_address1, fam_address2, fam_city, fam_state, fam_country, fam_zip, fam_status, fam_phone, fam_website, fam_email,familyno) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

												try{

													$stm  = $MyPdodb->prepare($sql);

															

													$stm->bindParam(1, $memberid, PDO::PARAM_STR);

													$stm->bindParam(2, $fam_fullname, PDO::PARAM_STR);

													$stm->bindParam(3, $fam_gender, PDO::PARAM_STR);

													$stm->bindParam(4, $fam_bloodgroup, PDO::PARAM_STR);

													$stm->bindParam(5, $fam_dob, PDO::PARAM_STR);

													$stm->bindParam(6, $fam_relationwithmember, PDO::PARAM_STR);

													$stm->bindParam(7, $fam_maritalstatus, PDO::PARAM_STR);

													$stm->bindParam(8, $fam_education, PDO::PARAM_STR);

													$stm->bindParam(9, $fam_occupation, PDO::PARAM_STR);

													$stm->bindParam(10, $fam_nameofcompany, PDO::PARAM_STR);

													$stm->bindParam(11, $fam_designation, PDO::PARAM_STR);

													$stm->bindParam(12, $fam_address1, PDO::PARAM_STR);

													$stm->bindParam(13, $fam_address2, PDO::PARAM_STR);

													$stm->bindParam(14, $fam_city, PDO::PARAM_STR);

													$stm->bindParam(15, $fam_state, PDO::PARAM_STR);

													$stm->bindParam(16, $fam_country, PDO::PARAM_STR);

													$stm->bindParam(17, $fam_zip, PDO::PARAM_STR);

													$stm->bindParam(18, $fam_status, PDO::PARAM_STR);

													$stm->bindParam(19, $fam_phone, PDO::PARAM_STR);

													$stm->bindParam(20, $fam_website, PDO::PARAM_STR);

													$stm->bindParam(21, $fam_email, PDO::PARAM_STR);

													$stm->bindParam(22, $familyno, PDO::PARAM_STR);

													

													

														if($stm->execute()){

															$msg =CommonModel::create()->getSettings('FAMILY_INSERT_MSG');

														}else{

															$msg =CommonModel::create()->getSettings('FAMILY_INSERT_ERROR_MSG');

														}	

												}catch(PDOException $e){

															Logger::newMessage($e);

															logger::customErrorMsg();

												}

									 }

									$msg = 'Members Imported';		

								}catch(PDOException $e){

										Logger::newMessage($e);

										logger::customErrorMsg();

								}

							$k++;

					}

			}//end for

			}return $msg;

		

			

	}

	public function checkUserEmail($emailAddress,$recId=0){

		global $MyPdodb;	

		 	

		 if(!empty($recId)){		

			 $idSql=" and user_id != :id";

		 }else{

			 $idSql="";

		 }

		 $sql = "SELECT count(user_id) as cnt FROM hi_members where email_address= :email ".$idSql;   

		 try{

				 $stm  = $MyPdodb->prepare($sql);      		  

				 $stm->bindParam(':email', $emailAddress, PDO::PARAM_STR);

				 if(!empty($recId)){

					 $stm->bindParam(':id', $recId, PDO::PARAM_STR);

				 }

				$stm->execute();

				$results = $stm->fetchAll(PDO::FETCH_CLASS);		

				$totalCounts = $results[0];		

				$totalCounts->cnt;

				 if($totalCounts->cnt > 0){

					 return false;

				 }else{

				 	return true;

				 }

			}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

			}

	}	

	public function checkMember($name,$recId=0){

		global $MyPdodb;	

		 	

		 if(!empty($recId)){		

			 $idSql=" and id != :id";

		 }else{

			 $idSql="";

		 }

		 $sql = "SELECT count(id) as cnt FROM hi_members where email= :name and email!=''".$idSql;   

		 try{

				 $stm  = $MyPdodb->prepare($sql);      		  

				 $stm->bindParam(':name', $name, PDO::PARAM_STR);

				 if(!empty($recId)){

				

					 $stm->bindParam(':id', $recId, PDO::PARAM_STR);

				 }

				$stm->execute();

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

				$totalCounts = $results[0];		

				$totalCounts->cnt;

				 if($totalCounts->cnt > 0){

					 return false;

				 }else{

				 		

					 return true;

				 }

						

			}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

			}

	}

	public function selectMemberDetail($id){

		global $MyPdodb;		   

		$sql = "SELECT * FROM hi_members where id = :id";		

		try{

			$stm  = $MyPdodb->prepare($sql);    

			 $stm->bindParam(':id', $id, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			foreach($results as $result){

				$sql = "select name as cityname from hi_cities where id='".$result->city."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$cityname = $res->cityname;

					//array_push($arrres,$totalsubsec);

					$results[$i]->cityname = $cityname;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}

			$i=0;

			foreach($results as $result){

				$sql = "select name as countryname from hi_countries where id='".$result->country."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$countryname = $res->countryname;

					//array_push($arrres,$totalsubsec);

					$results[$i]->countryname = $countryname;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			$i++;

			}	

			

			return $results[0];				       

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

	public function selectFamilyDetail($id){

		global $MyPdodb;		   

		$sql = "SELECT * FROM hi_family where id = :id";		

		try{

			$stm  = $MyPdodb->prepare($sql);    

			 $stm->bindParam(':id', $id, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			foreach($results as $result){

			if($result->ismainmember==1){

				$sql = "select simage from hi_members where id='".$result->memberid."'";

				try{

					$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   				$res = $MyPdodb->queryFirst($sql);

					$simage = $res->simage;

					//array_push($arrres,$totalsubsec);

					$results[$i]->fam_simage = $simage;

				}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

				}

			}

			$i++;

			}	

			

			return $results[0];				       

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

	

	public function selectRequests($start=0,$limit) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));		

		$sql = "SELECT * FROM hi_memberrequest ";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function selectCountRequest() {

       global $MyPdodb;

       $sql = "SELECT count(id) as cnt FROM hi_memberrequest";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function insertWish($postvars) {

		global $MyPdodb;

		$birthday_id =$postvars['birthday_id'];

		$wish =$postvars['wish'];

		$status =$postvars['status'];

		if($status==''){

			$status=1;

		}

		$tdate = date("Y-m-d h:i:s");	  

		$sql = "insert into hi_birthdaywishes (from_id, birthday_id, tdate, wish, status) values (?,?,?,?,?)";

		try{

			$stm  = $MyPdodb->prepare($sql);

					

			$stm->bindParam(1, $_SESSION["member_id"], PDO::PARAM_INT);

			$stm->bindParam(2, $birthday_id, PDO::PARAM_INT);

			$stm->bindParam(3, $tdate, PDO::PARAM_STR);

			$stm->bindParam(4, $wish, PDO::PARAM_STR);

			$stm->bindParam(5, $status, PDO::PARAM_INT);

			

			

				if($stm->execute()){

					$msg ="Wish saved";

				}else{

					$msg ="Error occured";

				}	

				return $msg;

		}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

		} 

	}

	public function insertMsg($postvars) {

		global $MyPdodb;

		$missyou_id =$postvars['missyou_id'];

		$wish =$postvars['wish'];

		$status =$postvars['status'];

		if($status==''){

			$status=1;

		}

		$tdate = date("Y-m-d h:i:s");	  

		$sql = "insert into hi_missyoumsgs (from_id, missyou_id, tdate, wish, status) values (?,?,?,?,?)";

		try{

			$stm  = $MyPdodb->prepare($sql);

					

			$stm->bindParam(1, $_SESSION["member_id"], PDO::PARAM_INT);

			$stm->bindParam(2, $missyou_id, PDO::PARAM_INT);

			$stm->bindParam(3, $tdate, PDO::PARAM_STR);

			$stm->bindParam(4, $wish, PDO::PARAM_STR);

			$stm->bindParam(5, $status, PDO::PARAM_INT);

			

			

				if($stm->execute()){

					$msg ="Message saved";

				}else{

					$msg ="Error occured";

				}	

				return $msg;

		}catch(PDOException $e){

					Logger::newMessage($e);

					logger::customErrorMsg();

		} 

	}

	public function getWishList($postvars){

		global $MyPdodb;

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));	

		

		$sql_count = "SELECT count(id) as cnt FROM hi_birthdaywishes where status=1 and birthday_id='".$postvars['birthday_id']."' order by tdate desc ";

	    try {

				$stm  = $MyPdodb->prepare($sql_count);      		

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

		    }	

				

		$totalCounts = $results[0]->cnt;			

	    $_REQUEST["totalres"] = $totalCounts;

		$_REQUEST["nume"] = $totalCounts;	

		$sql = "SELECT * FROM hi_birthdaywishes where status=1 and birthday_id='".$postvars['birthday_id']."' order by tdate desc LIMIT ?, ?";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$BindArr[] =(int) $postvars["eu"];

			$BindArr[] =(int) $postvars["limit"];	

			$stm->execute($BindArr);

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				//print_r($result);

					$sql = "select fullname as member, simage, familyno, gender from hi_members where id='".$result->from_id."'";

					try{

						$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

						$res = $MyPdodb->queryFirst($sql);

						$member = $res->member;

						$photo = $res->simage;

						$familyno = $res->familyno;

						$gender = $res->gender;

						//array_push($arrres,$totalsubsec);

						$results[$i]->member = $member;

						$results[$i]->photo = $photo;

						$results[$i]->familyno = $familyno;

						$results[$i]->gender = $gender;

					}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

					}

				$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

	public function getMsgList($postvars){

		global $MyPdodb;

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));	

		

		$sql_count = "SELECT count(id) as cnt FROM hi_missyoumsgs where status=1 and missyou_id='".$postvars['missyou_id']."' order by tdate desc ";

	    try {

				$stm  = $MyPdodb->prepare($sql_count);      		

				$stm->execute($BindArr);

				$results = $stm->fetchAll(PDO::FETCH_CLASS);

			}catch(PDOException $e){

				Logger::newMessage($e);

				logger::customErrorMsg();

		    }	

				

		$totalCounts = $results[0]->cnt;			

	    $_REQUEST["totalres"] = $totalCounts;

		$_REQUEST["nume"] = $totalCounts;	

		$sql = "SELECT * FROM hi_missyoumsgs where status=1 and missyou_id='".$postvars['missyou_id']."' order by tdate desc LIMIT ?, ?";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$BindArr[] =(int) $postvars["eu"];

			$BindArr[] =(int) $postvars["limit"];	

			$stm->execute($BindArr);

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				//print_r($result);

					$sql = "select fullname as member, simage,familyno,gender from hi_members where id='".$result->from_id."'";

					try{

						$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

						$res = $MyPdodb->queryFirst($sql);

						$member = $res->member;

						$photo = $res->simage;

						$familyno = $res->familyno;

						$gender = $res->gender;

						//array_push($arrres,$totalsubsec);

						$results[$i]->member = $member;

						$results[$i]->photo = $photo;

						$results[$i]->familyno = $familyno;

						$results[$i]->gender = $gender;

					}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

					}

				$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

	public function selectPages_wishes($start=0,$limit,$memberid) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));		

		$start = (int) $start;

		$limit = (int) $limit;		

		$sql = "SELECT * FROM hi_birthdaywishes where birthday_id = '".$memberid."'";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				//print_r($result);

					$sql = "select fullname as member, simage from hi_members where id='".$result->from_id."'";

					try{

						$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

						$res = $MyPdodb->queryFirst($sql);

						$member = $res->member;

						$photo = $res->simage;

						//array_push($arrres,$totalsubsec);

						$results[$i]->member = $member;

						$results[$i]->photo = $photo;

					}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

					}

				

				$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function selectPages_msgs($start=0,$limit,$memberid) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));		

		$start = (int) $start;

		$limit = (int) $limit;		

		$sql = "SELECT * FROM hi_missyoumsgs where missyou_id = '".$memberid."'";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			foreach($results as $result){

				//print_r($result);

					$sql = "select fullname as member, simage from hi_members where id='".$result->from_id."'";

					try{

						$MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

						$res = $MyPdodb->queryFirst($sql);

						$member = $res->member;

						$photo = $res->simage;

						//array_push($arrres,$totalsubsec);

						$results[$i]->member = $member;

						$results[$i]->photo = $photo;

					}catch(PDOException $e){

						Logger::newMessage($e);

						logger::customErrorMsg();

					}

				

				$i++;

			}	

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function selectPages_family($start=0,$limit,$memberid) {

		

		global $MyPdodb;

		$MyPdodb->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('MyPDOStatement'));		

		$start = (int) $start;

		$limit = (int) $limit;		

		$sql = "SELECT * FROM hi_family where memberid = '".$memberid."'";  

		try{

			$stm  = $MyPdodb->prepare($sql);      		

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);

			$i=0;

			

			return $results ;		

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

		

    }

	public function selectCount_wishes($memberid) {

       global $MyPdodb;

       $sql = "SELECT count(id) as cnt FROM hi_birthdaywishes where birthday_id = '".$memberid."'";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function selectCount_msgs($memberid) {

       global $MyPdodb;

       $sql = "SELECT count(id) as cnt FROM hi_missyoumsgs where missyou_id = '".$memberid."'";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function selectCount_family($memberid) {

       global $MyPdodb;

       $sql = "SELECT count(id) as cnt FROM hi_family where memberid = '".$memberid."'";        	       	  

	   $MyPdodb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

	   return $MyPdodb->queryFirst($sql);	   	  

    }

	public function deletewish($recId) {

       global $MyPdodb;		        

	    $sql = "delete from hi_birthdaywishes where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       		

			$msg=CommonModel::create()->getSettings('MESSAGE_DELETE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function deletemsg($recId) {

       global $MyPdodb;		        

	    $sql = "delete from hi_missyoumsgs where  id = :id ";

		try{

			$stm  = $MyPdodb->prepare($sql);      			

			$stm->bindParam(':id', $recId, PDO::PARAM_INT);

			$stm->execute();       		

			$msg=CommonModel::create()->getSettings('MESSAGE_DELETE_MSG');

			return $msg;			

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

		

    }

	public function getMemberEmail($id){

		global $MyPdodb;		   

		$sql = "SELECT email FROM hi_members where id in(select memberid from hi_family where id=:id)";		

		try{

			$stm  = $MyPdodb->prepare($sql);    

			 $stm->bindParam(':id', $id, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			return $results[0];				       

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

	public function getMemberEmail_($id){

		global $MyPdodb;		   

		$sql = "SELECT email FROM hi_members where id =:id";		

		try{

			$stm  = $MyPdodb->prepare($sql);    

			 $stm->bindParam(':id', $id, PDO::PARAM_INT);

			$stm->execute();

			$results = $stm->fetchAll(PDO::FETCH_CLASS);	

			$i=0;

			return $results[0];				       

	    }catch(PDOException $e){

			Logger::newMessage($e);

			logger::customErrorMsg();

		}

	}

}

?>