<?php
require_once "check.class.php";
class users extends check{

	var $dblink;
	
	var $vLogin;
	var $vPass;
	var $vEmail;
	var $vGender;
	var $vFirstName;
	var $vMiddleName;
	var $vLastName;
	var $vHearing_Source;
	var $dDob;
	var $vRealtion_Status;
	var $vCountry;
	var $vState;
	var $vCounty;
	var $vCity;
	var $vAstro_Sign;
	var $nHeight;
	var $vBody_Type;
	var $vEye_Color;
	var $vHair_Color;
	var $vBody_Art;
	var $vBest_Feature;
	var $vHobbies;
	var $vTravel_Destination;
	var $vFauvorite_Things;
	var $vLast_Read;
	var $vSports_Enjoyed;
	var $vOther_Interests;
	var $vExcersise;
	var $vEating_Habits;
	var $vSmoking;
	var $vDrinking;
	var $vProfession;
	var $vAnual_Income;
	var $vLiving_Situation;
	var $nChildren;
	var $vPets;
	var $vEthinicity;
	var $vReligion;
	var $vEducation;
	var $vLanguages;
	var $vPolitcal_Outlook;
	var $vTitle;
	var $tAbout_Me;
	var $tAbout_Partner;
	var $tSharePartner;
	var $vStatus;
	var $vOnline;
	var $vFeatured;
	var $vId_Varified;
	var $vBC_Verified;
	var $dActive_Date;
	var $vIntro_Check;
	var $dLast_Login;
	var $dLast_Login_Time;
	var $vMobile;
	var $vProvider;
	var $vBilling;
	var $dStartDate;

	var $Age;

	var $now;


	var $tContent;
	var $nUser_Id_From;
	var $nUser_Id_To;

	var $nPartner_Pref_Id;
	var $nAge_Low;
	var $nAge_High;
	var $nHeight_Low;
	var $nHeight_High;
	var $vRelegion;
	var $vIncome;
	var $vRelationship;
	var $vChildren;

	var $nAlert_Id;
	var $nNewUser;
	var $nAddFavourites;
	var $nProfileViewed;
	var $nAddHot;
	var $nNewMessageMobile;
	var $nNewInterestMobile;

	var $vUrl;
	var $dDate;
	var $nPhoto_Id;
	var $arrFile;
	var $arrExtns;

	var $arrSearch;

	var $vFeet;
	var $vInch;
	var $vFeet_Low;
	var $vInch_Low;
	var $vFeet_High;
	var $vInch_High;

	var $tmy_looks_today;
	var $tmy_likes_onanyday;
	var $tmy_dislikes_onanyday;
	var $tmy_personality;
	var $tmy_mood_today;
	var $tmy_music;
	var $tmy_movies;
	var $tmy_tv;
	var $tmy_sports_play;
	var $tmy_sports_watch;
	var $tmy_travel_been;
	var $tmy_travel_going;
	var $tmy_arts_culture_events;
	var $tmy_poison_place;
	var $taday_in_my_life;
	var $vmy_night_life_out;
	var $vmy_night_life_in;
	var $tmy_food;
	var $tmy_money;
	var $tmy_last_restaurant;
	var $tmy_last_restaurant_review;
	var $tmy_charity;
	var $tmy_politics;
	var $tmy_major_world_issue;
	var $tmy_doings_on_major_world_issue;
	var $tmy_scenario_question_one;
	var $tmy_scenario_answer_one;
	var $tmy_scenario_question_two;
	var $tmy_scenario_answer_two;
	var $tmy_perfect_mate;

	var $vProfileType;
	var $tmy_profile;

	function users ($db)
	{
		$this->dblink	= $db;
		$this->now		= date("Y-m-d");
		$this->arrFile	= array();
		$this->arrExtns	= array("jpg", "jpeg", "gif", "png", "JPG", "JPEG", "GIF", "PNG");
		$this->arrSearch= array();
	}
	
