
sub create_event_email_table {
	
	my ($event_id) = @_ ; 
	
	&db_min_ro('event_quotes','1,country_id,event_system_id_multiple,type_details_id,qty,club_name,operator_ids,ref,organisation_ids,date_from,date_to,poc_name,poc_contact_nr,type,sport_type_ids,region_id,city_id,quote_to,category_id_1,category_id_2,additional_notes,user_id,format_of_title',"`id`='$event_id'",'','') ;
	
	# &db_min_ro('user_type','id,name,email,user_type',"",'','') ;
	&db_min_ro('users','id,name,email,user_type',"",'','') ;
	
	our %operator_email =  () ; 
	foreach (keys %{$db{user_type}}) {
		$operator_email{$db{user_type}{$_}{email}} = 1 if substr($db{user_type}{$_}{user_type},0,6) eq 'casual' and $db{user_type}{$_}{email} ; 		
	}
	
	my $system_details = "" ; 
	
	&db_min_ro('event_type_details','id,name','','','') ; 
	
	foreach (split(",",$db{event_quotes}{1}{type_details_id})) {
		$system_details .= qq~$db{event_type_details}{$_}{name},~ ;
	}
	chop $system_details if $system_details ;
	
	&db_min_ro('sport_types','id,name','','','') ; 
	
	&db_min_ro('event_systems','id,name','','','') ; 
	
	my $SystemName = qq~~ ; 
	
	foreach (split(";",$db{$table}{$qt_id}{event_system_id_multiple})) {
		$SystemName .= qq~$db{event_systems}{$_}{name},~ ; 
	}
	chop $SystemName if $SystemName ;
	
	&db_min_ro('event_quotes_categories','id,category','','','') ;
	
	&db_min_ro('regions','id,name','','','') ;
	
	&db_min_ro('countries','1,name,country',"`id`='$db{event_quotes}{1}{country_id}'",'','') ;
	
	&db_min_ro('cities','id,city','','','') ;
	
	&db_min_ro('organisations','id,name','','','') ; 
	
	&db_min_ro('customers','id,name','','','') ;
	
	&db_min_ro('event_types','1,name',"`id`='$db{event_quotes}{1}{type}'",'','') if $db{event_quotes}{1}{type} ;
	
	&db_min_ro('event_quotes_min','1,category_details',"`id`='$event_id'",'','') ;
	
	my @cat_details = split('\|;\|',$db{event_quotes_min}{1}{category_details}) ; 
	
	our $sports = qq~~ ; 
	
	foreach (split(",",$db{event_quotes}{1}{sport_type_ids})) {
		
		$sports .= qq~$db{sport_types}{$_}{name},~ ; 
		
	}
	
	chop $sports if $sports ; 
	
	my $venues = qq~~ ; 
	
	foreach (split(",",$db{event_quotes}{1}{organisation_ids})) {
		
		$venues .= qq~$db{organisations}{$_}{name},~ ; 
		
	}
	
	chop $venues if $venues ; 
	
	my $op_cnt = qq~~ ; my $op_names = qq~~ ; 
	
	foreach (split(",",$db{event_quotes}{1}{operator_ids})) {	
		$op_cnt++ ; 
		$op_names .= qq~$db{users}{$_}{name},~ ; 
	}
	chop $op_names if $op_names ;
	$op_names = qq~$op_cnt [$op_names]~ if $op_names; 
	
	my %event_details = () ; 
	
	my $city_name = qq~~ ; 
	$city_name .= qq~$db{cities}{$db{event_quotes}{1}{city_id}}{city},~ if $db{cities}{$db{event_quotes}{1}{city_id}}{city} ; 
	$city_name .= qq~$db{regions}{$db{event_quotes}{1}{region_id}}{name},~ if $db{regions}{$db{event_quotes}{1}{region_id}}{name} ; 
	$city_name .= qq~$db{countries}{1}{name} [$db{countries}{1}{country}]~ ; 
	
	$event_details{Client} = qq~<tr><th>Client</th><th>$db{customers}{$db{event_quotes}{1}{quote_to}}{name}</th></tr>~ ;
	$event_details{EventName} = qq~<tr><th>Event Name</th><th>$db{event_quotes}{1}{ref} [$event_id]</th></tr>~ ;
	$event_details{DateFrom}  = qq~<tr><td>Event Date/Time From</td><td>&nbsp;$db{event_quotes}{1}{date_from}</td></tr>~ if $db{event_quotes}{1}{date_from} ;
	$event_details{DateTo} = qq~<tr><td>Event Date/Time To</td><td>&nbsp;$db{event_quotes}{1}{date_to}</td></tr>~ if $db{event_quotes}{1}{date_to} ;
	$event_details{Type} = qq~<tr><td>Type of System</td><td>&nbsp;$db{event_types}{1}{name}</td></tr>~ if $db{event_types}{1}{name} ;
	$event_details{SystemDetails} = qq~<tr><td>System Details</td><td>&nbsp;$system_details</td></tr>~ if $system_details ;
	$event_details{SystemName} = qq~<tr><td>System Name</td><td>&nbsp;$SystemName</td></tr>~ if $SystemName ;
	$event_details{ClubName} = qq~<tr><td>Club Name</td><td>&nbsp;$db{event_quotes}{1}{club_name}</td></tr>~ if $db{event_quotes}{1}{club_name} ; 
	$event_details{Days} = qq~<tr><td>Days</td><td>&nbsp;$db{event_quotes}{1}{qty}</td></tr>~ if $db{event_quotes}{1}{qty} ; 
	$event_details{NrofOperators} = qq~<tr><td>Nr of Operators</td><td>&nbsp;$op_names</td></tr>~ if $op_names ;
	$event_details{SportTypes} = qq~<tr><td>Sport Types(s)</td><td>&nbsp;$sports</td></tr>~ if $sports ; 
	$event_details{City} = qq~<tr><td>City</td><td>&nbsp;$city_name</td></tr>~ ;
	$event_details{Venue} = qq~<tr><td>Venue(s)</td><td>&nbsp;$venues</td></tr>~ if $venues ;
	$event_details{PocName} = qq~<tr><td>Poc Name</td><td>&nbsp;$db{event_quotes}{1}{poc_name}</td></tr>~ if $db{event_quotes}{1}{poc_name} ;
	$event_details{PocContactNr} = qq~<td>Poc Contact Nr</td><td>&nbsp;$db{event_quotes}{1}{poc_contact_nr}</td></tr>~ if $db{event_quotes}{1}{poc_contact_nr} ;

	$cat_details[0] =~ s/\n/,/g; $cat_details[1] =~ s/\n/,/g; $db{event_quotes}{1}{additional_notes} =~ s/\n/,/g; $db{event_quotes}{1}{format_of_title} =~ s/\n/,/g;
		
	$event_details{Category1} = qq~<tr><td>Category 1</td><td>&nbsp;$db{event_quotes_categories}{$db{event_quotes}{1}{category_id_1}}{category}</td></tr>~ if $db{event_quotes_categories}{$db{event_quotes}{1}{category_id_1}}{category} ;
	$event_details{Category1Details} = qq~<tr><td>Category 1 Details</td><td>&nbsp;$cat_details[0]</td></tr>~ if $cat_details[0] ;
	$event_details{Category2} = qq~<tr><td>Category 2</td><td>&nbsp;$db{event_quotes_categories}{$db{event_quotes}{1}{category_id_2}}{category}</td></tr>~ if $db{event_quotes_categories}{$db{event_quotes}{1}{category_id_2}}{category} ;
	$event_details{Category2Details} = qq~<tr><td>Category 2 Details</td><td>&nbsp;$cat_details[1]</td></tr>~ if $cat_details[1] ;
	$event_details{AdditionalNotes} = qq~<tr><td>Additional Notes</td><td>&nbsp;$db{event_quotes}{1}{additional_notes}</td></tr>~ if $db{event_quotes}{1}{additional_notes} ;
	$event_details{format_of_title} = qq~<tr><td>Format of TITLE to be followed&nbsp;<br>when scheduling events</td><td>&nbsp;$db{event_quotes}{1}{format_of_title}</td></tr>~ if $db{event_quotes}{1}{format_of_title} ;

	our $table_message = qq~
		$event_details{Client}
		$event_details{EventName}
		$event_details{DateFrom}
		$event_details{DateTo}
		$event_details{Type}
		$event_details{SystemDetails}
		$event_details{SystemName}
		$event_details{ClubName}
		$event_details{Days}
		$event_details{NrofOperators}
		$event_details{SportTypes}
		$event_details{City}
		$event_details{Venue}
		$event_details{PocName}
		$event_details{PocContactNr}
		$event_details{Category1}
		$event_details{Category1Details}
		$event_details{Category2}
		$event_details{Category2Details}
		$event_details{AdditionalNotes}
		$event_details{format_of_title}
	~ ; 
	
	$message = qq~Good day

Please find attached event details.~ ;	


} #------------------------------------------------------------------------------------------

1;
