Location: PHPKode > scripts > Tiny P2P > tiny-p2p/P2P.cls.php
<?
	require_once("ClsConnection.cls.php");

	class SingleMember extends ClsConnection
	{
		var $ErrorInProfile;
		var $MemberId;
		var $MyFullName;
		var $MemberFullName;
		var $MemberCity;
		var $MemberBirthDay;
		var $MemberEducation;
		var	$MemRegDate;
		var	$JobTitle;
		var	$Company;
		var $PhotoName;
		
		//Constructor.
		function SingleMember()
		{
			$this->ClsConnection();	//Database Connection.
		}

		//Load One Member Detail Informations by Member Variables.
		function SingleMemberInfo()
		{
			$AminQuery="SELECT * FROM pla_registration WHERE MemberId=".$this->MemberId;	//echo $AminQuery;
			$QMemInfo=mysql_query($AminQuery);
			if(mysql_num_rows($QMemInfo)>0)
			{
				$RsMemInfo=mysql_fetch_object($QMemInfo);
				$this->MemberFullName=$RsMemInfo->FirstName." ".$RsMemInfo->SirName;
				$this->MemberCity=$RsMemInfo->PrimaryCity;
				$this->MemberBirthDay=substr($this->MonthName(substr($RsProfileInfo->DateOfBirth,5,2)),0,3)."-".substr($RsProfileInfo->DateOfBirth,8,2);
				$this->MemberEducation=$RsMemInfo->EduLevelOfEdu;
				$this->MemRegDate=substr($RsMemInfo->MemRegDateTime,0,10);
				$this->JobTitle=$RsMemInfo->EmpTitle;
				$this->Company=$RsMemInfo->EmpCompanyName;
				$AllImgName=explode(",",$RsMemInfo->PhotoName);
				$this->PhotoName=$AllImgName[0];
			}
			else
				$this->ErrorInProfile="Sorry! This member profile not found.";
		}
		
		//This Function Return Month Name against Month No.	 Input parameter=1 return "January"
		function MonthName($MonthNo)
		{
			switch($MonthNo)
			{
				case "01"	:	return "January";
				case "02"	:	return "February";
				case "03"	:	return "March";
				case "04"	:	return "April";
				case "05"	:	return "May";
				case "06"	:	return "June";
				case "07"	:	return "July";
				case "08"	:	return "Auguest";
				case "09"	:	return "September";
				case "10"	:	return "October";
				case "11"	:	return "November";
				case "12"	:	return "December";
				default: return "Month No Not Match";
			}
		}
	}	

	class P2PMembers extends SingleMember
	{
		var $Error="";
		var $AllMemberInfoTableName="pla_registration";
		var $NetworkTableName="p2p_network";
		var $WhosOnlineTable="m_usr_online";
		var $ConditionForAllMember="MemberStatus='Active Member'";
		var $MyMemberId=0;	//Root Member Id.	$MemberId(In Base Class-SingleMember)=For Temporary Processing.
		var $InviteStatus="Approved";	//Status= Approved, Pending, Deny
		var $TotalP2PMember=0;

		//Alphabet Listing. (A,B,C..Z).
		var $CssClassForAlphabetListing="";
		var $CurrentPageName="";
		var $NamePrefix="";

		//Display Variables
		var $PerPageRecord=2;		//Record Per Page.
		var $MaxListingPerPage=10;	//Listing (eg. 1,2,3,...10).
		var $ListingStart=1;
		var $CurListing=1;
		var $RecordStart=1;
		var $RecordEnd=1;
		var $TotalListing=0;
		
		//For Whos Online.
		var $MyFriendsOnline=false;	//False= All Online Members In P2P Network. True= All Online Members Who are My Friend Only
		
		//For Newest Members.
		var $NewestMember=false;

		// This Function Return an Array of All Member Ids (who are registered). 
		// (1) If NamePrefix=="" then MemberId returns against ConditionForAllMember condition.
		// (2) For NamePrefix value it return MemberIds Whose name start with 'NamePrefix'.
		function AllRegisteredMemberIds()
		{
			$this->Error="";
			if($this->NamePrefix=="")
				$Query="SELECT * FROM ".$this->AllMemberInfoTableName." WHERE ".$this->ConditionForAllMember;	//Set your condition 
			elseif($this->NamePrefix=="a2z")
				$Query="select * from ".$this->AllMemberInfoTableName." where MemberStatus='Active Member'";
			else
				$Query="select * from ".$this->AllMemberInfoTableName." where MemberStatus='Active Member' and '".$this->NamePrefix."' like SUBSTRING(FirstName,1,1)";
			if($this->NewestMember==true)	//Search Id for Newest Members.
				$Query.="ORDER BY MemberId DESC";
			else
				$Query.="ORDER BY FirstName";	//Alphabetic Sorting.
			//echo $Query;
			$QAllMember=mysql_query($Query);
			if(mysql_num_rows($QAllMember)>0)
			{
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					$AllMemIds[]=$RsMemInfo->MemberId;
				//foreach($AllMemIds as $CurMemId)	echo $CurMemId."<br>";
				$AllMemIds=array_unique($AllMemIds);
				$this->TotalP2PMember=count($AllMemIds);
				
				return $AllMemIds;
			}
			else
			{
				$this->Error="Sorry! No member found for the condition: ".$this->Condition;
				return $this->Error;
			}
		}
		
		// This Function Return All Member Ids Who are In my Network.
		function AllMemberIdsInMyNetwork()
		{
			$this->Error="";
			if($this->NamePrefix=="" || $this->NamePrefix=="a2z")
				$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->NetworkTableName." Net WHERE (Net.MemberId=".$this->MyMemberId." or Net.InvitedMemberId=".$this->MyMemberId.") AND Net.InviteStatus='Approved' AND (MI.MemberId=Net.MemberId OR MI.MemberId=Net.InvitedMemberId) AND MI.MemberStatus='Active Member' AND MI.MemberId<>".$this->MyMemberId;
			else
				$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->NetworkTableName." Net WHERE (Net.MemberId=".$this->MyMemberId." or Net.InvitedMemberId=".$this->MyMemberId.") AND Net.InviteStatus='Approved' AND (MI.MemberId=Net.MemberId OR MI.MemberId=Net.InvitedMemberId) AND MI.MemberStatus='Active Member' and '".$this->NamePrefix."' like SUBSTRING(MI.FirstName,1,1) AND MI.MemberId<>".$this->MyMemberId;
			//echo $Query;
			$QAllMember=mysql_query($Query);
			if(mysql_num_rows($QAllMember)>0)
			{
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					$AllMemIds[]=$RsMemInfo->MemId;
				array_unique($AllMemIds);
				$this->TotalP2PMember=count($AllMemIds);
				return $AllMemIds;
			}
			else
			{
				$this->Error="Sorry! No member in your network.";
				return $this->Error;
			}
		}

		// This Function Return All Member Ids Whos are Online. 
		//$this->MyFriendsOnline=false : All Online Members In P2P Network. $this->MyFriendsOnline=True: All Online Members Who are My Friend
		function AllOnlineMemberIds()
		{
			$this->Error="";
			if($this->MyFriendsOnline==false)	//All Online Members
			{
				if($this->NamePrefix=="" || $this->NamePrefix=="a2z")
					$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->WhosOnlineTable." WO WHERE WO.MemberId=MI.MemberId AND WO.status='Online' AND MI.MemberId<>".$this->MyMemberId;
				else
					$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->WhosOnlineTable." WO WHERE WO.MemberId=MI.MemberId AND WO.status='Online' AND MI.MemberId<>".$this->MyMemberId." AND '".$this->NamePrefix."' like SUBSTRING(MI.FirstName,1,1)";
			}
			else
			{
				if($this->NamePrefix=="" || $this->NamePrefix=="a2z")
					$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->WhosOnlineTable." WO,".$this->NetworkTableName." Net WHERE (Net.MemberId=".$this->MyMemberId." or Net.InvitedMemberId=".$this->MyMemberId.") AND WO.MemberId=MI.MemberId AND (MI.MemberId=Net.MemberId OR MI.MemberId=Net.InvitedMemberId) AND Net.InviteStatus='Approved' AND WO.status='Online' AND MI.MemberId<>".$this->MyMemberId;
				else
					$Query="SELECT MI.MemberId AS MemId FROM ".$this->AllMemberInfoTableName." MI,".$this->WhosOnlineTable." WO,".$this->NetworkTableName." Net WHERE (Net.MemberId=".$this->MyMemberId." or Net.InvitedMemberId=".$this->MyMemberId.") AND WO.MemberId=MI.MemberId AND (MI.MemberId=Net.MemberId OR MI.MemberId=Net.InvitedMemberId) AND Net.InviteStatus='Approved' AND WO.status='Online' AND MI.MemberId<>".$this->MyMemberId."AND '".$this->NamePrefix."' like SUBSTRING(MI.FirstName,1,1)";
			}			
			//echo $Query;
			$QAllMember=mysql_query($Query);
			if(mysql_num_rows($QAllMember)>0)
			{
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					$AllMemIds[]=$RsMemInfo->MemId;
				$AllMemIds=array_unique($AllMemIds);
				$this->TotalP2PMember=count($AllMemIds);
				return $AllMemIds;
			}
			else
			{
				$this->Error="Sorry! Currently no members are available online.";
				return $this->Error;
			}
		}
		
		// This Function Returns All Friends(Member) Who Are In My Network (Accept My Request and Whos request I Accept)
		// Please Set MyMemberId= Member id which Friends you want to get.
		function AllMemberIdsByInviteStatus()		//(Using Table: p2p_network)
		{
			$this->MemberId=$this->MyMemberId;
			if($this->InviteStatus=="Deny")		//Deny have one way display view.
				$Query="SELECT * FROM p2p_network WHERE MemberId=".$this->MemberId." and InviteStatus='".$this->InviteStatus."'";	//Set your condition 
			else
				$Query="SELECT * FROM p2p_network WHERE (MemberId=".$this->MemberId." or InvitedMemberId=".$this->MemberId.") and InviteStatus='".$this->InviteStatus."'";	//Set your condition 
			//echo "<br>".$Query;
			$QAllMember=mysql_query($Query);	//echo "<br>Total for ".$this->InviteStatus.":".mysql_num_rows($QAllMember);
			if(mysql_num_rows($QAllMember)>0)
			{
				$Counter=0;
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					if($this->MyMemberId!=$RsMemInfo->MemberId)	//Check This Id Invites(InvitedMemberId) or Invited by(MemberId).
						$AllMemIds[]=$RsMemInfo->MemberId;
					else
						$AllMemIds[]=$RsMemInfo->InvitedMemberId;
				echo "<br>For Member Id: ".$this->MemberId;
				$this->DisplayAllMemberIds($AllMemIds,$this->InviteStatus);	//Display All Member Ids According to Status
				array_unique($AllMemIds);
				return $AllMemIds;
			}
			else
			{	//echo "Sorry !!!!!!! No memmber.";
				$this->Error="Sorry! No member found for the invite status: '".$this->InviteStatus."'";
				return $this->Error;
			}
		}
		
		//This Function is used for display An Array of Member Id which is actually result of A status.
		function DisplayAllMemberIds($AllMemIds,$Status)
		{
			echo "<br>According to Status: ".$Status." Total Member:".count($AllMemIds)."<br>Ids: ";
			if(is_array($AllMemIds))
				foreach($AllMemIds as $CurId)	echo " ".$CurId." ";
			else
				echo $AllMemIds;
		}
		
		// Count Total Friend of $MemberId and Return.
		function TotalFriend($MemberId)		//(Using Table: p2p_network)
		{	
			$Aminul="select count(NetworkId) from p2p_network where (MemberId=$MemberId or InvitedMemberId=$MemberId) and InviteStatus='Approved'";
			//echo "<br>".$Aminul;
			$QForTotalFriend=mysql_query($Aminul);
			if(mysql_num_rows($QForTotalFriend)>0)
			{
				$RsTotalFriend=mysql_fetch_row($QForTotalFriend);
				return $RsTotalFriend[0];
			}
			else
				return 0;
		}
		
		// SetInvite Status="Approved/Pending/Deny" for Current Member($this->MemberId).
		function AminulSetInviteStatus()
		{
			//Find Relation between these two id;
			$InviteStatus="NeverInvited";
			if($this->MemberId==$this->MyMemberId)
				$InviteStatus="Myself";
			//Find for Approved By any one invitation.
			$QApprove="SELECT * FROM ".$this->NetworkTableName." WHERE ( (MemberId=".$this->MemberId." AND InvitedMemberId=".$this->MyMemberId.") OR (MemberId=".$this->MyMemberId." AND InvitedMemberId=".$this->MemberId.") ) AND InviteStatus='Approved'";
			$QPending="SELECT * FROM ".$this->NetworkTableName." WHERE ( (MemberId=".$this->MemberId." AND InvitedMemberId=".$this->MyMemberId.") OR (MemberId=".$this->MyMemberId." AND InvitedMemberId=".$this->MemberId.") ) AND InviteStatus='Pending'";
			$QDeny="SELECT * FROM ".$this->NetworkTableName." WHERE MemberId=".$this->MyMemberId." AND InvitedMemberId=".$this->MemberId." AND InviteStatus='Deny'";
			if(mysql_num_rows(mysql_query($QApprove))>0)
				$InviteStatus="Approved";
			elseif(mysql_num_rows(mysql_query($QPending))>0)
				$InviteStatus="Pending";
			elseif(mysql_num_rows(mysql_query($QDeny))>0)
				$InviteStatus="Deny";
			return $InviteStatus;
		}
		
		//Create and Return Alphabet Listing.(A,B,C....Z)
		function AlphabetListing()
		{
			$Alphabet="A";
			$AlphabetWithLink="";
			for($AlpCounter=1;$AlpCounter<=26;$AlpCounter++,$Alphabet++)
				if($Alphabet==$this->NamePrefix)
					$AlphabetWithLink.="$Alphabet ";
				else
					$AlphabetWithLink.="<A HREF='".$this->CurrentPageName."?NamePrefix=$Alphabet&CurListing=1'class='".$this->CssClassForAlphabetListing."'>$Alphabet</a>&nbsp;";
			if($this->NamePrefix!="a2z")
				$AlphabetWithLink.="<A HREF='".$this->CurrentPageName."' class='".$this->CssClassForAlphabetListing."'>&nbsp;(All)</a> ";
			return $AlphabetWithLink;
		}
		
		//Set $Message Variable.
		function SetMessage()
		{
			$Message="";
			if($this->TotalP2PMember==0 && $this->NamePrefix=="a2z")
				$Message="Sorry!! No member in your network.";
			elseif($this->TotalP2PMember==0 && $this->NamePrefix!="")
				$Message="Sorry!! No member with name prefix ' ".$this->NamePrefix." '";
			elseif($this->TotalP2PMember==0)
				$Message="Sorry!! No member in your network.";
			return $Message;
		}
		
		//Set Display Variables
		function SetListingVariables()
		{	
			if($this->RecordEnd>$this->TotalP2PMember)
				$this->RecordEnd=$this->TotalP2PMember;
			$this->TotalListing=ceil($this->TotalP2PMember/$this->PerPageRecord);
		}

		//Find Member Full Name for a Specific Member.	For Empty Parameter this function Assign My Full Name Using $this->MyMemberId
		function MemberFullName($CurMemberId=0)
		{
			$TmpCurMemId=$CurMemberId;
			if($CurMemberId==0)
				$CurMemberId=$this->MyMemberId;
			$RsMemName=mysql_fetch_object(mysql_query("select * from pla_registration where MemberId=$CurMemberId"));
			$CurMemberFullName=ucfirst($RsMemName->FirstName)." ".ucfirst($RsMemName->SirName);	//echo $CurMemberFullName."<br>";
			if($TmpCurMemId==0)
				$this->MyFullName=$CurMemberFullName;
			return $CurMemberFullName;
		}		
		
		// Advanced Search..........(Using Parameter: $FirstName,$LastName,$City,$Country,$LastSchool,$EmpIndustry,$AgeStart,$AgeEnd)
		function AdvancedSearch($FirstName,$LastName,$City,$Country,$LastSchool,$EmpIndustry,$AgeStart,$AgeEnd)
		{
			$CurDate=date("Y-m-d");
			$QExactMatch.="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ";	
			$QPartialMatch.="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ";
			if($FirstName!="")
			{
				$FirstName=strtolower($FirstName);
				$QExactMatch.="LOWER(FirstName)='$FirstName' and ";
				$QPartialMatch.="LOWER(FirstName) LIKE '%$FirstName%' and ";
			}
			if($LastName!="")
			{
				$LastName=strtolower($LastName);
				$QExactMatch.="LOWER(SirName)='$LastName' and ";
				$QPartialMatch.="LOWER(SirName) LIKE '%$LastName%' and ";
			}
			if($City!="")
			{
				$City=strtolower($City);
				$QExactMatch.="LOWER(PrimaryCity)='$City' and ";
				$QPartialMatch.="LOWER(PrimaryCity) LIKE '%$City%' and ";
			}
			if($Country!="Any")
			{
				$QExactMatch.="ResidenceCountry='$Country' and ";
				$QPartialMatch.="ResidenceCountry='$Country' and ";	//Country only have exact match.
			}
			if($LastSchool!="")
			{
				$LastSchool=strtolower($LastSchool);
				$QExactMatch.="LOWER(EduLastSchool)='$LastSchool' and ";
				$QPartialMatch.="LOWER(EduLastSchool) LIKE '%$LastSchool%' and ";
			}
			if($EmpIndustry!="Any")
			{
				$QExactMatch.="EmpIndustry='$EmpIndustry' and ";
				$QPartialMatch.="EmpIndustry='$EmpIndustry' and ";
			}
			if($AgeStart>0 && $AgeEnd>0)
			{
				$QExactMatch.="'$CurDate'-DateOfBirth>$AgeStart and '$CurDate'-DateOfBirth<$AgeEnd and ";
				$QPartialMatch.="'$CurDate'-DateOfBirth>$AgeStart and '$CurDate'-DateOfBirth<$AgeEnd and ";
			}
			if($AgeStart>0 && $AgeEnd==0)
			{
				$QExactMatch.="'$CurDate'-DateOfBirth>$AgeStart and ";
				$QPartialMatch.="'$CurDate'-DateOfBirth>$AgeStart and ";
			}
			if($AgeStart==0 && $AgeEnd>0)
			{
				$QExactMatch.="'$CurDate'-DateOfBirth<$AgeEnd and ";
				$QPartialMatch.="'$CurDate'-DateOfBirth<$AgeEnd and ";
			}	//echo "Exact Match: ".$QExactMatch;	//echo "<br>Partial Match: ".$QPartialMatch;
			
			if(strlen($QPartialMatch)>70)
			{
				trim($QExactMatch);
				trim($QPartialMatch);
				$QExactMatch=substr($QExactMatch,0,strlen($QExactMatch)-4);			//Remove Trailing and
				$QPartialMatch=substr($QPartialMatch,0,strlen($QPartialMatch)-4);	//Remove Trailing and
			}
		
			if($QExactMatch=="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ")
				$QExactMatch="SELECT * FROM pla_registration WHERE MemberStatus='Active Member'";
			if($QPartialMatch=="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ")
				$QPartialMatch="SELECT * FROM pla_registration WHERE MemberStatus='Active Member'";
		
			if($this->NamePrefix=="")
				$NamePrefix="a2z";
			if($NamePrefix!="a2z" && $NamePrefix!="" )
			{
				$QExactMatch.=" and '$NamePrefix' like SUBSTRING(FirstName,1,1)";
				$QPartialMatch.=" and '$NamePrefix' like SUBSTRING(FirstName,1,1)";
			}
			
			/*//For Debugging Write INto a txt file.
				$Content="Exact Match: ".$QExactMatch."\n";
				$Content.="Partial Match: ".$QPartialMatch;
				$Fp=fopen("AjaxOutput.txt","w");
				fwrite($Fp,$Content);
				fclose($Fp);*/
		
			//echo $QExactMatch;
			if(mysql_num_rows(mysql_query($QExactMatch))>0)
				$QSearchMembers=$QExactMatch;
			else
				$QSearchMembers=$QPartialMatch;
			//$this->SessionStarter();	
			//$_SESSION['QSearchMembers']=$QSearchMembers;
			
			$QAllMember=mysql_query($QSearchMembers);
			//echo "<br>Total: ".mysql_num_rows($QAllMember);
			if(mysql_num_rows($QAllMember)>0)
			{
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					$AllMemIds[]=$RsMemInfo->MemberId;
				$AllMemIds=array_unique($AllMemIds);
				$this->TotalP2PMember=count($AllMemIds);
				return $AllMemIds;
			}
			else
			{
				$this->Error="Sorry! No member in your network.";
				return $this->Error;
			}
			
		}

		// General Search..........(Using Parameter: $KeyWord)
		function GeneralSearch($KeyWord="")
		{
			if($KeyWord!="")
				$_SESSION['KeyWordForGenSearch']=$KeyWord;
			elseif($KeyWord=="")
				$KeyWord=$_SESSION['KeyWordForGenSearch'];
			$CurDate=date("Y-m-d");
			$QExactMatch.="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ";	
			$QPartialMatch.="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ";
			if($KeyWord!="")
			{
				$KeyWord=strtolower($KeyWord);
				$QExactMatch.="(LOWER(FirstName)='$KeyWord' OR LOWER(SirName)='$KeyWord') and ";
				$QPartialMatch.="(LOWER(FirstName) LIKE '%$KeyWord%' OR LOWER(SirName) LIKE '%$KeyWord%') and ";
			}
			
			if(strlen($QPartialMatch)>70)
			{
				trim($QExactMatch);
				trim($QPartialMatch);
				$QExactMatch=substr($QExactMatch,0,strlen($QExactMatch)-4);			//Remove Trailing 'and'
				$QPartialMatch=substr($QPartialMatch,0,strlen($QPartialMatch)-4);	//Remove Trailing 'and'
			}
		
			if($QExactMatch=="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ")
				$QExactMatch="SELECT * FROM pla_registration WHERE MemberStatus='Active Member'";
			if($QPartialMatch=="SELECT * FROM pla_registration WHERE MemberStatus='Active Member' and ")
				$QPartialMatch="SELECT * FROM pla_registration WHERE MemberStatus='Active Member'";
		
			if($this->NamePrefix=="")
				$NamePrefix="a2z";
			else
				$NamePrefix=$this->NamePrefix;
			if($NamePrefix!="a2z" && $NamePrefix!="" )
			{
				$QExactMatch.=" and '$NamePrefix' like SUBSTRING(FirstName,1,1)";
				$QPartialMatch.=" and '$NamePrefix' like SUBSTRING(FirstName,1,1)";
			}
			
			//echo $QExactMatch;
			if(mysql_num_rows(mysql_query($QExactMatch))>0)
				$QSearchMembers=$QExactMatch;
			else
				$QSearchMembers=$QPartialMatch;
			
			$QAllMember=mysql_query($QSearchMembers);
			//echo "<br>Total: ".mysql_num_rows($QAllMember);
			if(mysql_num_rows($QAllMember)>0)
			{
				$AllMemIds=array();
				while($RsMemInfo=mysql_fetch_object($QAllMember))
					$AllMemIds[]=$RsMemInfo->MemberId;
				$AllMemIds=array_unique($AllMemIds);
				$this->TotalP2PMember=count($AllMemIds);
				return $AllMemIds;
			}
			else
			{
				$this->Error="Sorry! No member in your network.";
				return $this->Error;
			}
			
		}

		//This Function Start Session if it's not Started.
		function SessionStarter()
		{
			if(!session_start())
				session_start();
		}
	}

	class MemRegistered extends ClsConnection
	{
		var $JoinedMemberId;	// Currently Registered Member Member Id.
		var $JoinedMemberEmail;	// Currently Registered Member Email Address.
		var $InvitedByMemId=0;	// Member Who Invite Friennds For Register.
		var $Message="";

		function MemRegistered()
		{
			$this->ClsConnection();	//Database Connection.
		}

		function ConnectRegMember()
		{
			$AminQuery="SELECT * FROM pla_invite_by_mem WHERE FriendEMail='".$this->JoinedMemberEmail."'";
			$QInvitedMemberId=mysql_query($AminQuery);
			if(mysql_num_rows($QInvitedMemberId)>0)
			{
				$RsInvitedMemId=mysql_fetch_object($QInvitedMemberId);
				$this->InvitedByMemId=$RsInvitedMemId->InviteByMemId;
				
				//Find Member Id Using pla_registration table.
				$AminQuery="SELECT * FROM pla_registration WHERE EMail='".$this->JoinedMemberEmail."'";
				$QMemId=mysql_query($AminQuery);
				if(mysql_num_rows($QMemId)>0)
				{
					$RsMemId=mysql_fetch_object($QMemId);
					$this->JoinedMemberId=$RsMemId->MemberId;
				}

				// Now Add This Invitation into p2p_network table.
				if($this->InvitedByMemId!=0)	// 0 means Invite by Admin
				{
					$QInsert="INSERT INTO p2p_network VALUES('',".$this->InvitedByMemId.",".$this->JoinedMemberId.",'Approved','Friend through invitation for registration.','".date("Y-m-d H:i:s")."','Active')";
					//echo "<br>".$QInsert;	//WaitingForAdminPermission
					if(mysql_query($QInsert))
						$this->Message="Successfully added.";
					else
						$this->Message="Error while additing into network.";
				}
				else
					$this->Message="Invited by administrator.";
			}
			return true;
		}
	}
?>
Return current item: Tiny P2P