	function set_values($arr=array())
	{
		$this->vLogin				= isset($arr['vLogin'])				?	stripslashes(trim($arr['vLogin']))				:	"";
		
                $this->vPass				= isset($arr['vPass'])				?	stripslashes(trim($arr['vPass']))				:	"";
		$this->vEmail				= isset($arr['vEmail'])				?	stripslashes(trim($arr['vEmail']))				:	"";
		$this->vGender				= isset($arr['vGender'])			?	stripslashes(trim($arr['vGender']))				:	"";
		$this->vFirstName			= isset($arr['vFirstName'])			?	stripslashes(trim($arr['vFirstName']))				:	"";
		$this->vMiddleName			= isset($arr['vMiddleName'])		?	stripslashes(trim($arr['vMiddleName']))				:	"";
		$this->vLastName			= isset($arr['vLastName'])			?	stripslashes(trim($arr['vLastName']))				:	"";
		$this->vHearing_Source		= isset($arr['vHearing_Source'])	?	stripslashes(trim($arr['vHearing_Source']))		:	"";
		$this->dDob					= isset($arr['dDob'])				?	stripslashes(trim($arr['dDob']))				:	"";
		$this->vRealtion_Status		= isset($arr['vRealtion_Status'])	?	stripslashes(trim($arr['vRealtion_Status']))	:	"";
		$this->vCountry				= isset($arr['vCountry'])			?	stripslashes(trim($arr['vCountry']))			:	"United States";
		$this->vState				= isset($arr['vState'])				?	stripslashes(trim($arr['vState']))				:	"";
		$this->vCounty				= isset($arr['vCounty'])			?	stripslashes(trim($arr['vCounty']))				:	"";
		$this->vCity				= isset($arr['vCity'])				?	stripslashes(trim($arr['vCity']))				:	"";
		$this->vAstro_Sign			= isset($arr['vAstro_Sign'])		?	stripslashes(trim($arr['vAstro_Sign']))			:	"";
		$this->vBody_Type			= isset($arr['vBody_Type'])			?	stripslashes(trim($arr['vBody_Type']))			:	"";
		$this->vEye_Color			= isset($arr['vEye_Color'])			?	stripslashes(trim($arr['vEye_Color']))			:	"";
		$this->vHair_Color			= isset($arr['vHair_Color'])		?	stripslashes(trim($arr['vHair_Color']))			:	"";
		$this->vBody_Art			= isset($arr['vBody_Art'])			?	stripslashes(trim($arr['vBody_Art']))			:	"";
		$this->vBest_Feature		= isset($arr['vBest_Feature'])		?	stripslashes(trim($arr['vBest_Feature']))		:	"";
		$this->vHobbies				= isset($arr['vHobbies'])			?	stripslashes(trim($arr['vHobbies']))			:	"";
		$this->vTravel_Destination	= isset($arr['vTravel_Destination'])?	stripslashes(trim($arr['vTravel_Destination']))	:	"";
		$this->vFauvorite_Things	= isset($arr['vFauvorite_Things'])	?	stripslashes(trim($arr['vFauvorite_Things']))	:	"";
		$this->vLast_Read			= isset($arr['vLast_Read'])			?	stripslashes(trim($arr['vLast_Read']))			:	"";
		$this->vOther_Interests		= isset($arr['vOther_Interests'])	?	stripslashes(trim($arr['vOther_Interests']))	:	"";
		$this->vExcersise			= isset($arr['vExcersise'])			?	stripslashes(trim($arr['vExcersise']))			:	"";
		$this->vSports_Enjoyed		= isset($arr['vSports_Enjoyed'])	?	stripslashes(trim($arr['vSports_Enjoyed']))		:	"";
		$this->vEating_Habits		= isset($arr['vEating_Habits'])		?	stripslashes(trim($arr['vEating_Habits']))		:	"";
		$this->vSmoking				= isset($arr['vSmoking'])			?	stripslashes(trim($arr['vSmoking']))			:	"";
		$this->vDrinking			= isset($arr['vDrinking'])			?	stripslashes(trim($arr['vDrinking']))			:	"";
		$this->vProfession			= isset($arr['vProfession'])		?	stripslashes(trim($arr['vProfession']))			:	"";
		$this->vAnual_Income		= isset($arr['vAnual_Income'])		?	stripslashes(trim($arr['vAnual_Income']))		:	"";
		$this->vLiving_Situation	= isset($arr['vLiving_Situation'])	?	stripslashes(trim($arr['vLiving_Situation']))	:	"";
		$this->nChildren			= isset($arr['nChildren'])			?	stripslashes(trim($arr['nChildren']))			:	"";
		$this->vPets				= isset($arr['vPets'])				?	stripslashes(trim($arr['vPets']))				:	"";
		$this->vEthinicity			= isset($arr['vEthinicity'])		?	stripslashes(trim($arr['vEthinicity']))			:	"";
		$this->vReligion			= isset($arr['vReligion'])			?	stripslashes(trim($arr['vReligion']))			:	"";
		$this->vEducation			= isset($arr['vEducation'])			?	stripslashes(trim($arr['vEducation']))			:	"";
		$this->vPolitcal_Outlook	= isset($arr['vPolitcal_Outlook'])	?	stripslashes(trim($arr['vPolitcal_Outlook']))	:	"";
		$this->vTitle				= isset($arr['vTitle'])				?	stripslashes(trim($arr['vTitle']))				:	"";
		$this->tAbout_Me			= isset($arr['tAbout_Me'])			?	stripslashes(trim($arr['tAbout_Me']))			:	"";
		$this->tAbout_Partner		= isset($arr['tAbout_Partner'])		?	stripslashes(trim($arr['tAbout_Partner']))		:	"";
		$this->vStatus				= isset($arr['vStatus'])			?	stripslashes(trim($arr['vStatus']))				:	"NNNN";
		$this->vBilling				= isset($arr['vBilling'])			?	stripslashes(trim($arr['vBilling']))			:	"D";
		$this->vOnline				= isset($arr['vOnline'])			?	stripslashes(trim($arr['vOnline']))				:	"Offline";
		$this->vFeatured			= isset($arr['vFeatured'])			?	stripslashes(trim($arr['vFeatured']))			:	"NNNN";
		$this->vId_Varified			= isset($arr['vId_Varified'])		?	stripslashes(trim($arr['vId_Varified']))		:	"NN";
		$this->vBC_Verified			= isset($arr['vBC_Verified'])		?	stripslashes(trim($arr['vBC_Verified']))		:	"NN";
		$this->vIntro_Check			= isset($arr['vIntro_Check'])		?	stripslashes(trim($arr['vIntro_Check']))		:	"";
		$this->dActive_Date			= isset($arr['dActive_Date'])		?	stripslashes(trim($arr['dActive_Date']))		:	date("Y-m-d");
		$this->dLast_Login			= isset($arr['dLast_Login'])		?	stripslashes(trim($arr['dLast_Login']))			:	date("Y-m-d");
		$this->dLast_Login_Time			= isset($arr['dLast_Login_Time'])		?	stripslashes(trim($arr['dLast_Login_Time']))			:	date("Y-m-d H:i:s");
		$this->dStartDate			= isset($arr['dStartDate'])			?	stripslashes(trim($arr['dStartDate']))			:	date("Y-m-d H:i:s");
		$this->vMobile				= isset($arr['vMobile'])			?	stripslashes(trim($arr['vMobile']))				:	"";
		$this->vProvider			= isset($arr['vProvider'])			?	stripslashes(trim($arr['vProvider']))			:	"";
                $this->vDate_Preference			= isset($arr['vDate_Preference'])			?	stripslashes(trim($arr['vDate_Preference']))			:	"";
                $this->fbId			= isset($arr['fbId'])			?	stripslashes(trim($arr['fbId']))			:	"";
		
		if (isset($arr['vSports_Enjoyed']) AND !empty($arr['vSports_Enjoyed']) AND is_array($arr['vSports_Enjoyed']))
		 {
			$this->vSports_Enjoyed		= implode(",", $arr['vSports_Enjoyed']);
		}
		 else {
			$this->vSports_Enjoyed		= isset($arr['vSports_Enjoyed'])	?	stripslashes(trim($arr['vSports_Enjoyed']))		:	"";
		}
		if (isset($arr['vLanguages']) AND !empty($arr['vLanguages']) AND is_array($arr['vLanguages'])) {
			$this->vLanguages			= implode(",", $arr['vLanguages']);
		} else {
			$this->vLanguages			= isset($arr['vLanguages'])			?	stripslashes(trim($arr['vLanguages']))			:	"";
		}
		if (isset($arr['tSharePartner']) AND !empty($arr['tSharePartner']) AND is_array($arr['tSharePartner'])) {
			$this->tSharePartner			= implode(",", $arr['tSharePartner']);
		} else {
			$this->tSharePartner		= isset($arr['tSharePartner'])		?	stripslashes(trim($arr['tSharePartner']))		:	"";
		}

		$this->Age					= isset($arr['Age'])				?	stripslashes(trim($arr['Age']))				:	"";


		$this->nPartner_Pref_Id		= isset($arr['nPartner_Pref_Id'])	?	stripslashes(trim($arr['nPartner_Pref_Id']))	:	"";
		$this->nAge_Low				= isset($arr['nAge_Low'])			?	stripslashes(trim($arr['nAge_Low']))			:	"";
		$this->nAge_High			= isset($arr['nAge_High'])			?	stripslashes(trim($arr['nAge_High']))			:	"";
		$this->vRelegion			= isset($arr['vRelegion'])			?	stripslashes(trim($arr['vRelegion']))			:	"";
		$this->vIncome				= isset($arr['vIncome'])			?	stripslashes(trim($arr['vIncome']))				:	"";
		$this->vRelationship		= isset($arr['vRelationship'])		?	stripslashes(trim($arr['vRelationship']))		:	"";
		$this->vChildren			= isset($arr['vChildren'])			?	stripslashes(trim($arr['vChildren']))			:	"";

		$this->nHeight_Low			= isset($arr['nHeight_Low'])		?	stripslashes(trim($arr['nHeight_Low']))			:	"";
		$this->nHeight_High			= isset($arr['nHeight_High'])		?	stripslashes(trim($arr['nHeight_High']))		:	"";
		$this->vFeet_Low			= isset($arr['vFeet_Low'])			?	stripslashes(trim($arr['vFeet_Low']))			:	"";
		$this->vInch_Low			= isset($arr['vInch_Low'])			?	stripslashes(trim($arr['vInch_Low']))			:	"";
		$this->vFeet_High			= isset($arr['vFeet_High'])			?	stripslashes(trim($arr['vFeet_High']))			:	"";
		$this->vInch_High			= isset($arr['vInch_High'])			?	stripslashes(trim($arr['vInch_High']))			:	"";

	
		$this->nHeight				= isset($arr['nHeight'])			?	stripslashes(trim($arr['nHeight']))				:	"";
		$this->vFeet				= isset($arr['vFeet'])				?	stripslashes(trim($arr['vFeet']))				:	"";
		$this->vInch				= isset($arr['vInch'])				?	stripslashes(trim($arr['vInch']))				:	"";

		if ($this->vFeet_Low <> "" AND $this->vInch_Low <> "" AND $this->nHeight_Low == "") {
			$this->nHeight_Low	= $this->vInch_Low;
			$this->nHeight_Low	+= 12*$this->vFeet_Low;

		} else if ($this->nHeight_Low <> "") {
			$this->vFeet_Low	= floor($this->nHeight_Low/12);
			$this->vInch_Low	= $this->nHeight_Low%12;
		}
		if ($this->vFeet_High <> "" AND $this->vInch_High <> "" AND $this->nHeight_High == "") {
			$this->nHeight_High	= $this->vInch_High;
			$this->nHeight_High	+= 12*$this->vFeet_High;

		} else if ($this->nHeight_High <> "") {
			$this->vFeet_High	= floor($this->nHeight_High/12);
			$this->vInch_High	= $this->nHeight_High%12;
		}
		if ($this->vFeet <> "" AND $this->vInch <> "" AND $this->nHeight == "") {
			$this->nHeight	= $this->vInch;
			$this->nHeight	+= 12*$this->vFeet;

		} else {
			$this->vFeet	= floor($this->nHeight/12);
			$this->vInch	= $this->nHeight%12;
		}

		$this->tmy_looks_today	= isset($arr['tmy_looks_today'])	?	stripslashes(trim($arr['tmy_looks_today']))	:	"";
		$this->tmy_likes_onanyday	= isset($arr['tmy_likes_onanyday'])	?	stripslashes(trim($arr['tmy_likes_onanyday']))	:	"";
		$this->tmy_dislikes_onanyday	= isset($arr['tmy_dislikes_onanyday'])	?	stripslashes(trim($arr['tmy_dislikes_onanyday']))	:	"";
		$this->tmy_personality	= isset($arr['tmy_personality'])	?	stripslashes(trim($arr['tmy_personality']))	:	"";
		$this->tmy_mood_today	= isset($arr['tmy_mood_today'])	?	stripslashes(trim($arr['tmy_mood_today']))	:	"";
		$this->tmy_music	= isset($arr['tmy_music'])	?	stripslashes(trim($arr['tmy_music']))	:	"";
		$this->tmy_movies	= isset($arr['tmy_movies'])	?	stripslashes(trim($arr['tmy_movies']))	:	"";
		$this->tmy_tv	= isset($arr['tmy_tv'])	?	stripslashes(trim($arr['tmy_tv']))	:	"";
		$this->tmy_sports_play	= isset($arr['tmy_sports_play'])	?	stripslashes(trim($arr['tmy_sports_play']))	:	"";
		$this->tmy_sports_watch	= isset($arr['tmy_sports_watch'])	?	stripslashes(trim($arr['tmy_sports_watch']))	:	"";
		$this->tmy_travel_been	= isset($arr['tmy_travel_been'])	?	stripslashes(trim($arr['tmy_travel_been']))	:	"";
		$this->tmy_travel_going	= isset($arr['tmy_travel_going'])	?	stripslashes(trim($arr['tmy_travel_going']))	:	"";
		$this->tmy_arts_culture_events	= isset($arr['tmy_arts_culture_events'])	?	stripslashes(trim($arr['tmy_arts_culture_events']))	:	"";
		$this->tmy_poison_place	= isset($arr['tmy_poison_place'])	?	stripslashes(trim($arr['tmy_poison_place']))	:	"";
		$this->taday_in_my_life	= isset($arr['taday_in_my_life'])	?	stripslashes(trim($arr['taday_in_my_life']))	:	"";
		$this->vmy_night_life_out	= isset($arr['vmy_night_life_out'])	?	stripslashes(trim($arr['vmy_night_life_out']))	:	"";
		$this->vmy_night_life_in	= isset($arr['vmy_night_life_in'])	?	stripslashes(trim($arr['vmy_night_life_in']))	:	"";
		$this->tmy_food	= isset($arr['tmy_food'])	?	stripslashes(trim($arr['tmy_food']))	:	"";
		$this->tmy_money	= isset($arr['tmy_money'])	?	stripslashes(trim($arr['tmy_money']))	:	"";
		$this->tmy_last_restaurant	= isset($arr['tmy_last_restaurant'])	?	stripslashes(trim($arr['tmy_last_restaurant']))	:	"";
		$this->tmy_last_restaurant_review	= isset($arr['tmy_last_restaurant_review'])	?	stripslashes(trim($arr['tmy_last_restaurant_review']))	:	"";
		$this->tmy_charity	= isset($arr['tmy_charity'])	?	stripslashes(trim($arr['tmy_charity']))	:	"";
		$this->tmy_politics	= isset($arr['tmy_politics'])	?	stripslashes(trim($arr['tmy_politics']))	:	"";
		$this->tmy_major_world_issue	= isset($arr['tmy_major_world_issue'])	?	stripslashes(trim($arr['tmy_major_world_issue']))	:	"";
		$this->tmy_doings_on_major_world_issue	= isset($arr['tmy_doings_on_major_world_issue'])	?	stripslashes(trim($arr['tmy_doings_on_major_world_issue']))	:	"";
		$this->tmy_scenario_question_one	= isset($arr['tmy_scenario_question_one'])	?	stripslashes(trim($arr['tmy_scenario_question_one']))	:	"The 9:30 Club is featuring one of your old favs like Emmet Swimming or one of your new favs like Joss Stone; however your boss just offered you free tix to the National Symphony Orchestra at the Kennedy Center";
		$this->tmy_scenario_answer_one	= isset($arr['tmy_scenario_answer_one'])	?	stripslashes(trim($arr['tmy_scenario_answer_one']))	:	"";
		$this->tmy_scenario_question_two	= isset($arr['tmy_scenario_question_two'])	?	stripslashes(trim($arr['tmy_scenario_question_two']))	:	"A gorgeous girl/guy walks up to you at a Martini bar, with that look in her/his eye. What do you do?";
		$this->tmy_scenario_answer_two	= isset($arr['tmy_scenario_answer_two'])	?	stripslashes(trim($arr['tmy_scenario_answer_two']))	:	"";
		$this->tmy_perfect_mate	= isset($arr['tmy_perfect_mate'])	?	stripslashes(trim($arr['tmy_perfect_mate']))	:	"";

		$this->tmy_profile	= isset($arr['tmy_profile'])	?	stripslashes(trim($arr['tmy_profile']))	:	"";
		$this->vProfileType	= isset($arr['vProfileType'])	?	stripslashes(trim($arr['vProfileType'])):	"I";

	}

	function get_providers()
	{
		//$array	= array(array("provider"=>"","vSMSgateway"=>""));
                $array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."gateways where vActive='1' order by provider";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array; 
	}

	function check($id)
	{
		$message	= "";
		if ($this->vLogin == "")
			$message	.= "Please enter your username.<br>";
		if (!$this->check_username($this->vLogin))
			$message	.= "Only the following characters are allowed in a username ([a-z][A-Z][0-9].-_).<br>";
		if ($this->username_existance($id)) 
			$message	.= "The username you have chosen already exists.<br>";

		if ($id <= 0) {
			if ($this->vPass == "")
				$message	.= "Please enter your password.<br>";
		}
		if (!$this->check_email($this->vEmail))
			$message	.= "Please enter a valid email address.<br>";
		if ($this->vFirstName == "")
			$message	.= "Please enter your first name.<br>";
		if ($this->vLastName == "")
			$message	.= "Please enter your last name.<br>";
		if ($this->vMobile <> "") {
			if (!$this->check_numerals($this->vMobile)) {
				$message	.= "Only numbers are allowed in the mobile number (make sure to add a '1' before the area code i.e. 12025557638).<br>";
			}
			if ($this->vProvider == "") {
				$message	.= "Please select a mobile service provider also<br>";
			}
		}

                if($this->check_email_available($this->vEmail,$id))
                        {

                         $message	.= "Email id already exist please choose a different mail id<br>";

                        }

		if (!$this->check_date($this->dDob))
			$message	.= "Please enter a valid date of birth.<br>";
		/*if ($this->vCity == "")
			$message	.= "Please enter your city.<br>";
		if ($this->vCounty == "")
			$message	.= "Please select your county.<br>";*/
		if ($this->vTitle == "")
			$message	.= "Please enter the title of your profile.<br>";

		if ($this->tmy_last_restaurant_review <> "" AND $this->tmy_last_restaurant == "")
			$message	.= "Please enter the name of the last restaurant you have visited<br>";
		if ($this->tmy_doings_on_major_world_issue <> "" AND $this->tmy_major_world_issue == "")
			$message	.= "Please enter your response to the profile question 'Of the major issues in the world, which ones are you the most passionate about?' before entering your response to the profile question 'What are you are doing about it?'.<br>";
		if ($this->vProfileType == "U" AND $this->tmy_profile == "")
			$message	.= "Since you have chosen 'Unique' as your Profile Display type, please enter the Administrator written profile";
		return $message;
	}

