<?php
class Participant{
	private $first;
	private $last;
	private $address;
	private $phone;
	private $email;
	
	function __construct($first, $last, $address, $phone, $email){
		$this->first=$first;
		$this->last=$last;
		$this->address=$address;
		$this->phone=$phone;
		$this->email=$email;
	}
	
	function __get($prop){
		if(property_exists($this, $prop))
			return $this->$prop;
	}
	function __set($prop, $val){
		if(property_exists($this, $prop))
			$this->$prop=$val;
	}
	function __toString(){
		$ret=$this->last.", ".$this->first."<br/>";
		$ret.=$this->address."<br/>";
		$ret.=$this->phone."<br/>";
		$ret.=$this->email."<br/>";
		
		return $ret;
	}
	function getBSRow(){
		$ret="<div class='row'>";
		$ret.="<div class='col-12 col-md-4'>".$this->last.", ".$this->first."</div>";
		$ret.="<div class='col-12 col-md-4'>".$this->phone."</div>";
		$ret.="<div class='col-12 col-md-4'><a href='mailto:".$this->email."'>".$this->email."</a></div>";
		$ret.="</div>";
		
		return $ret;
		
	}
	
}

function createPartFromDB($id){
	include("../includes/connect.php");
	$sql="select * from users where id=$id";
	$result=$smeConn->query($sql);
	if($result->num_rows>0){
		$row=$result->fetch_assoc();
		$address=$row['street']."<br/>".$row['city'].", ".$row['state']." ".$row['zip'];
		return new Participant($row['first'], $row['last'], $address, $row['phone'], $row['email'] );
		
	}
	else
		return null;
	
}

?>