<?php
	class Event{
		private $id;
		private $name;
		private $location;
		private $address;
		private $date;
		private $time;
		private $orgEmail;
		
		function __construct($id, $name, $location, $address, $date, $time, $orgEmail){
			$this->id=$id;
			$this->name=$name;
			$this->location=$location;
			$this->address=$address;
			$this->date=$date;
			$this->time=$time;
			$this->orgEmail=$orgEmail;
		}
		function __get($prop){
			if(property_exists($prop)){
				return $this->$prop;
			}
		}
		function __set($prop, $val){
			if(property_exists($prop)){
				$this->$prop=$val;
			}
		}
		function __toString(){
			return $this->id.":".$this->name.":".$this->location.":".$this->address.":".$this->date.":".$this->time.":".$this->orgEmail;
		}
		function getBSRow(){
			$ret="<div class='row' data-id=".$this->id.">";
			$ret.="<div class='col-12 col-md-5'>".$this->date." - ".$this->time."</div>";
			$ret.="<div class='col-12 col-md-5'>".$this->name."</div>";
			$ret.="<div class='col-12 col-md-2'>";
			$ret.="<a href='http://maps.google.com?q=".$this->address."'><i class='fas fa-map-marker-alt'></i></a> ";
			$ret.=" <a href='mailto:".$this->orgEmail."'><i class='fas fa-envelope'></i></a>";
			$ret.="</div>";
			$ret.="</div>";
		
		    return $ret;
		}
		
	}
	
	function createEventFromDB($id){
		//if coming from a script
		include("../includes/connect.php");
		//if coming from a page file
		//include("includes/connect.php");
			
		$sql="select * from events where id=$id";
		$result=$smeConn->query($sql);
		if($result->num_rows>0){
			$row=$result->fetch_assoc();
			$orgId=$row['organizer'];
			$orgsql="select * from users where id=$orgId";
			$orgRes=$smeConn->query($orgsql);
			$orgRow=$orgRes->fetch_assoc();
			$orgEmail=$orgRow['email'];
			return new Event($row['id'], $row['name'], $row['location'], $row['address'], $row['date'], $row['time'],$orgEmail );	
		}
		else
			return null;
		
	}
?>