	function username_existance($id)
	{
		$flag	= false;
		$sql	= "SELECT * FROM ".TABLEPREFIX."user 
				   WHERE vLogin LIKE '".addslashes($this->vLogin)."' AND nUser_Id NOT LIKE '".$id."' AND vStatus != 'DDDD'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$flag	= true;
		}
		return $flag;
	}
        function useremail_existance($email)
                {
                        $flag	= false;
                        $sql	= "SELECT * FROM ".TABLEPREFIX."user 
                                           WHERE vEmail LIKE '".addslashes($email)."'AND vStatus != 'DDDD'";
                        $res	= @mysql_query($sql, $this->dblink);
                        if (@mysql_num_rows($res) > 0) {
                                $flag	= true;
                        }
                        return $flag;
                }
       function userename_existance_without_id($usename)
                { 
                        $flag	= false;
                        $sql	= "SELECT * FROM ".TABLEPREFIX."user 
                                           WHERE vLogin LIKE '".addslashes($usename)."'AND vStatus != 'DDDD'";
                        $res	= @mysql_query($sql, $this->dblink);
                        if (@mysql_num_rows($res) > 0) {
                                $flag	= true;
                        }
                        return $flag;
                }         
                
        function createusername($usename)
        {

             if($this->userename_existance_without_id($usename))
             {
                 $usename = $usename.rand(1,50);
                 $this->createusername($usename);
             }
            
             return $usename;
        }         
                
	function save($id=0)
	{
		$message	= $this->check($id); 
		if ($message == "") {
			if ($id >= 1) {
				$message	= $this->update($id);
				if ($message == "" AND $this->vPass <> "") {
					$this->update_password($id);
				}
			} else {
				$message	= $this->insert();
			}
		}
		return $message;
	}
       
	function insert()
	{
		$date		= date("Y-m-d H:i:s");
		$message	= "";
                //$arrDob=explode("-",$this->dDob);
                $arrDob=explode("/",$this->dDob);
		list($month,$dt,$year)=$arrDob;
		$dob=$year."-".$month."-".$dt;

		$sql		= "INSERT INTO ".TABLEPREFIX."user (vLogin, vPass, vEmail, vGender, dDob,
								   vCountry, vState, vCity, vCounty, vStatus, vHearing_Source,
								   vBilling, dActive_Date, dLast_Login, dLast_Login_Time,
								   vFirstName, vMiddleName, vLastName, vRealtion_Status,
								   vAstro_Sign, nHeight, vBody_Type, vMobile, vProvider, vSmoking,
								   vDrinking, nChildren, vEthinicity, vReligion, vEducation,
								   tmy_looks_today, tmy_likes_onanyday, tmy_dislikes_onanyday,
								   tmy_mood_today, tmy_personality,tmy_music, tmy_movies,
								   tmy_tv, tmy_sports_play, tmy_sports_watch, tmy_travel_been,
								   tmy_travel_going, tmy_arts_culture_events, tmy_poison_place,
								   taday_in_my_life, vmy_night_life_out, vmy_night_life_in,
								   tmy_food, tmy_money, tmy_last_restaurant, tmy_charity, 
								   tmy_last_restaurant_review, tmy_politics,
								   tmy_major_world_issue, tmy_doings_on_major_world_issue,
								   tmy_scenario_question_one, tmy_scenario_answer_one,
								   tmy_scenario_question_two, tmy_scenario_answer_two,
								   vTitle, tmy_perfect_mate , vOnline, vFeatured, vId_Varified,
								   vBC_Verified, dStartDate, vProfileType, tmy_profile)
					  VALUES ('".addslashes($this->vLogin)."', '".md5(addslashes($this->vPass))."',
					          '".addslashes($this->vEmail)."', '".addslashes($this->vGender)."',
							  '".addslashes($dob)."', '".addslashes($this->vCountry)."',
							  '".addslashes($this->vState)."', '".addslashes($this->vCity)."',
							  '".addslashes($this->vCounty)."', '".addslashes($this->vStatus)."',
							  '".addslashes($this->vHearing_Source)."', 
							  '".addslashes($this->vBilling)."', '".addslashes($this->dActive_Date)."',
							  '".addslashes($this->dLast_Login)."', 
							  '".addslashes($this->dLast_Login_Time)."',
							  '".addslashes($this->vFirstName)."', '".addslashes($this->vMiddleName)."',
							  '".addslashes($this->vLastName)."', 
							  '".addslashes($this->vRealtion_Status)."', 
							  '".addslashes($this->vAstro_Sign)."', '".addslashes($this->nHeight)."',
							  '".addslashes($this->vBody_Type)."', '".addslashes($this->vMobile)."',
							  '".addslashes($this->vProvider)."',
							  '".addslashes($this->vSmoking)."', '".addslashes($this->vDrinking)."',
							  '".addslashes($this->nChildren)."', '".addslashes($this->vEthinicity)."',
							  '".addslashes($this->vReligion)."', '".addslashes($this->vEducation)."',
							  '".addslashes($this->tmy_looks_today)."',
							  '".addslashes($this->tmy_likes_onanyday)."',
							  '".addslashes($this->tmy_dislikes_onanyday)."',
							  '".addslashes($this->tmy_mood_today)."',
							  '".addslashes($this->tmy_personality)."',
							  '".addslashes($this->tmy_music)."', '".addslashes($this->tmy_movies)."',
							  '".addslashes($this->tmy_tv)."', '".addslashes($this->tmy_sports_play)."',
							  '".addslashes($this->tmy_sports_watch)."',
							  '".addslashes($this->tmy_travel_been)."',
							  '".addslashes($this->tmy_travel_going)."',
							  '".addslashes($this->tmy_arts_culture_events)."',
							  '".addslashes($this->tmy_poison_place)."',
							  '".addslashes($this->taday_in_my_life)."',
							  '".addslashes($this->vmy_night_life_out)."',
							  '".addslashes($this->vmy_night_life_in)."',
							  '".addslashes($this->tmy_food)."', '".addslashes($this->tmy_money)."',
							  '".addslashes($this->tmy_last_restaurant)."', 
							   '".addslashes($this->tmy_charity)."', 
							  '".addslashes($this->tmy_last_restaurant_review)."',
							  '".addslashes($this->tmy_politics)."', 
							  '".addslashes($this->tmy_major_world_issue)."',
							  '".addslashes($this->tmy_doings_on_major_world_issue)."',
							  '".addslashes($this->tmy_scenario_question_one)."',
							  '".addslashes($this->tmy_scenario_answer_one)."',
							  '".addslashes($this->tmy_scenario_question_two)."',
							  '".addslashes($this->tmy_scenario_answer_two)."',
							  '".addslashes($this->vTitle)."',
							  '".addslashes($this->tmy_perfect_mate)."',
							  '".addslashes($this->vOnline)."', '".addslashes($this->vFeatured)."',
							  '".addslashes($this->vId_Varified)."', 
							  '".addslashes($this->vBC_Verified)."', '{$date}',
							  '".addslashes($this->vProfileType)."',
							  '".addslashes($this->tmy_profile)."')";
                                                          

		$res		= @mysql_query($sql, $this->dblink);
		if (!$res) {
			$message	.= "Unable to add user, please try again later.<br>";
	   } else {
			$uid	= @mysql_insert_id($this->dblink);
			if ($uid) {
				$this->set_user_alert();
				$this->insert_user_alerts($uid);

				$sql		= "INSERT INTO ".TABLEPREFIX."payments (vMethod, vTxn_Id, dDate, nUser_Id, vReason)
							   VALUES ('Admin Posted', 'FREE', '{$date}', '{$uid}',
										'Profile Registration')";
				$res		= @mysql_query($sql, $this->dblink);
				if (!$res) {
					$message	.= "Unable to log your payment details.<br>";
				} else {
					$payid		= @mysql_insert_id($this->dblink);
					$prid		= $this->get_product_id('Profile Registration');
					$message	.= $this->make_order($uid, $prid, $payid);
				}
			}
		}
		return $message;
	}

	function get_product_id($name='')
	{
		$id	=0;
		$sql	= "SELECT * FROM ".TABLEPREFIX."products WHERE vProdName = '{$name}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$row	= @mysql_fetch_array($res);
			$id		= $row['nProdId'];
		}
		return $id;
	}

	function make_order($uid=0, $prid=0, $pid=0)
	{
		$message	= "";
		$date		= date("Y-m-d H:i:s");
		$sql		= "INSERT INTO ".TABLEPREFIX."orders (nProdId, nUserId,
								nPayment_Id, dDate)
					   VALUES ('{$prid}', '{$uid}', '{$pid}', '{$date}')";
		$res		= @mysql_query($sql, $this->dblink);
	}


	function update($id)
	{
		$message	= "";

		//$arrDob=explode("-",$this->dDob);
                $arrDob=explode("/",$this->dDob);
		list($month,$date,$year)=$arrDob;
		$dob=$year."-".$month."-".$date;

		$sql		= "UPDATE ".TABLEPREFIX."user SET
						vLogin = '".addslashes($this->vLogin)."',
						vEmail = '".addslashes($this->vEmail)."',
						vGender = '".addslashes($this->vGender)."',
						dDob = '".addslashes($dob)."',
						vCountry = '".addslashes($this->vCountry)."',
						vState = '".addslashes($this->vState)."',
						vCounty = '".addslashes($this->vCounty)."',
						vCity = '".addslashes($this->vCity)."',
						vStatus = '".addslashes($this->vStatus)."',
						vHearing_Source = '".addslashes($this->vHearing_Source)."',
						vBilling = '".addslashes($this->vBilling)."',
						vOnline = '".addslashes($this->vOnline)."',
						vFeatured = '".addslashes($this->vFeatured)."',
						vId_Varified = '".addslashes($this->vId_Varified)."',
						vBC_Verified = '".addslashes($this->vBC_Verified)."',
						vIntro_Check = '".addslashes($this->vIntro_Check)."',
						dLast_Login = '".addslashes($this->dLast_Login)."',
						vFirstName = '".addslashes($this->vFirstName)."',
						vMiddleName = '".addslashes($this->vMiddleName)."',
						vLastName = '".addslashes($this->vLastName)."',
						vRealtion_Status = '".addslashes($this->vRealtion_Status)."',
						vAstro_Sign = '".addslashes($this->vAstro_Sign)."',
						nHeight = '".addslashes($this->nHeight)."',
						vBody_Type = '".addslashes($this->vBody_Type)."',
						vProvider = '".addslashes($this->vProvider)."',
						vMobile = '".addslashes($this->vMobile)."',
						vSmoking = '".addslashes($this->vSmoking)."',
						vDrinking = '".addslashes($this->vDrinking)."',
						nChildren = '".addslashes($this->nChildren)."',
						vEthinicity = '".addslashes($this->vEthinicity)."',
						vReligion = '".addslashes($this->vReligion)."',
						vEducation = '".addslashes($this->vEducation)."', 
						tmy_looks_today = '".addslashes($this->tmy_looks_today)."',
						tmy_likes_onanyday = '".addslashes($this->tmy_likes_onanyday)."',
						tmy_dislikes_onanyday = '".addslashes($this->tmy_dislikes_onanyday)."',
						tmy_mood_today = '".addslashes($this->tmy_mood_today)."',
						tmy_personality = '".addslashes($this->tmy_personality)."',
						tmy_music = '".addslashes($this->tmy_music)."',
						tmy_movies = '".addslashes($this->tmy_movies)."',
						tmy_tv = '".addslashes($this->tmy_tv)."',
						tmy_sports_play = '".addslashes($this->tmy_sports_play)."',
						tmy_sports_watch = '".addslashes($this->tmy_sports_watch)."',
						tmy_travel_been = '".addslashes($this->tmy_travel_been)."',
						tmy_travel_going = '".addslashes($this->tmy_travel_going)."',
                                                taday_in_my_life = '".addslashes($this->taday_in_my_life)."',
                                                tmy_charity = '".addslashes($this->tmy_charity)."',
                                                vmy_night_life_out = '".addslashes($this->vmy_night_life_out)."',
                                                vmy_night_life_in = '".addslashes($this->vmy_night_life_in)."',
                                                tmy_food = '".addslashes($this->tmy_food)."',
                                                tmy_money = '".addslashes($this->tmy_money)."',
                                                tmy_last_restaurant = '".addslashes($this->tmy_last_restaurant)."',
                                                tmy_last_restaurant_review = '".addslashes($this->tmy_last_restaurant_review)."',

						tmy_arts_culture_events = '".addslashes($this->tmy_arts_culture_events)."',
						tmy_poison_place = '".addslashes($this->tmy_poison_place)."',
						tmy_politics = '".addslashes($this->tmy_politics)."',
						tmy_major_world_issue = '".addslashes($this->tmy_major_world_issue)."',
						tmy_doings_on_major_world_issue = '".addslashes($this->tmy_doings_on_major_world_issue)."',
						tmy_scenario_question_one = '".addslashes($this->tmy_scenario_question_one)."',
						tmy_scenario_answer_one = '".addslashes($this->tmy_scenario_answer_one)."',
						tmy_scenario_question_two = '".addslashes($this->tmy_scenario_question_two)."',
						tmy_scenario_answer_two = '".addslashes($this->tmy_scenario_answer_two)."',
						vTitle = '".addslashes($this->vTitle)."',
						tmy_perfect_mate = '".addslashes($this->tmy_perfect_mate)."',
						vProfileType = '".addslashes($this->vProfileType)."',
						dStartDate = now(),
						tmy_profile = '".addslashes($this->tmy_profile)."' 
					WHERE nUser_Id = '{$id}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update user, please try again later.<br>";
		return $message;

	}

	function update_password($id)
	{
		$sql	= "UPDATE ".TABLEPREFIX."user
				   SET vPass = '".md5(addslashes($this->vPass))."'
				   WHERE nUser_Id = '{$id}'";
		$res	= @mysql_query($sql, $this->dblink);
                
                $sql	= "SELECT * FROM ".TABLEPREFIX."user  
                           WHERE nUser_Id = '.{$id}.'";
                $res1	= @mysql_query($sql, $this->dblink);
                if (@mysql_num_rows($res1) > 0) {
                    
                    $row	= @mysql_fetch_array($res1);
                    require_once "settings.class.php";
                    //$admin_mail     = settings::getone('adminmail');
                    $settingsObj = new settings();
                    $admin_mail	= $settingsObj->getone('adminmail');
                   
                    $from	= $admin_mail;
                    $to		= $row['vEmail'];
                    $toname	= $row['vLogin'];
                    $fromname	= $site_name." Team";
                    $subject	= 'New Password';
                    $htmlbody	= '';

                    $basepath	= BASE_PATH;
                    $mail_title	= '';
                    $send_date	= date('F j, Y');
                    $content	= "<h2 style='font-size: 18px;'>Dear member ".$row['vLogin']." </h2>
                                                    <p>Your password has been changed by admin 
                                                    and your new password is ".md5(addslashes($this->vPass)).".</p>
                                                    <p>By Yours <br />".$site_name." Team</p>";
                    $headers = "From:$from\r\nReply-to: $from\r\nContent-type: text/html; charset=us-ascii";
                    mail($to,$subject,$content,$headers);
	}
        }

	function get_users()
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."user WHERE vStatus NOT LIKE 'D%' ORDER BY nUser_Id DESC";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function select($id=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."user WHERE nUser_Id = '{$id}' AND  vStatus NOT LIKE 'D%'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array = @mysql_fetch_array($res);
		}
		@mysql_free_result($res);
		return $array;
	}

	function delete_users($arr=array())
	{
		$message	= "";
		$ids		= isset($arr['ids'])	?	$arr['ids']	:	array();
		if (empty($ids))
			$message	=  "Please select the user(s) that you would like to delete.<br>";
		if ($message == "") {
			$idstring	= implode("','", $ids);

			$sql		= "UPDATE ".TABLEPREFIX."user 
						   SET vStatus = INSERT(vStatus, 1, 1, 'D')
						   WHERE nUser_Id IN ('$idstring')";
			$res		= @mysql_query($sql, $this->dblink);
			if (!$res)
				$message	= "Unable to delete the selected users, please try again later.<br>";
			else
				$message	= "<font color='green'>The selected user(s) deleted successfully</font>.<br>";
		}
		return $message;
	}

	function get_all_interests()
	{
		$array	= array();
		$sql	= "SELECT I.nInterest_Id, I.nUser_Id_From, U.vLogin AS vLogin_From,
						  I.nUser_Id_To, U1.vLogin AS vLogin_To, I.dDate, I.vStatus,
						  DATE_FORMAT(I.dDate, '%D %M %Y') as dDay
					FROM ".TABLEPREFIX."interests AS I
					JOIN ".TABLEPREFIX."user AS U ON U.nUser_Id = I.nUser_Id_From
					JOIN ".TABLEPREFIX."user AS U1 ON U1.nUser_Id = I.nUser_Id_To";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}

/************** INTERESTS SECTION STARTS *********************************/

	function delete_interests($arr=array())
	{
		$message	= "";
		$ids		= isset($arr['ids'])	?	$arr['ids']	:	array();
		if (empty($ids))
			$message	=  "Please select the interest you would like to delete.<br>";
		if ($message == "") {
			$idstring	= implode("','", $ids);

			$sql		= "DELETE FROM ".TABLEPREFIX."interests 
						   WHERE nInterest_Id IN ('$idstring')";
			$res		= @mysql_query($sql, $this->dblink);
			if (!$res)
				$message	= "Unable to delete the interests, please try again later.<br>";
			else
				$message	= "<font color='green'>Selected interests deleted successfully.</font><br>";
		}
		return $message;
	}

/************** INTERESTS SECTION ENDS *********************************/

/************** MESSAGES SECTION STARTS *********************************/

	function get_all_messages()
	{
		$array	= array();
		$sql	= "SELECT M.nMessage_Id, M.vTitle, M.dDate, M.vStatus, M.nUser_Id_From,
						  U.vLogin as vLogin_From, M.nUser_Id_To, U1.vLogin as vLogin_To,
						  DATE_FORMAT(M.dDate, '%D %M %Y') as dDay
					FROM ".TABLEPREFIX."message as M 
					JOIN ".TABLEPREFIX."user as U ON M.nUser_Id_From = U.nUser_Id
					JOIN ".TABLEPREFIX."user as U1 ON M.nUser_Id_To = U1.nUser_Id
					ORDER BY M.nMessage_Id DESC";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function delete_messages($arr=array())
	{
		$message	= "";
		$ids		= isset($arr['ids'])	?	$arr['ids']	:	array();
		if (empty($ids))
			$message	=  "Please select the messages you would like to delete.<br>";
		if ($message == "") {
			$idstring	= implode("','", $ids);

			$sql		= "DELETE FROM ".TABLEPREFIX."message 
						   WHERE nMessage_Id IN ('$idstring')";
			$res		= @mysql_query($sql, $this->dblink);
			if (!$res)
				$message	= "Unable to delete the selected message(s), please try again later.<br>";
			else
				$message	= "<font color='green'>The selected message(s) have been successfully deleted.</font><br>";
		}
		return $message;
	}

	function set_message($arr=array())
	{
		$this->vTitle				= isset($arr['vTitle'])				?	stripslashes(trim($arr['vTitle']))				:	"";
		$this->tContent				= isset($arr['tContent'])			?	stripslashes(trim($arr['tContent']))			:	"";
		$this->vLogin_From		= isset($arr['vLogin_From'])		?	stripslashes(trim($arr['vLogin_From']))		:	"";
		$this->vLogin_To			= isset($arr['vLogin_To'])		?	stripslashes(trim($arr['vLogin_To']))			:	"";
		$this->dDate				= isset($arr['dDate'])				?	stripslashes(trim($arr['dDate']))				:	date("Y-m-d H:i:s");
		$this->vStatus				= isset($arr['vStatus'])			?	stripslashes(trim($arr['vStatus']))			:	"NN";
	}

	function get_message($id=0)
	{
		$array	= array();
		$sql	= "SELECT M.*,U.vLogin as vLogin_From,U1.vLogin as vLogin_To  FROM ".TABLEPREFIX."message AS M 
                            JOIN ".TABLEPREFIX."user as U ON M.nUser_Id_From = U.nUser_Id  AND U.vStatus NOT LIKE 'D%' 
                            JOIN ".TABLEPREFIX."user as U1 ON M.nUser_Id_To = U1.nUser_Id AND U1.vStatus NOT LIKE 'D%'  
                            WHERE M.nMessage_Id = '{$id}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array = @mysql_fetch_array($res);
		}
		@mysql_free_result($res);
		return $array;
	}

	function save_message($id=0)
	{
		$message	= $this->check_message();
		if ($message == "") {
			if ($id >= 1) {
				$message	= $this->update_message($id);
			} else {
				$message	= $this->insert_message();
			}
		}
		return $message;

	}

	function check_message()
	{
		$message	= "";
		if ($this->vTitle  == "")
			$message	.= "Please enter a title for the message.<br>";
		if ($this->tContent == "")
			$message	.= "Please enter the content for the message.<br>";
		return $message;
	}

	function insert_message()
	{
		$message	= "";
		$sql		= "INSERT INTO ".TABLEPREFIX."message (nUser_Id_From, nUser_Id_To, vTitle,
												 tContent, dDate, vStatus)
					   VALUES ('".addslashes($this->nUser_Id_From)."',
							   '".addslashes($this->nUser_Id_To)."',
							   '".addslashes($this->vTitle)."', '".addslashes($this->tContent)."',
							   '".addslashes($this->dDate)."', '".addslashes($this->vStatus)."')";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to add message, please try again later.<br>";
		return $message;
	}

	function update_message($id)
	{
		$message	= "";
		$sql		= "UPDATE ".TABLEPREFIX."message
					   SET vTitle = '".addslashes($this->vTitle)."',
					       tContent = '".addslashes($this->tContent)."',
						   vStatus = '".addslashes($this->vStatus)."'
					   WHERE nMessage_Id = '{$id}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update message, please try again later.<br>";
		return $message;
	}

/************ PARTNER PREFERENCES ***************/

	function set_partner_preference($arr=array())
	{
		$this->nPartner_Pref_Id	= isset($arr['nPartner_Pref_Id'])	?	stripslashes(trim($arr['nPartner_Pref_Id']))	:	"";
		$this->nAge_Low			= isset($arr['nAge_Low'])			?	stripslashes(trim($arr['nAge_Low']))			:	"18";
		$this->nAge_High		= isset($arr['nAge_High'])			?	stripslashes(trim($arr['nAge_High']))			:	"99";
		$this->vBody_Type		= isset($arr['vBody_Type'])			?	stripslashes(trim($arr['vBody_Type']))			:	"";
		$this->vDrinking		= isset($arr['vDrinking'])			?	stripslashes(trim($arr['vDrinking']))			:	"";
		$this->vSmoking			= isset($arr['vSmoking'])			?	stripslashes(trim($arr['vSmoking']))			:	"";
		$this->vEye_Color		= isset($arr['vEye_Color'])			?	stripslashes(trim($arr['vEye_Color']))			:	"";
		$this->vHair_Color		= isset($arr['vHair_Color'])		?	stripslashes(trim($arr['vHair_Color']))			:	"";
		$this->vEthinicity		= isset($arr['vEthinicity'])		?	stripslashes(trim($arr['vEthinicity']))			:	"";
		$this->vRelegion		= isset($arr['vRelegion'])			?	stripslashes(trim($arr['vRelegion']))			:	"";
		$this->vEducation		= isset($arr['vEducation'])			?	stripslashes(trim($arr['vEducation']))			:	"";
		$this->vProfession		= isset($arr['vProfession'])		?	stripslashes(trim($arr['vProfession']))			:	"";
		$this->vIncome			= isset($arr['vIncome'])			?	stripslashes(trim($arr['vIncome']))				:	"";
		$this->vRelationship	= isset($arr['vRelationship'])		?	stripslashes(trim($arr['vRelationship']))		:	"";
		$this->vChildren		= isset($arr['vChildren'])			?	stripslashes(trim($arr['vChildren']))			:	"";
		if (isset($arr['vLanguages']) AND !empty($arr['vLanguages']) AND is_array($arr['vLanguages'])) {
			$this->vLanguages			= implode(",", $arr['vLanguages']);
		} else {
			$this->vLanguages			= isset($arr['vLanguages'])			?	stripslashes(trim($arr['vLanguages']))			:	"";
		}
		$this->nHeight_Low			= isset($arr['nHeight_Low'])		?	stripslashes(trim($arr['nHeight_Low']))			:	"";
		$this->nHeight_High			= isset($arr['nHeight_High'])		?	stripslashes(trim($arr['nHeight_High']))		:	"";
		$this->vFeet_Low			= isset($arr['vFeet_Low'])			?	stripslashes(trim($arr['vFeet_Low']))			:	"";
		$this->vInch_Low			= isset($arr['vInch_Low'])			?	stripslashes(trim($arr['vInch_Low']))			:	"";
		$this->vFeet_High			= isset($arr['vFeet_High'])			?	stripslashes(trim($arr['vFeet_High']))			:	"";
		$this->vInch_High			= isset($arr['vInch_High'])			?	stripslashes(trim($arr['vInch_High']))			:	"";

		if ($this->vFeet_Low <> "" AND $this->vInch_Low <> "" AND $this->nHeight_Low == "") {
			$this->nHeight_Low	= $this->vInch_Low;
			$this->nHeight_Low	+= 12*$this->vFeet_Low;

		} else if ($this->nHeight_Low <> "") {
			$this->vFeet_Low	= floor($this->nHeight_Low/12);
			$this->vInch_Low	= $this->nHeight_Low%12;
		}
		if ($this->vFeet_High <> "" AND $this->vInch_High <> "" AND $this->nHeight_High == "") {
			$this->nHeight_High	= $this->vInch_High;
			$this->nHeight_High	+= 12*$this->vFeet_High;

		} else if ($this->nHeight_High <> "") {
			$this->vFeet_High	= floor($this->nHeight_High/12);
			$this->vInch_High	= $this->nHeight_High%12;
		}

	}

	function get_user_partner_preference($uid=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."user as U LEFT JOIN ".TABLEPREFIX."partner_preferance as P
		           ON U.nUser_Id = P.nUser_Id 
			       WHERE U.nUser_Id = '{$uid}' AND U.vStatus NOT LIKE 'D%'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		@mysql_free_result();
		return $array;
	}

	function get_user_partner_preference_once($uid=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."partner_preferance
			       WHERE nUser_Id = '{$uid}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		@mysql_free_result();
		return $array;
	}

	function save_user_partner_preference($uid=0, $id=0)
	{
		$message	= "";
		if ($id > 0) {
			$message	.= $this->update_user_partner_preference($uid, $id);
		} else {
			$message	.= $this->insert_user_partner_preference($uid);
		}
		return $message;
	}

	function insert_user_partner_preference($uid=0)
	{
		$message	= "";
		$sql		= "INSERT INTO ".TABLEPREFIX."partner_preferance (nUser_Id, nAge_Low, nAge_High,
								   vBody_Type, nHeight_Low, nHeight_High, vDrinking,
								   vSmoking, vEye_Color, vHair_Color, vEthinicity,
								   vRelegion, vEducation, vLanguages, vProfession,
								   vIncome, vRelationship, vChildren)
				       VALUES ('{$uid}', '".addslashes($this->nAge_Low)."',
							   '".addslashes($this->nAge_High)."',
							   '".addslashes($this->vBody_Type)."',
							   '".addslashes($this->nHeight_Low)."',
							   '".addslashes($this->nHeight_High)."',
							   '".addslashes($this->vDrinking)."',
							   '".addslashes($this->vSmoking)."',
							   '".addslashes($this->vEye_Color)."',
							   '".addslashes($this->vHair_Color)."',
							   '".addslashes($this->vEthinicity)."',
							   '".addslashes($this->vRelegion)."',
							   '".addslashes($this->vEducation)."',
							   '".addslashes($this->vLanguages)."',
							   '".addslashes($this->vProfession)."',
							   '".addslashes($this->vIncome)."',
							   '".addslashes($this->vRealationship)."',
							   '".addslashes($this->vChildren)."')";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res) {
			$message	.= "Unable to add partner preference, please try later.<br>";
		} else {
			$this->nPartner_Pref_Id	= @mysql_insert_id($this->dblink);
		}
		return $message;
	}

	function update_user_partner_preference($uid=0, $id=0)
	{
		$message	= "";
		$sql		= "UPDATE ".TABLEPREFIX."partner_preferance
		               SET nAge_Low	= '".addslashes($this->nAge_Low)."',
					       nAge_High = '".addslashes($this->nAge_High)."',
						   vBody_Type = '".addslashes($this->vBody_Type)."',
                           nHeight_Low = '".addslashes($this->nHeight_Low)."',
                           nHeight_High = '".addslashes($this->nHeight_High)."',
                           vDrinking = '".addslashes($this->vDrinking)."',
                           vSmoking = '".addslashes($this->vSmoking)."',
                           vEye_Color = '".addslashes($this->vEye_Color)."',
                           vHair_Color = '".addslashes($this->vHair_Color)."',
                           vEthinicity = '".addslashes($this->vEthinicity)."',
                           vRelegion = '".addslashes($this->vRelegion)."',
                           vEducation = '".addslashes($this->vEducation)."',
                           vLanguages = '".addslashes($this->vLanguages)."',
						   vProfession = '".addslashes($this->vProfession)."',
						   vIncome = '".addslashes($this->vIncome)."',
                           vRelationship = '".addslashes($this->vRelationship)."',
                           vChildren = '".addslashes($this->vChildren)."'
					   WHERE nUser_Id = '{$uid}' AND nPartner_Pref_Id = '{$id}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update your partner preferences, please try again later.<br>";
		return $message;
	}

	function mobile_alert_activated()
	{
		$flag	= false;
		require_once "settings.class.php";
		//$array	= settings::select();
                $settingsObj = new settings();
                $array	= $settingsObj->select();
		if (!empty($array)) {
			if ($array['mobile_alert'] == "YES")
				$flag	= true;
		}
		return $flag;
	}

	function set_user_alert($arr=array())
	{
		$this->nAlert_Id		= isset($arr['nAlert_Id'])		?	stripslashes(trim($arr['nAlert_Id']))		:	"0";
		$this->nUser_Id			= isset($arr['nUser_Id'])		?	stripslashes(trim($arr['nUser_Id']))		:	"0";
		$this->nNewUser			= isset($arr['nNewUser'])		?	stripslashes(trim($arr['nNewUser']))		:	"N";
		$this->nAddFavourites	= isset($arr['nAddFavourites'])	?	stripslashes(trim($arr['nAddFavourites']))	:	"N";
		$this->nProfileViewed	= isset($arr['nProfileViewed'])	?	stripslashes(trim($arr['nProfileViewed']))	:	"N";
		$this->nAddHot			= isset($arr['nAddHot'])		?	stripslashes(trim($arr['nAddHot']))			:	"N";
		$this->nNewMessageMobile= isset($arr['nNewMessageMobile'])	?	stripslashes(trim($arr['nNewMessageMobile']))	:	"N";
		$this->nNewInterestMobile= isset($arr['nNewInterestMobile'])?	stripslashes(trim($arr['nNewInterestMobile']))	:	"N";
	}

	function get_user_alerts($id=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."user as U LEFT JOIN ".TABLEPREFIX."alert as A
		           ON U.nUser_Id = A.nUser_Id 
				   WHERE U.nUser_Id = '{$id}' AND U.vStatus NOT LIKE 'D%'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		@mysql_free_result($res);
		return $array;
	}

	function get_user_alerts_only($id=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."alert 
				   WHERE nUser_Id = '{$id}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		@mysql_free_result($res);
		return $array;
	}

	function save_user_alerts($uid=0, $id=0)
	{
		$message	= "";
		if ($id > 0) {
			$message	.= $this->update_user_alerts($uid, $id);
		} else {
			$message	.= $this->insert_user_alerts($uid);
		}
		return $message;
	}

	function insert_user_alerts($uid)
	{
		$message	= "";
		$sql		= "INSERT INTO ".TABLEPREFIX."alert (nUser_Id, nNewUser, nAddFavourites,
									          nProfileViewed, nAddHot, nNewMessageMobile,
											  nNewInterestMobile)
					   VALUES ('{$uid}', '".addslashes($this->nNewUser)."',
					           '".addslashes($this->nAddFavourites)."',
							   '".addslashes($this->nProfileViewed)."',
							   '".addslashes($this->nAddHot)."',
							   '".addslashes($this->nNewMessageMobile)."',
							   '".addslashes($this->nNewInterestMobile)."')";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res) {
			$message	.= "Unable to set alerts, please try later.<br>";
		} else {
			$this->nAlert_Id	= @mysql_insert_id($this->dblink);
		}
		return $message;
	}

	function update_user_alerts($uid, $id)
	{
		$message	= "";
		$sql		= "UPDATE ".TABLEPREFIX."alert
		               SET nNewUser =  '".addslashes($this->nNewUser)."',
					       nAddFavourites = '".addslashes($this->nAddFavourites)."',
                           nProfileViewed = '".addslashes($this->nProfileViewed)."',
						   nAddHot = '".addslashes($this->nAddHot)."',
						   nNewMessageMobile = '".addslashes($this->nNewMessageMobile)."',
						   nNewInterestMobile = '".addslashes($this->nNewInterestMobile)."'
					   WHERE nUser_Id = '{$uid}' AND nAlert_Id = '{$id}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update your alerts, please try again later.<br>";
		return $message;
	}

	function set_user_image($arr=array())
	{
		$this->vTitle	= isset($arr['vTitle'])		?	stripslashes(trim($arr['vTitle']))	:	"";
		$this->nUser_Id	= isset($arr['nUser_Id'])	?	stripslashes(trim($arr['nUser_Id'])):	"0";
		$this->nPhoto_Id= isset($arr['nPhoto_Id'])	?	stripslashes(trim($arr['nPhoto_Id'])):	"0";
		$this->vUrl		= isset($arr['vUrl'])		?	stripslashes(trim($arr['vUrl']))	:	"";
		$this->dDate	= isset($arr['dDate'])		?	stripslashes(trim($arr['dDate']))	:	date("Y-m-d H:i:s");
		$this->arrFile		= isset($arr['file']) && !empty($arr['file'])	?	$arr['file']	   :   array();
	}

	function get_user_image($uid=0, $id=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."photos
		           WHERE nUser_Id = '{$uid}' AND nPhoto_Id = '{$id}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		return $array;
	}

	function get_image($id=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."photos
		           WHERE nPhoto_Id = '{$id}'"; 
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			$array	= @mysql_fetch_array($res);
		}
		return $array;
	}

	function get_user_images($uid=0)
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."photos
		           WHERE nUser_Id = '{$uid}'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_assoc($res)) {
				$array[]	= $row;
			}
		}
		return $array;
	}

	function delete_user_image($uid=0, $id=0,$apiflag=0)
	{
            $array	= $this->get_user_image($uid, $id);
            
            if($apiflag)
                        {
                            $path = str_replace('api/', '', PROFILE_IMAGE_PATH);
                        }else{
                            $path = PROFILE_IMAGE_PATH;
                        }
            
            
		if (!empty($array)) {
			
				@unlink($path.DIRECTORY_SEPARATOR.$array['vUrl']);
/* Thumbnail code */
				
					@unlink($path.DIRECTORY_SEPARATOR."pthumb_".$array['vUrl']);
				
				
					@unlink($path.DIRECTORY_SEPARATOR."sthumb_".$array['vUrl']);
				
/* Thumbnail code */

				$sql	= "DELETE FROM ".TABLEPREFIX."photos
				           WHERE nUser_Id = '{$uid}' AND nPhoto_Id = '{$id}'";
				$res	= @mysql_query($sql, $this->dblink);
			
		}
	}

	function save_user_image($uid=0, $id=0,$apiflag)
	{
		$message	= $this->check_user_image($uid, $id,$apiflag);
		if ($message == "") {
			if ($id >= 1) {
				$message	= $this->update_user_image($uid, $id,$apiflag);
			} else {
				if ($this->arrFile['size'] > 0) {
					$message	= $this->insert_user_image($uid);
				} else {
					$message	= "Please browse to select an image to upload.<br>";
				}
			}
		}
		if ($message == "")
			$message	= "<font color='green'>Your image has been uploaded successfully.</font><br>";

		return $message;
	}

        function getPhotoDetails($pid)
        {
            
        }
        
        
	function check_user_image($uid, $id,$apiflag)
	{
		$message	= "";
		if ($this->vTitle == "")
			$message	.= "Please enter a title for the image.<br>";
		if ($this->arrFile['size'] > 0) {
			$extn	= substr(strrchr($this->arrFile['name'], "."), 1);
			if (!in_array($extn, $this->arrExtns)) {
				$message	.= "The extension <b>".$extn."</b> is not allowed.<br>";
			} else {
				$message	.= $this->save_image($uid, $id,$apiflag);
			}
		}
		return $message;
	}

	function save_image($uid, $id,$apiflag)
	{
		$message	= "";
		if ($id <= 0)
			$message	= $this->upload_image($uid,$apiflag);
		else
			$message	= $this->change_image($uid, $id,$apiflag);
		return $message;
	}

	function upload_image($uid,$apiflag)
	{
		$message	= "";
		if (@is_uploaded_file($this->arrFile['tmp_name'])) {
			$extn		= substr(strrchr($this->arrFile['name'], "."), 1);
			$uploadfile	= $uid."_".$this->generate_password().".".$extn;
                        //echo PROFILE_IMAGE_PATH.DIRECTORY_SEPARATOR.$uploadfile;
                        //exit;
                        //echo $apiflag; exit;
                        if($apiflag)
                        {
                            $path = str_replace('api/', '', PROFILE_IMAGE_PATH);
                            $path = str_replace('admin/', '', $path);

                           
                        }else{
                            $path = PROFILE_IMAGE_PATH;
                        }
                       // echo $apiflag; exit;
                       
                        $filemove = @move_uploaded_file($this->arrFile['tmp_name'], $path.DIRECTORY_SEPARATOR.$uploadfile);
                        
                        if(!$filemove)
                        {
                            
                            $filename = $path.DIRECTORY_SEPARATOR.$uploadfile;
                            $content = fopen($this->arrFile['tmp_name'], "r");
                            $filemove = file_put_contents($filename, $content);
                        }
                        
                        
                        if ($filemove) {
				$this->vUrl	= $uploadfile; 
/* Thumbnail code */
				require_once "thumbnail.class.php";
				$objCThumb	= new thumbnail($path.DIRECTORY_SEPARATOR.$uploadfile, 100, 100);
				$objCThumb->save($uploadfile, $path.DIRECTORY_SEPARATOR, "sthumb_");
				$objCThumb1	= new thumbnail($path.DIRECTORY_SEPARATOR.$uploadfile, 300, 300);
				$objCThumb1->save($uploadfile, $path.DIRECTORY_SEPARATOR, "pthumb_");
/* Thumbnail code */

			} else {
				$message	.= "File cannot be saved due to possible file upload attack(s).<br>";
			}
		} else {
			$message	.= "File cannot be saved due to possible file upload attack.<br>";
		}
		return $message;
	}

	function change_image($uid, $id,$apiflag)
	{ 
		$message		= "";
		$array			= $this->get_user_image($uid, $id);
		$this->vUrl		= $array['vUrl'];
                
              if($apiflag)
                        {
                            $path = str_replace('api/', '', PROFILE_IMAGE_PATH);
                        }else{
                            $path = PROFILE_IMAGE_PATH;
                        }
                
		if (@is_uploaded_file($this->arrFile['tmp_name'])) {
			$extn		= substr(strrchr($this->arrFile['name'], "."), 1);
			$uploadfile	= $uid."_".$this->generate_password().".".$extn;
			if (@move_uploaded_file($this->arrFile['tmp_name'], $path.DIRECTORY_SEPARATOR.$uploadfile)) {
				
					@unlink($path.DIRECTORY_SEPARATOR.$this->vUrl);
				

/* Thumbnail code */
				
					@unlink($path.DIRECTORY_SEPARATOR."pthumb_".$this->vUrl);
				
				
					@unlink($path.DIRECTORY_SEPARATOR."sthumb_".$this->vUrl);
				
				require_once "thumbnail.class.php";
				$objCThumb	= new thumbnail($path.DIRECTORY_SEPARATOR.$uploadfile, 100, 100);
				$objCThumb->save($uploadfile, $path.DIRECTORY_SEPARATOR, "sthumb_");
				$objCThumb1	= new thumbnail($path.DIRECTORY_SEPARATOR.$uploadfile, 300, 300);
				$objCThumb1->save($uploadfile, $path.DIRECTORY_SEPARATOR, "pthumb_");
/* Thumbnail code */

				$this->vUrl	= $uploadfile;
				$messagae	= $this->change_image_in_table($uid, $id);
			} else {
				$message	.= "File cannot be saved due to possible file upload attack(s).<br>";
			}
		} else {
			$message	.= "File cannot be saved due to possible file upload attack.<br>";
		}
		return $message;
	}

	function change_image_in_table($uid, $id)
	{
		$messagae	= "";
		$sql		= "UPDATE ".TABLEPREFIX."photos 
					   SET vUrl  = '".addslashes($this->vUrl)."'
					   WHERE nPhoto_Id = '{$id}' AND nUser_Id = '{$uid}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update user image, please try again later.<br>";
		return $message;
	}

	function insert_user_image($uid)
	{
		$messagae	= "";
		$sql		= "INSERT INTO ".TABLEPREFIX."photos (nUser_Id, vTitle, vUrl, dDate)
					   VALUES ('".addslashes($uid)."',
							   '".addslashes($this->vTitle)."',
							   '".addslashes($this->vUrl)."',
							   '".addslashes($this->dDate)."')";
		$res		= @mysql_query($sql, $this->dblink);
                
		if (!$res)
			$message	.= "Unable to add success story, please try again later.<br>";
		return $message;
	}

	function update_user_image($uid, $id)
	{
		$messagae	= "";
		$sql		= "UPDATE ".TABLEPREFIX."photos 
					   SET vTitle = '".addslashes($this->vTitle)."'
					   WHERE nPhoto_Id = '{$id}' AND nUser_Id = '{$uid}'";
		$res		= @mysql_query($sql, $this->dblink);
		if (!$res)
			$message	.= "Unable to update success story image, please try again later.<br>";
		return $message;
	}


	function search_messages($arrP=array(), $flag=false,$order=' ')
	{
		$array	= array();
		$arraysearch	= array();
		$string			= "";

		$search	= isset($arrP['api_search'])	?	stripslashes(trim($arrP['api_search']))	:	"";

		if ($flag) {
			$_SESSION['api_search']	= "";

			$string	= "";
			$title	= isset($arrP['title'])	?	stripslashes(trim($arrP['title']))	:	"";
			$from	= isset($arrP['from'])	?	stripslashes(trim($arrP['from']))	:	"";
			$to		= isset($arrP['to'])	?	stripslashes(trim($arrP['to']))		:	"";
			$date	= isset($arrP['date'])	?	stripslashes(trim($arrP['date']))	:	"";
			if ($title <> "")
				$string	.= "LOWER(M.vTitle) LIKE '".strtolower(addslashes($title))."%' AND ";
			if ($date <> "")
				$string	.= "DATE_FORMAT(M.dDate, '%m/%d/%Y') = '".addslashes($date)."' AND ";
			if ($from <> "")
				$string	.= "U.vLogin = '".addslashes($from)."' AND ";
			if ($to <> "")
				$string	.= "U1.vLogin = '".addslashes($to)."' AND ";

			if ($string <> "")
				$string	= " WHERE ".$string." 1=1";

			$arraysearch['search']		= $string;
			$arraysearch['date']		= addslashes($date);
			$arraysearch['title']		= addslashes($title);
			$arraysearch['from']		= addslashes($from);
			$arraysearch['to']			= addslashes($to);

			$this->arrSearch			= $arraysearch;
			$_SESSION['api_search']		= serialize($arraysearch);

		} else {
			if ($search <> "") {
				$this->arrSearch = unserialize($search);
				$string	= $this->arrSearch['search'];
			}
		}

		$sql	= "SELECT M.nMessage_Id, M.vTitle, M.dDate, M.vStatus, M.nUser_Id_From,
						  U.vLogin as vLogin_From, M.nUser_Id_To, U1.vLogin as vLogin_To,
						  DATE_FORMAT(M.dDate, '%D %M %Y') as dDay
					FROM ".TABLEPREFIX."message as M 
					JOIN ".TABLEPREFIX."user as U ON M.nUser_Id_From = U.nUser_Id  AND U.vStatus NOT LIKE 'D%'
					JOIN ".TABLEPREFIX."user as U1 ON M.nUser_Id_To = U1.nUser_Id 
					      AND U1.vStatus NOT LIKE 'D%' ".$string;
                 if($order!=' '){
                    $sql.=  " ORDER BY ".$order;
                    
                    }
                    else{
                        $sql .=" ORDER BY M.nMessage_Id DESC";
                    }                                  

                                              
					
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function search_interests($arrP=array(), $flag=false,$order=' ')
	{
		$array	= array();
		$arraysearch	= array();
		$string			= "";

		$search	= isset($arrP['api_search'])	?	stripslashes(trim($arrP['api_search']))	:	"";

		if ($flag) {
			$_SESSION['api_search']	= "";

			$string	= "";
			$from	= isset($arrP['from'])	?	stripslashes(trim($arrP['from']))	:	"";
			$to		= isset($arrP['to'])	?	stripslashes(trim($arrP['to']))		:	"";
			$date	= isset($arrP['date'])	?	stripslashes(trim($arrP['date']))	:	"";
			if ($date <> "")
				$string	.= "DATE_FORMAT(I.dDate, '%m/%d/%Y') = '".addslashes($date)."' AND ";
			if ($from <> "")
				$string	.= "U.vLogin = '".addslashes($from)."' AND ";
			if ($to <> "")
				$string	.= "U1.vLogin = '".addslashes($to)."' AND ";

			if ($string <> "")
				$string	= " WHERE ".$string." 1=1";

			$arraysearch['search']		= $string;
			$arraysearch['date']		= addslashes($date);
			$arraysearch['from']		= addslashes($from);
			$arraysearch['to']			= addslashes($to);

			$this->arrSearch			= $arraysearch;
			$_SESSION['api_search']		= serialize($arraysearch);

		} else {
			if ($search <> "") {
				$this->arrSearch = unserialize($search);
				$string	= $this->arrSearch['search'];
			}
		}

		$sql	= "SELECT I.nInterest_Id, I.nUser_Id_From, U.vLogin AS vLogin_From,
						  I.nUser_Id_To, U1.vLogin AS vLogin_To, I.dDate, I.vStatus,
						  DATE_FORMAT(I.dDate, '%D %M %Y') as dDay
					FROM ".TABLEPREFIX."interests AS I
					JOIN ".TABLEPREFIX."user AS U ON U.nUser_Id = I.nUser_Id_From AND U.vStatus NOT LIKE 'D%'
					JOIN ".TABLEPREFIX."user AS U1 ON U1.nUser_Id = I.nUser_Id_To 
					      AND U1.vStatus NOT LIKE 'D%' ".$string;
                 if($order!=' '){
                    $sql.=  " ORDER BY ".$order;
                    
                    }
                    else{
                        $sql .=" ORDER BY I.nInterest_Id DESC";
                    }
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}
        
         function search_users_count($arrP=array(), $flag=false,$order=' ')
	{
		$array	= array();
		$arraysearch	= array();
		$string			= "";

		$search	= isset($arrP['api_search'])	?	stripslashes(trim($arrP['api_search']))	:	"";

		if ($flag) {
			$_SESSION['api_search']	= "";

			$string	= "";
			$user	= isset($arrP['user'])	?	stripslashes(trim($arrP['user']))	:	"";
			$name	= isset($arrP['name'])	?	stripslashes(trim($arrP['name']))	:	"";
			$gend	= isset($arrP['gend'])	?	stripslashes(trim($arrP['gend']))	:	"";
			$ddlSearch = isset($_POST['ddlSearch'])	?	stripslashes(trim($_POST['ddlSearch']))	:	"";

			if ($ddlSearch <> "")
			{
				if ($ddlSearch=='name')
					$string	.= "CONCAT_WS(' ', vFirstName,vMiddleName,vLastName) LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='username')
					$string	.= "vLogin LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='email')
					$string	.= "vEmail LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='age')
					$string	.= "(TRUNCATE((TO_DAYS(NOW()) - TO_DAYS(dDob))/365, 0) LIKE '%".strtolower(addslashes($user))."%') AND ";

			}//end if

			if ($gend <> "")
				$string	.= "vGender = '".addslashes($gend)."' AND ";

			$arraysearch['search']		= $string;
			$arraysearch['user']		= addslashes($user);
			$arraysearch['name']		= addslashes($name);
			$arraysearch['gend']		= addslashes($gend);

			$this->arrSearch			= $arraysearch;
			$_SESSION['api_search']		= serialize($arraysearch);

		} else {
			if ($search <> "") {
				$this->arrSearch = unserialize($search);
				$string	= $this->arrSearch['search'];
			}
		}
			if ($string <> "")
				$string	= " WHERE ".$string." vStatus NOT LIKE 'D%'";
			else
				$string	= " WHERE  vStatus NOT LIKE 'D%'";


		$sql	= "SELECT nUser_Id FROM ".TABLEPREFIX."user ".$string;
                if($order!=' '){                
			$sql.= 	   " ORDER BY ".$order;
                                
                }
                else{
                    $sql.= 	   " ORDER BY nUser_Id DESC";
                }

		$res	= @mysql_query($sql, $this->dblink);
                return mysql_num_rows($res);
//		if (@mysql_num_rows($res) > 0) {
//			while ($row = @mysql_fetch_array($res)) {
//				$array[]	= $row;
//			}
//		}
//		@mysql_free_result($res);
//		return $array;
	}

	function search_users($arrP=array(), $flag=false,$order=' ',$limit='',$pagination='',$Pagesize)
	{
		$array	= array();
		$arraysearch	= array();
		$string			= "";

		$search	= isset($arrP['api_search'])	?	stripslashes(trim($arrP['api_search']))	:	"";

		if ($flag) {
			$_SESSION['api_search']	= "";

			$string	= "";
			$user	= isset($arrP['user'])	?	stripslashes(trim($arrP['user']))	:	"";
			$name	= isset($arrP['name'])	?	stripslashes(trim($arrP['name']))	:	"";
			$gend	= isset($arrP['gend'])	?	stripslashes(trim($arrP['gend']))	:	"";
			$ddlSearch = isset($_POST['ddlSearch'])	?	stripslashes(trim($_POST['ddlSearch']))	:	"";

			if ($ddlSearch <> "")
			{
				if ($ddlSearch=='name')
					$string	.= "CONCAT_WS(' ', vFirstName,vMiddleName,vLastName) LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='username')
					$string	.= "vLogin LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='email')
					$string	.= "vEmail LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='age')
					$string	.= "(TRUNCATE((TO_DAYS(NOW()) - TO_DAYS(dDob))/365, 0) LIKE '%".strtolower(addslashes($user))."%') AND ";

			}//end if

			if ($gend <> "")
				$string	.= "vGender = '".addslashes($gend)."' AND ";

			$arraysearch['search']		= $string;
			$arraysearch['user']		= addslashes($user);
			$arraysearch['name']		= addslashes($name);
			$arraysearch['gend']		= addslashes($gend);

			$this->arrSearch			= $arraysearch;
			$_SESSION['api_search']		= serialize($arraysearch);

		} else {
			if ($search <> "") {
				$this->arrSearch = unserialize($search);
				$string	= $this->arrSearch['search'];
			}
		}
			if ($string <> "")
				$string	= " WHERE ".$string." vStatus NOT LIKE 'D%'";
			else
				$string	= " WHERE  vStatus NOT LIKE 'D%'";


		$sql	= "SELECT * FROM ".TABLEPREFIX."user ".$string;
                if($order!=' '){                
			$sql.= 	   " ORDER BY ".$order;
                                
                }
                else{
                    $sql.= 	   " ORDER BY nUser_Id DESC ";
                }
                 if($pagination!='')
                {
                    if($pagination==1)
                     {   $sql.=' LIMIT 0,'.$Pagesize;}
                    elseif($pagination==-1)
                    {
                        if($limit!='')
                            $sql.=' LIMIT '.$limit;
                    }
                    else
                    $sql.=' LIMIT '.($pagination-1)*$Pagesize.",".$Pagesize;
                }
                else {
                   $sql.=' LIMIT 0,'.$Pagesize;
               }
//echo $sql;


		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}
        function export_to_excel($arrP=array(), $flag=false,$order=' ')
	{
		$array	= array();
		$arraysearch	= array();
		$string			= "";

		$search	= isset($arrP['api_search'])	?	stripslashes(trim($arrP['api_search']))	:	"";

		if ($flag) {
			$_SESSION['api_search']	= "";

			$string	= "";
			$user	= isset($arrP['user'])	?	stripslashes(trim($arrP['user']))	:	"";
			$name	= isset($arrP['name'])	?	stripslashes(trim($arrP['name']))	:	"";
			$gend	= isset($arrP['gend'])	?	stripslashes(trim($arrP['gend']))	:	"";
			$ddlSearch = isset($_POST['ddlSearch'])	?	stripslashes(trim($_POST['ddlSearch']))	:	"";

			if ($ddlSearch <> "")
			{
				if ($ddlSearch=='name')
					$string	.= "CONCAT_WS(' ', vFirstName,vMiddleName,vLastName) LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='username')
					$string	.= "vLogin LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='email')
					$string	.= "vEmail LIKE '%".strtolower(addslashes($user))."%' AND ";
				if ($ddlSearch=='age')
					$string	.= "(TRUNCATE((TO_DAYS(NOW()) - TO_DAYS(dDob))/365, 0) LIKE '%".strtolower(addslashes($user))."%') AND ";

			}//end if

			if ($gend <> "")
				$string	.= "vGender = '".addslashes($gend)."' AND ";

			$arraysearch['search']		= $string;
			$arraysearch['user']		= addslashes($user);
			$arraysearch['name']		= addslashes($name);
			$arraysearch['gend']		= addslashes($gend);

			$this->arrSearch			= $arraysearch;
			$_SESSION['api_search']		= serialize($arraysearch);

		} else {
			if ($search <> "") {
				$this->arrSearch = unserialize($search);
				$string	= $this->arrSearch['search'];
			}
		}
			if ($string <> "")
				$string	= " WHERE ".$string." vStatus NOT LIKE 'D%'";
			else
				$string	= " WHERE  vStatus NOT LIKE 'D%'";


		$sql	= "SELECT * FROM ".TABLEPREFIX."user ".$string;
                if($order!=' '){                
			$sql.= 	   " ORDER BY ".$order;
                                
                }
                else{
                    $sql.= 	   " ORDER BY nUser_Id DESC";
                }

		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
                 $xldata	=	'<table width="100%"  border="1" cellspacing="0" cellpadding="0">
                          <tr>
                            <td class="support2" colspan="3">Users List &nbsp;&nbsp;</td>
                          </tr>
                         </table>
                         <table width="100%"  border="1" cellspacing="0" cellpadding="0">
                          <tr>
                            <td class="ba1">
                              <table width="100%"  border="1" cellspacing="1" cellpadding="3">
                              <tr class="ba1">
                                <td width="" class="dollar"><strong>Sl No</strong> </td>
                                <td width="60%" class="dollar"><strong>Username</strong> </td>
                                <td width="35%" class="dollar"><strong>Name</strong> </td>
                                <td width="35%" class="dollar"><strong>Gender</strong> </td>
                                <td width="35%" class="dollar"><strong>Email</strong> </td>
                                <td width="35%" class="dollar"><strong>Created date</strong> </td>
                                <td width="35%" class="dollar"><strong>Status</strong> </td>
                                </tr>';
                                    if(sizeof($array)>0) {
                                        $i=1;
                                        foreach($array as $row) {
                                             
                                             switch($row['vStatus']){
                                                 case"ANNN":
                                                     $status="Active";
                                                     break;
                                                 case"SNNN":
                                                     $status="Suspended";
                                                     break;
                                                 case"ENNN":
                                                     $status="Expired";
                                                     break;
                                                default: 
                                                     $status="Inactive";
                                                     break;
                                             }
                                            $xldata	= $xldata.' <tr bgcolor="#FFFFFF" class="maintext">
                                            <td width="5%">'.$i.'</td>    
                                            <td width="60%">'.htmlspecialchars(stripslashes($row['vLogin'])).'</td>
                                            <td width="35%">'.htmlspecialchars(stripslashes($row['vFirstName'])).' '.htmlspecialchars(stripslashes($row['vMiddleName'])).' '.htmlspecialchars(stripslashes($row['vLastName'])).'</td>
                                            <td width="35%">'.htmlspecialchars(stripslashes($row['vGender'])).'</td>
                                            <td width="35%">'.htmlspecialchars(stripslashes($row['vEmail'])).'</td>    
                                            <td width="35%">'.htmlspecialchars(stripslashes(date("m/d/Y",strtotime($row['dStartDate'])))).'</td>
                                            <td width="35%">'.$status.'</td>';
                                            $i++;
                                        }//end for
				   
                                }
                                $xldata	= $xldata.'        </table>
                                        </td>
                                      </tr>
                                    </table>';
							 
        
	header("Content-type: application/ms-excel");
	header("Content-Transfer-Encoding: binary");
	header("Content-Disposition: attachment; filename=\"UsersReport.xls\""); 
	echo $xldata;
        exit;
		//return $array;
	}

	function search_users2($arrP=array(), $flag=false,$limit='',$pagination='',$Pagesize)
	{
		$array	= array();
		$string			= "";

		$string	= "";
		$ddlProfile = isset($_POST['ddlProfile'])	?	stripslashes(trim($_POST['ddlProfile']))	:	$_GET['ddlProfile'];

		if ($ddlProfile <> "")
		{
			if ($ddlProfile=='active')
				$string	.= "vStatus LIKE '%ANNN%' ";
			if ($ddlProfile=='not')
				$string	.= "vStatus LIKE '%NNNN%' ";
			if ($ddlProfile=='susp')
				$string	.= "vStatus LIKE '%SNNN%' ";
			if ($ddlProfile=='expire')
				$string	.= "vStatus LIKE '%ENNN%' ";
			if ($ddlProfile=='all')
				$string	.= "vStatus NOT LIKE 'D%' ";
		}//end if

		$sql	= "SELECT * FROM ".TABLEPREFIX."user where ".$string."  
				   ORDER BY nUser_Id DESC";
                 if($pagination!='')
                {
                    if($pagination==1)
                     {   $sql.=' LIMIT 0,'.$Pagesize;}
                    elseif($pagination==-1)
                    {
                        if($limit!='')
                            $sql.=' LIMIT '.$limit;
                    }
                    else
                    $sql.=' LIMIT '.($pagination-1)*$Pagesize.",".$Pagesize;
                }
                else {
                   $sql.=' LIMIT 0,'.$Pagesize;
               }

		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) 
		{
			while ($row = @mysql_fetch_array($res)) 
			{
				$array[]	= $row;
			}//end while
		}//end if
		@mysql_free_result($res);
		return $array;
	}//end function
        
        function search_users2_count($arrP=array(), $flag=false)
	{
		$array	= array();
		$string			= "";

		$string	= "";
		$ddlProfile = isset($_POST['ddlProfile'])	?	stripslashes(trim($_POST['ddlProfile']))	:	$_GET['ddlProfile'];

		if ($ddlProfile <> "")
		{
			if ($ddlProfile=='active')
				$string	.= "vStatus LIKE '%ANNN%' ";
			if ($ddlProfile=='not')
				$string	.= "vStatus LIKE '%NNNN%' ";
			if ($ddlProfile=='susp')
				$string	.= "vStatus LIKE '%SNNN%' ";
			if ($ddlProfile=='expire')
				$string	.= "vStatus LIKE '%ENNN%' ";
			if ($ddlProfile=='all')
				$string	.= "vStatus NOT LIKE 'D%' ";
		}//end if

		$sql	= "SELECT nUser_Id FROM ".TABLEPREFIX."user where ".$string."  
				   ORDER BY nUser_Id DESC";
                

		$res	= @mysql_query($sql, $this->dblink);
		return mysql_num_rows($res) ;
	}

	function hear_list()
	{
		$array	= array();
		$sql	= "SELECT count(nUser_Id) as vCount,vHearing_Source
					FROM `".TABLEPREFIX."user` 
					WHERE vStatus NOT LIKE 'D%'
					GROUP BY vHearing_Source";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}
	
	function freecode_list()
	{
		$array	= array();
		$sql	= "select count(u.nUser_Id) as vCount,f.vCode from ".TABLEPREFIX."user u 
						left join ".TABLEPREFIX."payments p on u.nUser_Id=p.nUser_Id   
						left join ".TABLEPREFIX."orders o on p.nPayment_Id=o.nPayment_Id
						left join ".TABLEPREFIX."free_code f on f.nFreeCode_Id=o.nProdId
						where p.vMethod ='Free Code' and u.vStatus NOT LIKE 'D%'
						GROUP BY f.vCode";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function get_country_list()
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."country WHERE tc_status LIKE 'A'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[$row['tc_id']]	= $row['tc_name'];
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function get_state_list($name="")
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."state as S JOIN ".TABLEPREFIX."country as C
				   ON S.tc_id = C.tc_id AND S.ts_status LIKE 'A'
				   WHERE LOWER(C.tc_name) = '".addslashes(strtolower($name))."'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[$row['ts_id']]	= $row['ts_name'];
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function get_county_list($name="")
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."county as C JOIN  ".TABLEPREFIX."state as S 
				   ON C.ts_id = S.ts_id AND C.tco_status LIKE 'A'
				   WHERE LOWER(S.ts_name) = '".addslashes(strtolower($name))."'";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[$row['tco_id']]	= $row['tco_name'];
			}
		}
		@mysql_free_result($res);
		return $array;
	}

	function get_products($type='P', $view='A', $del='N')
	{
		$array	= array();
		$sql	= "SELECT * FROM ".TABLEPREFIX."products 
		           WHERE vType = '{$type}' AND vStatus = '{$view}' AND vDeleted = '{$del}'
				   ORDER BY nProdId";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);
		return $array;
	}
/***************************** CRONS ****************/

	function clean_up()
	{
		$time	= time();
		$sql	= "UPDATE ".TABLEPREFIX."user
				   SET vLogin = CONCAT(vLogin, NOW()+0), vStatus = INSERT (vStatus, 4, 1, 'C')
				   WHERE DATE_ADD(dLast_Login, INTERVAL 12 MONTH) <= CURDATE()
				   AND vStatus NOT LIKE '___C";

		$res	= @mysql_query($sql, $this->dblink);
		return $res;
	}

	function force_expired()
	{
            require_once "settings.class.php";
            require_once "misc.class.php";
            require_once ("userside.class.php");
            $objM		= new misc();            
            //$arrSet		= settings::select();
            $settingsObj = new settings();
            $arrSet	= $settingsObj->select();
            $intDay		= $arrSet['ValidityDayMembership'];
            if($arrSet['regmode']==REGISTRATION_PAID_MODE)
            {
		$date	= date("Y-m-d H:i:s");		
		$sql	= "UPDATE ".TABLEPREFIX."user
		           SET vStatus = INSERT (vStatus, 1, 1, 'E') WHERE DATE_ADD(dStartDate, INTERVAL $intDay DAY) <= '{$date}'";
		$res	= @mysql_query($sql, $this->dblink);
            }
            if($arrSet['regmode']==REGISTRATION_FREEMIUM_MODE)
            {             
                $date	= date("Y-m-d H:i:s");
                $freemiumPeriod = $arrSet['freemium_period'];       
                $this->deduct_credit_with_premium_credit_users($arrSet['credit_value'],$arrSet['membership_amount'],$intDay);                
                $this->deduct_credit_with_freemium_credit_users($arrSet['credit_value'],$freemiumPeriod,$arrSet['membership_amount']);                 
            }
	}

	function clear_uncompleted_users()
	{
		$date	= date("Y-m-d");
		$sql	= "UPDATE ".TABLEPREFIX."user
		           SET vLogin = CONCAT(vLogin, NOW()+0), vStatus = INSERT (vStatus, 4, 1, 'C')
				   WHERE DATE_ADD(dActive_Date, INTERVAL 1 DAY) < CURDATE()
				   AND vStatus = 'DDDD'";
		$res	= @mysql_query($sql, $this->dblink);
	}

	function force_logout()
	{
		$sql	= "UPDATE ".TABLEPREFIX."user
		           SET vOnline = 'Offline' 
				   WHERE DATE_ADD(dLast_Login_Time, INTERVAL 30 MINUTE) < NOW()";
		$res	= @mysql_query($sql, $this->dblink);
	}	
        
        function deduct_credit_with_freemium_credit_users($creditValue,$freemiumPeriod,$amount)
	{
		$array	= array();
                $date	= date("Y-m-d H:i:s");
                $creditExactValue = $amount/$creditValue;
                $creditRequired = ceil($creditExactValue);
		$sql	= "SELECT * FROM ".TABLEPREFIX."user WHERE vStatus NOT LIKE 'D%'  AND premiumUser='N' AND nCredits>=$creditRequired AND DATE_ADD(dStartDate, INTERVAL $freemiumPeriod DAY) <= '{$date}' ORDER BY nUser_Id DESC";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
                    while ($row = @mysql_fetch_array($res)) {
                            $array[]	= $row;
                    }
		}
		@mysql_free_result($res); 
		$objU			= new userside($this->dblink);              
                if($array){
                    foreach($array as $key=>$user){
                        $uid = $user['nUser_Id'];
                        $creditRequired =  number_format($creditRequired,2,".","");                        
                        mysql_query("update ".TABLEPREFIX."user set nCredits=nCredits-".$creditRequired.",premiumUser='Y' where nUser_Id='{$uid}'") or die(mysql_error());
                        $objU->renewal_finished($uid, "2", array());
                    }
                }	
	}
        
        function deduct_credit_with_premium_credit_users($creditValue,$amount,$intDay)
	{
		$array	= array();
                $date	= date("Y-m-d H:i:s");
                $creditExactValue = $amount/$creditValue;
                $creditRequired = ceil($creditExactValue);
		$sql	= "SELECT * FROM ".TABLEPREFIX."user WHERE vStatus NOT LIKE 'D%'  AND premiumUser='Y' AND DATE_ADD(dStartDate, INTERVAL $intDay DAY) <= '{$date}' ORDER BY nUser_Id DESC";
		$res	= @mysql_query($sql, $this->dblink);
		if (@mysql_num_rows($res) > 0) {
			while ($row = @mysql_fetch_array($res)) {
				$array[]	= $row;
			}
		}
		@mysql_free_result($res);               
                $objU			= new userside($this->dblink);                
                if($array){
                    foreach($array as $key=>$user){
                        $uid = $user['nUser_Id'];
                        $creditRequired =  number_format($creditExactValue,2,".","");          
                        if($user['nCredits']>=$creditRequired)
                        { 
                            mysql_query("update ".TABLEPREFIX."user set nCredits=nCredits-".$creditRequired." where nUser_Id='{$uid}'") or die(mysql_error());
                            $objU->renewal_finished($uid, "2", array());
                        }
                        else{
                            mysql_query("update ".TABLEPREFIX."user set  vStatus=INSERT (vStatus, 1, 1, 'E') where nUser_Id='{$uid}'") or die(mysql_error());
                        }
                    }
                }	
                
	}
   
}
?>