#!/usr/bin/perl

BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
    
require cfg ;

# unless ($username eq 'handre') { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; }

use DBI;
use CGI::Carp qw(fatalsToBrowser);
use Date::Manip;
use Date::Calc qw(:all);

# use Font::TTF::Font;
# use GD;
# use GD::Text::Align;

use PDF::API2;
use CAM::PDF ;
# use PDF::API2;
use constant mm => 25.4/72;
use constant in =>    1/72;
use constant pt =>    1;

# my $pdf  = PDF::API2->new;
# my $page = $pdf->page;
# my $text = $page->text;

# my $font = $pdf->corefont('Helvetica');   # built-in font
# my $size = 8;

# $text->font($font, $size);

# my $string = "W";

# my $width = $text->advancewidth($string);

# print "Width of '$string' at ${size}pt = $width\n";

#------------------------------------------------------------------------------------------

@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});

our $qt_id     			= $ARGV[0] ;
our $tab_no    			= $ARGV[1] ;
our $tab_secs  			= $ARGV[2] ;
our $event_or_analytics = $ARGV[3] ;

# my @sections  = split(/\|/,$tab_secs); 

my @prefix_arr = qw( cost_desc_ curr_amnt_ qty_cost_ zar_amnt_ );

our $open_new_tab = qq~target="_blank"~ ; # opens booking page in a new tab

# our $debug = 1 ;
our $label = 1 ; # used in pdf_check_value_of_up

#------------------------------------------------------------------------------------------

print "Content-type: text/html\n\n";

&today ;
&pdf_curr_symbols ;

my $table = 'event_quotes' ;

&db_open_ro ;
    our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it
		&prep_pdf ;
	$db_ignore_open_close = 0 ; # do one open and one close instead of repeating it
&db_close_conn ;

&exclusions ;
&start_pdf ;
&build_pdf ;
&finish_pdf ;
&screen2 ;
    
exit ;

#------------------------------------------------------------------------------------------

sub process_date {
	
	my ($date_string) = @_ ; 
	
	my $year = substr($date_string, 0, 4) ; 
	my $month = substr($date_string, 5, 2) ; 
	$month = int($month); 
	$month = $month_array[$month - 1] ;
	my $day = substr($date_string, 8, 2) ; 
	my $date_return = "$day-" ; 
	$date_return .= "$month-" ;
	$date_return .= "$year" ;
	$date_return .= " @ " . substr($date_string,11,5) ; 
	
	return $date_return ;
	
} #------------------------------------------------------------------------------------------

sub prep_pdf {

	my @cols = () ;

	&tab_hash ;

	if ($event_or_analytics eq 'analytics') {
		&db_min_ro('analytics_event_bookings',"id,event_date","`id`='$qt_id'",'','') ;
		$db{$table}{$qt_id}{quote_date} = $db{analytics_event_bookings}{$qt_id}{event_date} ;
		$db{$table}{$qt_id}{quote_nr} = $qt_id ;
		&db_min_ro('sport_types','id,name','','','') ;
		return ; 
	}

	&db_min_ro('event_quotes',"*","`id`='$qt_id'",'','') ;
	
	our @month_array = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; 
	
	our $countryid = $db{$table}{$qt_id}{country_id} ;
	our $custid = $db{$table}{$qt_id}{quote_to} ;
	our $date_from_for_pdf = &process_date($db{$table}{$qt_id}{date_from}) ;
	our $date_to_for_pdf = &process_date($db{$table}{$qt_id}{date_to}) ;
	
	our $type_id = $db{$table}{$qt_id}{type} ;
	our %country = () ;

	&db_min_ro('customers','id,name,physical_address,contact_email,phone,contact_name,vat_nr',"`id`='$custid'",'','') ;
	$customer_name{$custid}         = $db{customers}{$custid}{name} ; 
	$customer_address{$custid}      = $db{customers}{$custid}{physical_address} ; 
	$customer_email{$custid}        = $db{customers}{$custid}{contact_email} ; 
	$customer_phone{$custid}        = $db{customers}{$custid}{phone} ; 
	$customer_contact_name{$custid} = $db{customers}{$custid}{contact_name} ; 
	$customer_vat_nr{$custid}       = $db{customers}{$custid}{vat_nr} ; 

	&db_min_ro('event_cost_items','id,name','','','') ;
	foreach my $id (keys %{$db{event_cost_items}}) { $price_list{$id} = $db{event_cost_items}{$id}{name} ; }

	&db_min_ro('countries','*',"`id`='$countryid'",'','') ;
	$country{$countryid} = $db{countries}{$countryid}{name} ; 
	$country{$countryid} = "Unknown" if not $country{$countryid} ;

	our $camera_system_id = $db{$table}{$qt_id}{camera_system_id} ;
	&db_min_ro('camera_systems','*',"`id`='$camera_system_id'",'','') ;
	$camera_system{$camera_system_id} = $db{camera_systems}{$camera_system_id}{name} ;
	
	our %event_type_for_pdf = () ; 
	&db_min_ro('event_types','id, name',"`id`='$type_id'",'','') ;
	$event_type_for_pdf{$type_id} = $db{event_types}{$type_id}{name} ;
	
	&db_min_ro('event_quotes_min','id,excl_costing_event,item_costing_event,qty_costing_event,usd_amnt_costing_event,item_ttl_costing_event,vat_costing_event,curr_amnt_costing_event,category_details',"`id`='$qt_id'",'','') ;	
	&db_min_ro('event_systems','id,name,description','','','') ; 	
	&db_min_ro('event_type_details','id,name','','','') ; 	
	&db_min_ro('users','id,name,phone','','','') ; 
	&db_min_ro('sport_types','id,name','','','') ;
	&db_min_ro('regions','id,name','','','') ;
	&db_min_ro('cities','id,name','','','') ;
	&db_min_ro('organisations','id,name','','','') ;
	&db_min_ro('event_quotes_categories','*','','','') ;
	&db_min_ro('clubs','*','','','') ;
	&db_min_ro('event_quotes_poc','*','','','') ;
	&db_min_ro('event_quotes_recipient','*','','','') ;
	
} #------------------------------------------------------------------------------------------
    
sub exclusions {

	our $exclude_rate = 0 ;
	our $exclude_vat  = 0 ;
		
	if ($db{$table}{$qt_id}{currency} ne 'ZAR') {
		$exclude_vat = 1 ;
	}
	
} #------------------------------------------------------------------------------------------
    
sub start_pdf {

	my  $qtpdfpath = "$pdfpath/event_details" ;
	our $pdfname = "Event_Details-$qt_id" . '.pdf' ;

	# &pdf_delete_previous_pdf($qtpdfpath) ;
	
	if (-f "$qtpdfpath/$pdfname") {
		unlink ("$qtpdfpath/$pdfname") or print "unable to unlink - $qtpdfpath/$pdfname : $!";
	}
	
	&pdf_initialise($qtpdfpath,$pdfname,'ITV Event Quote') ;
    
} #------------------------------------------------------------------------------------------
    
sub build_pdf {

	&tab_curr_symbols;
	&pdf_initialise_page ;
	
	$up = 292 ;
	# &quote_pdf_page_header ;

	&pdf_box_block_top(5,205,'#009bc8') ;
	
	$up       = 260 ;
	$across   = 1 ;
	$blue_box = 1 ;
	
	&pdf_page_header ;
	&quote_pdf_vars ;
	&quote_out_to_pdf ;
	# &quote_pdf_footer ;

	$up = 5 ;	
	&pdf_box_block_bottom(5,205,'#009bc8') ;
		
} #------------------------------------------------------------------------------------------

sub quote_out_to_pdf {

	&pdf_nl_t;

	&pdf_small_bold_text(150, $up, "Date") ; 
	my $dttxt = &custom_date_txt($db{$table}{$qt_id}{quote_date});

	&pdf_small_bold_text_right (198, $up, $dttxt) ;

	&pdf_nl;
	
	if ($event_or_analytics eq 'analytics') {
		&pdf_small_bold_text(150, $up, "Analytics Event Nr") ;
	} else {
		&pdf_small_bold_text(150, $up, "Event Nr") ;
	}
	# &pdf_small_text_right (198, $up, $qt_id) ;
	&pdf_small_bold_text_right (198, $up, $db{$table}{$qt_id}{quote_nr}) ;

	&pdf_nl;

	&pdf_nl_t;
	
	my $text = $page->text;
	my $font = $pdf->corefont('Helvetica');   # built-in font
	my $size = 8/pt ;
	$text->font($font, $size);
	
	unless ($event_or_analytics eq 'analytics') {
	
		&pdf_bar(10,$up,200,$up,'#969696','EVENT INFO',20,93) ; #EEEEEE
		$up = $up - 5;

		&pdf_box_block_top(10,200,'#969696') ; # start block -------------------------------------

		our $top = 0 ;

		if ($custid) {

			my ($expiry_year,$expiry_month,$expiry_day) = split(/\-/,$db{$table}{$qt_id}{quote_expiry});
			my $expiry_date = &custom_date_txt("$expiry_year-$expiry_month-$expiry_day") if $db{$table}{$qt_id}{quote_expiry} ;
			
			$top = $up ; 
			our $pos_cat = 15 ; our $pos_des = 60 ; our $next_line_space = 5 ;
			
			my $sport_types = '' ;
			
			my @sport_type_ids = ($db{$table}{$qt_id}{sport_type_ids} =~ /;/) ? split(";",$db{$table}{$qt_id}{sport_type_ids}) : split(",",$db{$table}{$qt_id}{sport_type_ids}) ;
			
			foreach (@sport_type_ids) {			
				$sport_types .= qq~$db{sport_types}{$_}{name}, ~ ;		
			}
			chop $sport_types if $sport_types ; chop $sport_types if $sport_types ; 

			my $operators = qq~~ ; my $cnt_ops = 0 ; 
			
			my @operator_ids = ($db{$table}{$qt_id}{operator_ids} =~ /;/) ? split(";",$db{$table}{$qt_id}{operator_ids}) : split(",",$db{$table}{$qt_id}{operator_ids}) ; 
			
			foreach (@operator_ids) {			
				next unless $_ ; 
				$cnt_ops++ ; 
				$operators .= qq~$db{users}{$_}{name}~ ;	
				
				my $phone = $db{users}{$_}{phone} ;
				$phone =~ s/ //g ;
				if (substr($phone,0,2) eq '27' && length($phone) == 11) {
					$phone = "+27 " . substr($phone,2,2) . " " .  substr($phone,4,3) . " " .  substr($phone,7,4) ;
				} elsif ((substr($phone,0,2) eq '07' || substr($phone,0,2) eq '08' || substr($phone,0,2) eq '02') && length($phone) == 10) {
					$phone = "+27 " . substr($phone,1,2) . " " .  substr($phone,3,3) . " " .  substr($phone,6,4) ;
				} else {
					$phone = $db{users}{$_}{phone} ;
				}
				
				$operators .= qq~ - $phone~ if $phone ;		
				$operators .= qq~, ~ ;						
			}
			chop $operators if $operators ; chop $operators if $operators ; 
			$operators = qq~$cnt_ops [$operators]~ if $cnt_ops ; 

			my $venue = qq~~ ;
			
			my @organisation_ids = ($db{$table}{$qt_id}{organisation_ids} =~ /;/) ? split(";",$db{$table}{$qt_id}{organisation_ids}) : split(",",$db{$table}{$qt_id}{organisation_ids}) ;
			
			foreach (@organisation_ids) {			
				$venue .= qq~$db{organisations}{$_}{name}, ~ ;		
			}
			chop $venue if $venue ; chop $venue if $venue ; 
			my $system_details = qq~~ ;
			if ($usertype ne 'schools_manager') {
				
				my @type_details_id = ($db{$table}{$qt_id}{type_details_id} =~ /;/) ? split(";",$db{$table}{$qt_id}{type_details_id}) : split(",",$db{$table}{$qt_id}{type_details_id}) ; 
				
				foreach my $type_id (@type_details_id) {			
					$system_details .= qq~$db{event_type_details}{$type_id}{name}, ~ ;		
				}
				chop $system_details if $system_details ; chop $system_details if $system_details ; 			
			}
			
			my $max_line_width = 100 ; 
			my @times_from 	= split(/\;/,$db{$table}{$qt_id}{times_from}) ;
			my @times_to 	= split(/\;/,$db{$table}{$qt_id}{times_to}) ;
			my @times_from_com = () ; my @times_to_com = () ; 
			push @times_from_com,substr($db{$table}{$qt_id}{date_from},11) ;
			my @days_active = split(/\;/,$db{$table}{$qt_id}{days_active}) ;
		
			my %dates_hash = () ;
			
			for (1 .. 10) {
				my ($year,$month,$day) = split(/\-/,substr($db{$table}{$qt_id}{date_from},0,10)) ; 
				my ($new_year,$new_month,$new_day) = Add_Delta_Days($year,$month,$day,$_-1) ;
				$new_day = sprintf("%02s",$new_day) ; $new_month = sprintf("%02s",$new_month) ; 
				$dates_hash{$_} = "$new_year-$new_month-$new_day" ;	
				push @times_from_com,$times_from[$_-2] if $times_from[$_-2] && $_ > 1 ;
				push @times_from_com,substr($db{$table}{$qt_id}{date_from},11) if !$times_from[$_-2] && $_ > 1 ;
				last if substr($db{$table}{$qt_id}{date_to},0,10) eq "$new_year-$new_month-$new_day" ;	
				push @times_to_com,$times_to[$_-1] if $times_to[$_-1] ;
				push @times_to_com,substr($db{$table}{$qt_id}{date_to},11) if !$times_to[$_-1] ;
			}
			
			push @times_to_com, substr($db{$table}{$qt_id}{date_to},11) ;
			
			my $system_count = 0 ; my $system_day_cnt = 0 ; my %system_has_daily_op = () ; 

			foreach my $system_row (split(/\|/,$db{$table}{$qt_id}{daily_operator_ids})) {
				$system_count++ ; 
				next unless $system_row ;
				$system_day_cnt = 0 ;
				foreach my $col (split(/\;/,$system_row)) {
					$system_day_cnt++ ;
					next unless $col ; 
					$default_op_ids{$system_count}{$system_day_cnt} = $col if $col ;
					$system_daily_ops{$system_count} .= qq~Day $system_day_cnt : $db{users}{$col}{name},~ if $col ; 
				}
				chop $system_daily_ops{$system_count} if $system_daily_ops{$system_count} ;
				# chop $system_daily_ops{$system_count} if $system_daily_ops{$system_count} ;
			}	
			$system_count = 0 ; 
			
			&display_text ("Event Name",$db{$table}{$qt_id}{ref}) if $db{$table}{$qt_id}{ref} ;
		
			if ($date_from_for_pdf && substr($db{$table}{$qt_id}{date_from},0,10) ne substr($db{$table}{$qt_id}{date_to},0,10)) {
				&display_text ("Date From",$date_from_for_pdf . qq~ to ~ . substr($times_to_com[0],0,5)) ;
				for (2 .. 9) {	
					last if substr($db{$table}{$qt_id}{date_to},0,10) eq $dates_hash{$_} ;
					next if $db{$table}{$qt_id}{days_active} and !$days_active[$_ - 1] ;
					my ($new_year,$new_month,$new_day) = split(/\-/,$dates_hash{$_}) ;
					my $val = $new_day . "-" . $month_array[$new_month - 1] . "-" . $new_year . " @ " . substr($times_from_com[$_ - 1],0,5) . " to " . substr($times_to_com[$_ - 1],0,5) ;
					&display_text ("",$val)  ;
				}
				&display_text ("Date To",substr($date_to_for_pdf,0,-5) . substr($times_from_com[-1],0,5) . qq~ to ~ . substr($date_to_for_pdf,-5,5)) if $date_to_for_pdf ;
			} elsif ($date_from_for_pdf && substr($db{$table}{$qt_id}{date_from},0,10) eq substr($db{$table}{$qt_id}{date_to},0,10)) {
				&display_text ("Date",$date_from_for_pdf . qq~ to ~ . substr($db{$table}{$qt_id}{date_to},11,5))  ;
			}
			
			&display_text ("Type of System",$event_type_for_pdf{$type_id}) if $event_type_for_pdf{$type_id} ;
			&display_text ("Type Details",$system_details) if $system_details ;

			if ($usertype ne 'schools_manager') {
				
				my $club_name = qq~~ ;
				# my $cnt_sys      = 0 ; 
				my @club_ids     = split(";",$db{$table}{$qt_id}{club_ids}) ;
				my @operator_ids = ($db{$table}{$qt_id}{operator_ids} =~ /;/) ? split(";",$db{$table}{$qt_id}{operator_ids}) : split(",",$db{$table}{$qt_id}{operator_ids}) ;
				my $cnt_sys = -1 ; 
				
				my $this_line = qq~~ ;
				
				foreach my $event_id (split(";",$db{$table}{$qt_id}{event_system_id_multiple})) {
					$cnt_sys++ ; 
					next if !$event_id && !$club_ids[$cnt_sys] ;
					$event_id =~ s/f-//g ;
					
					$this_line = qq~~ ;
					
					if ($db{event_systems}{$event_id}{name}) {
						$this_line .= qq~$db{event_systems}{$event_id}{name}~ ;
						$this_line .= ($db{event_systems}{$event_id}{description}) ? qq~ [$db{event_systems}{$event_id}{description}]~ : qq~~ ;				
					} else {
						$this_line .= qq~NO SYSTEM~ ;	
					} 
					
					$this_line .= qq~ >>> ~ ;
					
					$this_line .= ($db{clubs}{$club_ids[$cnt_sys]}{name}) ? qq~$db{clubs}{$club_ids[$cnt_sys]}{name} >>> ~ : qq~NO CLUB >>> ~ ;

					$this_line .= qq~$db{users}{$operator_ids[$cnt_sys]}{name}~ if $operator_ids[$cnt_sys] ;
					$cnt_sys++ ;
					
					$club_name .= qq~$this_line~ ;
					
					if ($system_daily_ops{$cnt_sys} && !$operator_ids[$cnt_sys-1]) {
						
						my $line_width123 = $text->advancewidth("$this_line\[");	
					 
						$line_width123 =  $line_width123*mm ;
			 
						my $available_space = 195 - 4 - $pos_des - $line_width123 ;
						
						my $max_operator_width = 0 ; 
						
						foreach (split(/\,/,$system_daily_ops{$cnt_sys})) {
							
							my $width123 = $text->advancewidth("$_");	 
							$width123 = $width123*mm ;
							$max_operator_width = $width123 if $width123 > $max_operator_width ;
							
						}

						my $space_width = $text->advancewidth(" ")*mm ;
						
						my $num_spaces = 0 ; 
						
						my $fist_line = qq~~ ;
						
						if ($max_operator_width > $available_space) {
							# $club_name .= qq~\n~ ;
							# $line_width123 += $available_space ;
							$line_width123 -= $max_operator_width ;
							$num_spaces = int($line_width123 / $space_width) ;
							$num_spaces = 0 ;
							for (1 .. $num_spaces) {
								# $club_name .= qq~ ~ ;
							}
						} else {
							$num_spaces = int($line_width123 / $space_width) ;
						}
					
						$club_name .= qq~[~ ;
						
						foreach (split(/\,/,$system_daily_ops{$cnt_sys})) {
							# $club_name .= qq~$_\n~ ;
							$club_name .= qq~$_,~ ;
							for (1 .. $num_spaces+1) {
								# $club_name .= qq~ ~ ;
							}
						}
						
						# $club_name =~ s/ +$// ;
						$club_name =~ s/\,+$// ;
						chomp $club_name ;
						$club_name .= qq~]~ ;	
					
						
					}
					
					$cnt_sys-- ;
					
					$club_name =~ s/ +$// ;
					$club_name =~ s/>+$// ;
					
					$club_name .= qq~\n~ ;
					
					# $val .= qq~>>> $db{clubs}{$club_ids[$cnt_sys]}{name} ~ if $db{clubs}{$club_ids[$cnt_sys]}{name} ;
					# $val .= qq~>>> $db{users}{$operator_ids[$cnt_sys]}{name} ~ if $db{users}{$operator_ids[$cnt_sys]}{name} ;
					# $val .= qq~[$db{users}{$operator_ids[$cnt_sys]}{phone}] ~ if $db{users}{$operator_ids[$cnt_sys]}{name} && $db{users}{$operator_ids[$cnt_sys]}{phone} ;
					# $club_name .= qq~<br>~ ;	
					# $cnt_sys++ ; 			
				}
		 
				# my $club_name = qq~~ ;
				# my @club_ids     = split(";",$db{$table}{$qt_id}{club_ids}) ;
				# my @operator_ids = split(",",$db{$table}{$qt_id}{operator_ids}) ;
				# my $cnt_sys = -1 ; 
				# foreach my $event_id (split(";",$db{$table}{$qt_id}{event_system_id_multiple})) {
					# $cnt_sys++ ; 
					# next if not $event_id and not $club_ids[$cnt_sys] ;
					# $club_name .= qq~$db{event_systems}{$event_id}{name} ~ if $event_id ;
					# $club_name .= qq~>>> ~ if $event_id and not $db{event_systems}{$event_id}{description} ;
					# $club_name .= qq~($db{event_systems}{$event_id}{description}) >>> ~ if $db{event_systems}{$event_id}{description} and $event_id ;
					# $club_name .= qq~NO SYSTEM >>> ~ unless $event_id ;	

					# $club_name .= qq~$db{clubs}{$club_ids[$cnt_sys]}{name} >>> ~ if $club_ids[$cnt_sys] ;
					# $club_name .= qq~NO CLUB >>> ~ unless $club_ids[$cnt_sys] ;
					
					# $club_name .= qq~$db{users}{$operator_ids[$cnt_sys]}{name}~ if $operator_ids[$cnt_sys] ;
					# $cnt_sys++ ;
					# $club_name .= qq~[$system_daily_ops{$cnt_sys}]~ if $system_daily_ops{$cnt_sys} && !$operator_ids[$cnt_sys] ;
					# $cnt_sys-- ;
					# # $val .= qq~>>> $db{clubs}{$club_ids[$cnt_sys]}{name} ~ if $db{clubs}{$club_ids[$cnt_sys]}{name} ;
					# # $val .= qq~>>> $db{users}{$operator_ids[$cnt_sys]}{name} ~ if $db{users}{$operator_ids[$cnt_sys]}{name} ;
					# # $val .= qq~[$db{users}{$operator_ids[$cnt_sys]}{phone}] ~ if $db{users}{$operator_ids[$cnt_sys]}{name} && $db{users}{$operator_ids[$cnt_sys]}{phone} ;
					# $club_name .= qq~\n~ ;	
					# # $cnt_sys++ ; 			
				# }
				# # chop $val if $val ; chop $val if $val ; 	
				# # $club_name = substr($club_name,0,-4) if $club_name ;
			
				chomp $club_name if $club_name ;
			
				&display_text ("System Details",$club_name,195) if $club_name  ;			
			
			}
			
			&display_text ("Operator(s)",$operators) if $operators ;
			&display_text ("Sport Type(s)",$sport_types) if $sport_types ;
			my $city = '' ;
			if ($db{$table}{$qt_id}{city_id} and $db{$table}{$qt_id}{city_id} =~ /,/) {
				# foreach (split(/,/,$db{$table}{$qt_id}{city_id})) {
					# $city .= qq~$db{cities}{$_}{name},~ ;
				# }
				# chop $city if $city ;		
				$city = join(",", map{ "$db{cities}{$_}{name}" } split(/\,/,$db{$table}{$qt_id}{city_id})) ;
				&display_text ("Cities",$city) ;
				&display_text ("Region",$db{regions}{$db{$table}{$qt_id}{region_id}}{name}) ;
			} elsif ($db{$table}{$qt_id}{city_id} or $db{$table}{$qt_id}{region_id}) {
				my $city = $db{cities}{$db{$table}{$qt_id}{city_id}}{name} ;
				$city .= qq~, $db{regions}{$db{$table}{$qt_id}{region_id}}{name}~ if $city and $db{$table}{$qt_id}{region_id} ;
				&display_text ("City",$city) if $city ;
				&display_text ("Region",$city) if $db{$table}{$qt_id}{region_id} and not $city ;
			}
			&display_text ("Venue",$venue) if $venue ;
			
			if ($db{$table}{$qt_id}{poc_id}) {
				my $poc_name = ($db{event_quotes_poc}{$db{$table}{$qt_id}{poc_id}}{name}) ? $db{event_quotes_poc}{$db{$table}{$qt_id}{poc_id}}{name} : "N/A" ;
				&display_text ("Poc Name",$poc_name)   ;
				# my $value_ = $db{event_quotes_poc}{$db{$table}{$qt_id}{poc_id}}{contact_nr} ;

				my $value_ = $db{event_quotes_poc}{$db{$table}{$qt_id}{poc_id}}{contact_nr} ; 
				$value_ =~ s/ //g ;
				if (substr($value_,0,2) eq '27' && length($value_) == 11) {
					$value_ = "+27 " . substr($value_,2,2) . " " .  substr($value_,4,3) . " " .  substr($value_,7,4) ;
				} elsif ((substr($value_,0,2) eq '07' || substr($value_,0,2) eq '08' || substr($value_,0,2) eq '02') && length($value_) == 10) {
					$value_ = "+27 " . substr($value_,1,2) . " " .  substr($value_,3,3) . " " .  substr($value_,6,4) ;
				} else {
					$value_ = $db{event_quotes_poc}{$db{$table}{$qt_id}{poc_id}}{contact_nr} ;
				}
				$value_ = "N/A" unless $value_ ; 	
				
				&display_text ("Poc Contact Nr","$value_") ; #if $db{$table}{$qt_id}{poc_contact_nr} ;			
			
			}
			 
			&display_text ("Category 1",$db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_1}}{category}) if $db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_1}}{category} ;	
			my @a = split(/\|;\|/,$db{event_quotes_min}{$qt_id}{category_details}) ;
			&display_text ("Category 1 Sub Categories",$a[0]) if $a[0] ;
			&display_text ("Category 2",$db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_2}}{category}) if $db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_2}}{category} ;
			&display_text ("Category 2 Sub Categories",$a[1]) if $a[1] ;
			
			if ($db{$table}{$qt_id}{recipient_id}) {
				
				my $rec_name = ($db{event_quotes_recipient}{$db{$table}{$qt_id}{recipient_id}}{name}) ? $db{event_quotes_recipient}{$db{$table}{$qt_id}{recipient_id}}{name} : "N/A" ;
				my $rec_nr = ($db{event_quotes_recipient}{$db{$table}{$qt_id}{recipient_id}}{contact_nr}) ? $db{event_quotes_recipient}{$db{$table}{$qt_id}{recipient_id}}{contact_nr} : "N/A" ;
				
				&display_text ("Recipient Name",$rec_name) ;
				
				$rec_nr =~ s/ //g ;
				if (substr($rec_nr,0,2) eq '27' && length($rec_nr) == 11) {
					$rec_nr = "+27 " . substr($rec_nr,2,2) . " " .  substr($rec_nr,4,3) . " " .  substr($rec_nr,7,4) ;
				} elsif ((substr($rec_nr,0,2) eq '07' || substr($rec_nr,0,2) eq '08' || substr($rec_nr,0,2) eq '02') && length($rec_nr) == 10) {
					$rec_nr = "+27 " . substr($rec_nr,1,2) . " " .  substr($rec_nr,3,3) . " " .  substr($rec_nr,6,4) ;
				}		
				
				&display_text ("Recipient Nr",$rec_nr) ;
			}
			
			&display_text ("Additional Notes",$db{$table}{$qt_id}{additional_notes}) if $db{$table}{$qt_id}{additional_notes} ;
			&display_text ("Format of Title",$db{$table}{$qt_id}{format_of_title}) if $db{$table}{$qt_id}{format_of_title} ;
			
			# &pdf_bar(60,$db{$table}{$qt_id}{format_of_title},120,0,1) ;
			$up -= $next_line_space ;
			
		}

		$up+=1.25 ;
		&pdf_box_block_bottom(10,200,'#969696') ; # end block -------------------------------------

	}

	$inner_blue_box = 0 ;

	unless ($db{$table}{$qt_id}{excl_purchase_summary}) {
		
	}
		
	my $analytics_sql_where = ($event_or_analytics eq 'analytics') ? "id= '$qt_id'" : "event_quote_id <> '0' AND event_quote_id = '$qt_id'" ;	
		
	# &db_min_ro('analytics_event_bookings','id,event_quote_id,fixtures_saved_values,analytics_saved_values,start_date_time,sport_type_ids,event_name',"event_quote_id <> '0' AND event_quote_id = '$qt_id'",'','') ;		
	&db_min_ro('analytics_event_bookings','id,event_quote_id,fixtures_saved_values,analytics_saved_values,start_date_time,sport_type_ids,event_name',"$analytics_sql_where",'','') ;		
	
	# our $analytics_event_exists = ($db{analytics_event_bookings}{$qt_id}{event_quote_id}) ? 1 : 0 ; 
	our $analytics_event_exists = 0 ; 

	foreach (keys %{$db{analytics_event_bookings}}) {
		 $analytics_event_exists = 1 ; 
	}

	if ($analytics_event_exists) {

		&db_switch_conn('sss') ;
	
		&db_min_ro('teams','id,name','','','') ; 
		
		&db_switch_conn('aisa') ;
		
		# our @months = ("","January","February","March","April","May","June","July","August","September","October","November","December") ; 
		
		my @fixtures_saved_values = () ; my @analytics_saved_values_arr = () ; my %analytics_saved_values = () ; 
		
		our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; 

		our $analytics_table_body = qq~~ ; our $analytics_table = qq~~ ; 
				 
		my $text2 = $page->text;
		my $font2 = $pdf->corefont('Helvetica');   # built-in font
		my $size2 = 13/pt ;
		$text2->font($font2, $size2);
		
		foreach my $id (keys %{$db{analytics_event_bookings}}) {

			$sort_field{27}  = 'fixture_date/Time_from' ; 
			$sort_field{28}  = 'sport' ; 
			$sort_field{29}  = 'team' ; 
			$sort_field{30}  = 'home_vs_opp_team' ; 
			$sort_field{31}  = 'stream_forwarding' ;
			$sort_field{32}  = 'stream_key' ; 
			$sort_field{33}  = 'stream_URL' ; 

			$db{analytics_event_bookings}{$id}{fixtures_saved_values} =~ s/\|+$// ;
			
			$db{analytics_event_bookings}{$id}{analytics_saved_values} = ";;" unless $db{analytics_event_bookings}{$id}{analytics_saved_values} ;
			
			@analytics_saved_values_arr = split(/\|/,$db{analytics_event_bookings}{$id}{analytics_saved_values}) ; 
			
			$db{analytics_event_bookings}{$id}{fixtures_saved_values} = ";;;" unless $db{analytics_event_bookings}{$id}{fixtures_saved_values} ;
			
			@fixtures_saved_values 	= split(/\|/,$db{analytics_event_bookings}{$id}{fixtures_saved_values}) ; 
			
			my $nr_of_rows = scalar @fixtures_saved_values ;
			$nr_of_rows = scalar @analytics_saved_values_arr if scalar @analytics_saved_values_arr > $nr_of_rows ;
			
			my $fixtures_row_cnt = 0 ;
			foreach my $data (@fixtures_saved_values) {
				my @abc = split(/\;/,$data) ;
				 
				$fixtures_row_cnt++ ;
				$analytics_saved_values{$id}{$fixtures_row_cnt}{$sort_field{27}} = ($abc[0]) ? &common_min_date_as_string($abc[0]) : ($db{analytics_event_bookings}{$id}{start_date_time}) ? &common_min_date_as_string($db{analytics_event_bookings}{$id}{start_date_time}) : &common_min_date_as_string("$now_year-$now_mm-$now_dd 08:00:00") ;
				$analytics_saved_values{$id}{$fixtures_row_cnt}{$sort_field{28}} = ($abc[1]) ? $db{sport_types}{$abc[1]}{name} : ($db{analytics_event_bookings}{$id}{sport_type_ids} && $db{analytics_event_bookings}{$id}{sport_type_ids} !~ /;/) ?  $db{sport_types}{$db{analytics_event_bookings}{$id}{sport_type_ids}}{name} : "N/A" ;
				$analytics_saved_values{$id}{$fixtures_row_cnt}{$sort_field{29}} = ucfirst $abc[2] . ' ' . uc $abc[3] ;
				$analytics_saved_values{$id}{$fixtures_row_cnt}{$sort_field{30}} = ($abc[4] && $abc[6]) ? $db{teams}{$abc[4]}{name} . ' VVVVVSSSS ' . $db{teams}{$abc[6]}{name} : ($abc[4]) ? $db{teams}{$abc[4]}{name} . ' VVVVVSSSS N/A' : ($abc[6]) ? 'N/A VVVVVSSSS ' . $db{teams}{$abc[6]}{name} : "" ;
			
			}
			
			my $analytics_row_cnt = 0 ;
			
			foreach (@analytics_saved_values_arr) {
				my @abc = split(/\;/,$_) ;
				$analytics_row_cnt++ ;
				$analytics_saved_values{$id}{$analytics_row_cnt}{$sort_field{31}} = ($abc[0] eq '1') ? "Yes" : ($abc[0] eq '2') ? "No" : "" ;
				
				$abc[1] =~ s/\_semi_colon_character_/\;/g ; 
				$abc[2] =~ s/\_semi_colon_character_/\;/g ; 
				$abc[1] =~ s/\_pipe_character_/\|/g ;  
				$abc[2] =~ s/\_pipe_character_/\|/g ;  
				
				$analytics_saved_values{$id}{$analytics_row_cnt}{$sort_field{32}} = $abc[1] ;
				$analytics_saved_values{$id}{$analytics_row_cnt}{$sort_field{33}} = $abc[2] ; 	
			}                    
			if ($analytics_row_cnt > $fixtures_row_cnt) { 
				for ($fixtures_row_cnt + 1 .. $analytics_row_cnt) {
					$analytics_saved_values{$id}{$_}{$sort_field{27}} = ($db{analytics_event_bookings}{$id}{start_date_time}) ? &common_min_date_as_string($db{analytics_event_bookings}{$id}{start_date_time}) : &common_min_date_as_string("$now_year-$now_mm-$now_dd 08:00:00") ;
					$analytics_saved_values{$id}{$_}{$sort_field{28}} = ($db{analytics_event_bookings}{$id}{sport_type_ids} && $db{analytics_event_bookings}{$id}{sport_type_ids} !~ /;/) ?  $db{sport_types}{$db{analytics_event_bookings}{$id}{sport_type_ids}}{name} : "N/A" ;
				}
			}
			
			# foreach my $row_cnt (keys %analytics_saved_values) {
				# foreach my $col (keys %{$analytics_saved_values{$row_cnt}}) {
					# # $analytics_saved_values{$row_cnt}{$col} = ($analytics_saved_values{$row_cnt}{$col}) ? $analytics_saved_values{$row_cnt}{$col} : '-->None<--' ; 
				# }
			# }
			
			# last ;
			
		}
		 
		my %col_widths = () ; 
		
		my $asd = 80 ;
		
		my $_27_narrow = 17.5 ; 
		my $_31_narrow = 18.5 ; 
		my $_31_extra_narrow = 9.5 ; 
		my $_33_narrow = 9.5 ; 
		my $_32_narrow = 8.5 ;
		
		$col_widths{$sort_field{27}} = 17.5 ; 
		$col_widths{$sort_field{28}} = 8 ; 
		$col_widths{$sort_field{29}} = 8 ; 
		$col_widths{$sort_field{30}} = 27 ; 
		$col_widths{$sort_field{31}} = 26 ;    
		$col_widths{$sort_field{32}} = 15.5 ;  
		$col_widths{$sort_field{33}} = 16.5 ; 
		# $col_widths{$sort_field{31}} = 5      ; 
		# $col_widths{$sort_field{32}} = 8.5     ; 
		# $col_widths{$sort_field{33}} = 10  ; 
		
		my %orig_col_widths = %col_widths ; 
		
		foreach my $analytics_id (sort { $b <=> $a } keys %analytics_saved_values) {
			
			next unless $analytics_id ;
			
			%col_widths = %orig_col_widths ; 
			
			my $pos_cat = 15 ; 

			my %rows_required = () ; my %max_rows_required = () ; 
			
			my %max_col_width_excl_heading = () ; my %split_teams = () ;
		
			foreach my $row_cnt (sort { $a <=> $b } keys %{$analytics_saved_values{$analytics_id}}) {

				$max_rows_required{$row_cnt} = 1 ;
				
				for $col_cnt (27 .. 31) {
					
					$rows_required{$row_cnt}{$col_cnt} = 1 ;
					 
					if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) {
						$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} = " $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} " ;
						# $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} = lc $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} ;
						my $line_width = $text->advancewidth($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}});	
						$line_width -= 40.024  if $col_cnt == 30 && $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} && $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} =~ /VVVVVSSSS/ ; ## VVVSSS		
						$line_width = $line_width*mm ;
						$col_widths{$sort_field{$col_cnt}} = $line_width if $col_widths{$sort_field{$col_cnt}} < $line_width ;
						$max_col_width_excl_heading{$sort_field{$col_cnt}} = $line_width if !$max_col_width_excl_heading{$sort_field{$col_cnt}} || $max_col_width_excl_heading{$sort_field{$col_cnt}} < $line_width ;
					}
				}

				$rows_required{$row_cnt}{32} = 1 ;
				
				if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{32}}) {
					
					$rows_required{$row_cnt}{32} = 0 ;
					
					my $row_cnt2 = 0 ; 
					
					foreach (split("\n",$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{32}})) {
						
						next unless $_ ;
						$rows_required{$row_cnt}{32}++ ;
						my $line_width = $text->advancewidth(" $_ ") ;
						$line_width = $line_width*mm ;
						$col_widths{$sort_field{32}} = $line_width if $col_widths{$sort_field{32}} < $line_width ;
						$max_col_width_excl_heading{$sort_field{32}} = $line_width if !$max_col_width_excl_heading{$sort_field{32}} || $max_col_width_excl_heading{$sort_field{32}} < $line_width ;
						$row_cnt2++ ;
						$max_rows_required{$row_cnt} = $row_cnt2 if $row_cnt2 > $max_rows_required{$row_cnt} ;
						
					}
				}
				
				if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{33}}) {
					$rows_required{$row_cnt}{33} = 2 ;
					$max_rows_required{$row_cnt} = 2 if $max_rows_required{$row_cnt} < 2 ;				
				}

			}
		
			$up -= 5 ;

			if ($up < 30+($max_rows_required{1}-1)*3.5) {
				&pdf_check_value_of_up(30+($max_rows_required{1}-1)*3.5) ;
				$up -= 6 ;
			}
			
			my $heading = "ANALYTICS INFO - $db{analytics_event_bookings}{$analytics_id}{event_name} [$analytics_id]" ;
			
			my $width4 = $text2->advancewidth($heading);	 
			$width4 = $width4*mm ;
			
			$width4 = 10 + (190-$width4)/2 ;
			$width4 = 12 if $width4 < 12 ;
			
			&pdf_bar(10,$up,200,$up,'#969696',$heading,20,$width4) ; #EEEEEE
			
			$up -= 5;
			
			&pdf_box_block_top(10,200,'#969696') ; # start block -------------------------------------
			
			$up -= 5 ;			
		
			my $tot_width = 0 ; my $tot_ideal_width = 180 ;
			foreach (keys %col_widths) {
				$tot_width += $col_widths{$_} ;
				$tot_width += 1 ;
			}
			$tot_width -= 1 ;

			my %prev_col_widths = %col_widths ;
			
			# my $tot_extra_width = $tot_width - $tot_ideal_width ; 
			
			if ($tot_width > $tot_ideal_width) {
				$col_widths{$sort_field{31}} = $_31_narrow ;
				$tot_width -= ($prev_col_widths{$sort_field{31}} - $col_widths{$sort_field{31}}) ;
				$prev_col_widths{$sort_field{31}} = $col_widths{$sort_field{31}} ;
			}
			
			if ($tot_width > $tot_ideal_width) {
				$col_widths{$sort_field{31}} = $_31_extra_narrow ;
				$tot_width -= ($prev_col_widths{$sort_field{31}} - $col_widths{$sort_field{31}}) ;			
			}
			
			if ($tot_width > $tot_ideal_width) {
				$col_widths{$sort_field{33}} = $_33_narrow ;
				$tot_width -= ($prev_col_widths{$sort_field{33}} - $col_widths{$sort_field{33}}) ;			
			}
			
			if ($tot_width > $tot_ideal_width) {
				if ($max_col_width_excl_heading{$sort_field{32}} < $col_widths{$sort_field{32}}) {
					$col_widths{$sort_field{32}} = $_32_narrow ;
					$tot_width -= ($prev_col_widths{$sort_field{32}} - $col_widths{$sort_field{32}}) ;					
				}
			}
			
			if ($tot_width > $tot_ideal_width) {
				$col_widths{$sort_field{27}} = $_27_narrow ; 
				$tot_width -= ($prev_col_widths{$sort_field{27}} - $col_widths{$sort_field{27}}) ;					
			}

			if ($tot_width > $tot_ideal_width) {

				my $max_total_len = 0 ; my $max_single_len = 0 ; my %tot_widths = () ; 
				
				foreach my $row_cnt (keys %{$analytics_saved_values{$analytics_id}}) {
					
					my ($home_team,$away_team) = split(/\ VVVVVSSSS /,$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{30}}) ; 
					
					$home_team = "N/A" unless $home_team ;
					$away_team = "N/A" unless $away_team ;
					
					my $line_width1 = $text->advancewidth(" $home_team vs ") ;
					my $line_width2 = $text->advancewidth(" $away_team ") ;
					my $line_width3 = $text->advancewidth(" $away_team vs $away_team ") ;
					
					$line_width1 = $line_width1*mm;
					$line_width2 = $line_width2*mm;
					$line_width3 = $line_width3*mm;
					
					$tot_widths{$row_cnt} = $line_width3 ;
	 
					$max_single_len = $line_width1 if $line_width1 > $max_single_len ;
					$max_single_len = $line_width2 if $line_width2 > $max_single_len ;
					$max_total_len 	= $line_width3 if $line_width3 > $max_total_len ;

				}
				
				$col_widths{$sort_field{30}} = $max_single_len ;
				$tot_width -= ($prev_col_widths{$sort_field{30}} - $col_widths{$sort_field{30}}) ;					
			
				foreach my $row_cnt (keys %{$analytics_saved_values{$analytics_id}}) {
					
					if ($tot_widths{$row_cnt} <= $max_single_len) {
						$split_teams{$row_cnt} = 0 ;
					} else {
						$split_teams{$row_cnt} = 1 ;
						$rows_required{$row_cnt}{30} = 2 ;
						$max_rows_required{$row_cnt} = 2 if !$max_rows_required{$row_cnt} || $max_rows_required{$row_cnt} < 2 ;
					}
					
				}
				
			}
		
			if ($tot_width < $tot_ideal_width) {
				$col_widths{$sort_field{32}} += ($tot_ideal_width - $tot_width) ;
			}
			
			my $up_orig = $up ; 

			my $min_up = $up ; 
			
			my %max_line_cnt = () ; my %row_height = () ; my %analytics_saved_values_new = () ; 
		
			foreach my $row_cnt (sort { $a <=> $b } keys %{$analytics_saved_values{$analytics_id}}) {
				
				$max_line_cnt{$row_cnt} = 1 unless $max_line_cnt{$row_cnt} ;
		
				my $line_width1 = $text->advancewidth(" 11-Aug-2025 ") ;
				# my $line_width2 = $text->advancewidth("Stream URL ");	 
				# my $line_width3 = $text->advancewidth("S/Key ");	 
				
				$line_width1 = $line_width1*mm ;
				# $line_width2 = $line_width2*mm ;
				# $line_width3 = $line_width3*mm ;
	 
				# $line_width1 = $line_width1;
				# $line_width1 = $line_width1;

				if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{32}}) {
					
					my $total_line_width = $text->advancewidth($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{32}});	
					
					my $max_line_width = 220 ; 
					
					my $prev_line_text = "" ; my $line_cnt = 0 ; my $line_text = "" ; 
					
					if ($total_line_width > $max_line_width) {
				
						foreach (split(/ /,$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{32}})) {
							
							$line_text .= "$_" ;
					
							my $line_text_width = $text->advancewidth($line_text) ;
							my $prev_line_text_width = $text->advancewidth($prev_line_text) ;

							$line_text .= " " ; $prev_line_text .= " " if $prev_line_text ;

							if ($prev_line_text_width <= $max_line_width && $max_line_width < $line_text_width) {
								
								chop $prev_line_text if $prev_line_text ;
								
								$analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} .= "$prev_line_text
" ;
								$up-=3.5 ; $line_cnt++ ; $line_text = "$_ " ; $prev_line_text = "$_ " ;
								$max_line_cnt{$row_cnt} = $line_cnt if $line_cnt > $max_line_cnt{$row_cnt} ;
								
							} else {
								$prev_line_text .= "$_" ;
							}
						}
					
						if ($line_text) {
							chop $line_text if $line_text ; 
							$analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} .= "$line_text
" ;
							$up-=3.5 ; $line_cnt++ ; $line_text = "" ; $prev_line_text = "" ;
							$max_line_cnt{$row_cnt} = $line_cnt if $line_cnt > $max_line_cnt{$row_cnt} ;
						}
						
						$up += 3.5*$line_cnt ; 	
						
					} else {
						$analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} .= "$prev_line_text
" ;
					}					
				} 
			}
			
			my $up_orig = $up ;
			
			foreach my $row_cnt (sort { $a <=> $b } keys %{$analytics_saved_values{$analytics_id}}) {
				
				next unless $row_cnt ;
				
				if ($row_cnt == 1) {
				
					for my $col_cnt (27 .. 33) {
						
						my $table_header =  join(" ", map { ucfirst $_ } split (/\_/, $sort_field{$col_cnt})) ; 
						
						if ($sort_field{$col_cnt} eq 'fixture_date/Time_from') {
							&pdf_small_bold_text ($pos_cat,$up,"Date Time") ;
							# $up -= 3.25 ; 
							# &pdf_small_bold_text ($pos_cat,$up,"/Time From") ;
							# $up += 3.25 ; 				
						} elsif ($sort_field{$col_cnt} eq 'age_group') {
							# &pdf_small_bold_text ($pos_cat,$up,"Age") ;
							# $up -= 3.25 ; 
							# &pdf_small_bold_text ($pos_cat,$up,"Group") ;
							# $up += 3.25 ; 
						} elsif ($sort_field{$col_cnt} eq 'stream_forwarding') { 
							if ($col_widths{$sort_field{31}} == $_31_narrow) {
								&pdf_small_bold_text ($pos_cat,$up,"S/Forwarding") ;
							} elsif ($col_widths{$sort_field{31}} == $_31_extra_narrow) {
								&pdf_small_bold_text ($pos_cat,$up,"S/F") ;
							} else {
								&pdf_small_bold_text ($pos_cat,$up,"Stream Forwarding") ;
							}
						} elsif ($sort_field{$col_cnt} eq 'stream_key') { 
							if ($col_widths{$sort_field{32}} == $_32_narrow) {
								&pdf_small_bold_text ($pos_cat,$up,"S/Key") ;
							} else {
								&pdf_small_bold_text ($pos_cat,$up,"Stream Key") ;
							} 
						} elsif ($sort_field{$col_cnt} eq 'stream_URL') { 
						
							if ($col_widths{$sort_field{33}} == $_33_narrow) {
								&pdf_small_bold_text ($pos_cat,$up,"S/URL") ;
							} else { 
								&pdf_small_bold_text ($pos_cat,$up,"Stream URL") ;
							}
						 
							# $up -= 3.25 ; 
							# &pdf_small_bold_text ($pos_cat,$up,"Forwarding") ;
							# $up += 3.25 ; 
						} else {
							&pdf_small_bold_text ($pos_cat,$up,"$table_header") ;
						}
						
						$pos_cat += $col_widths{$sort_field{$col_cnt}} + 1 ;
						
					}
					
					# $up -= 3.25 ;
					$up_orig = $up ;
					
				}	
				
				$pos_cat = 15 ;
				
				$up -= 5 ;
				
				if (($rows_required{$row_cnt}{27} > 1 || $col_widths{$sort_field{27}} == $_27_narrow) && $max_rows_required{$row_cnt} < 2) {
					$max_rows_required{$row_cnt} = 2 ;
				}
				
				$max_rows_required{$row_cnt} = 1 unless $max_rows_required{$row_cnt} ;
				
				my $remaining_space_required = 15 + 3.5*($max_rows_required{$row_cnt} - 1) ;
				
				if ($up < $remaining_space_required) {
					$up = 10 ;
					&pdf_box_block_bottom(10,200,'#969696') ; # end block -------------------------------------
					&pdf_check_value_of_up($remaining_space_required) ;
					&pdf_box_block_top(10,200,'#969696') ; # start block -------------------------------------
					$up -= 6 ;
				}
				
				$up_orig = $up ; 

				for my $col_cnt (27 .. 33) {
	 
					$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} = "" if $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} eq '-->None<--' ;
					
					$rows_required{$row_cnt}{$col_cnt} = 1 unless $rows_required{$row_cnt}{$col_cnt} ;
					
					if ($col_cnt == 27) {
						if ($rows_required{$row_cnt}{$col_cnt} > 1 || $col_widths{$sort_field{$col_cnt}} == $_27_narrow) {
							$rows_required{$row_cnt}{$col_cnt} = 2 ;
							$max_rows_required{$row_cnt} = 2 if $max_rows_required{$row_cnt} < 2 ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',substr($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}},0,12),10,$pos_cat,'small','small_black',1)  ;
							$up -= 3.5 ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',' ' . substr($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}},13,7),10,$pos_cat,'small','small_black',1)  ;
						} else {
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}},10,$pos_cat,'small','small_black',1)  ;
						}
					} elsif ($col_cnt == 28) {
						# my @sport_split = () ; 
						# if (length($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) > 10) {
							# @sport_split = split(/ /,$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) ; 
						# } else {
							# push @sport_split, $analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} ;
						# }
						&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}",10,$pos_cat,'small','small_black',1)  ;
					}  elsif ($col_cnt == 30) {
						my @teams_split = () ;  
						if ($split_teams{$row_cnt}) {
							@teams_split = split(/\ VVVVVSSSS /,$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) ;  
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"$teams_split[0] vs",10,$pos_cat,'small','small_black',1)  ;			
							$up -= 3.5 ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE'," $teams_split[1]",10,$pos_cat,'small','small_black',1)  ;			
						} else {
							$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}} =~ s/\VVVVVSSSS/\vs/g ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}",10,$pos_cat,'small','small_black',1)  ;						
						}

					}  elsif ($col_cnt == 32) {
						# chomp $analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} ;
						# my $new_line_cnt = 1 ;
						
						if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) {
							foreach (split("\n",$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}})) { 

								&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE'," $_ ",10,$pos_cat,'small','small_black',1)  ;
								$up -= 3.5 ;
								# $new_line_cnt++ ;
							}
							$up += 3.5 ;
						} else {
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1)  ;
						}
						# &pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}",10,$pos_cat,'small','small_black',1) ;
						# &pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1) unless $analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} ; 
						# $new_line_cnt = 1 unless $analytics_saved_values_new{$sort_field{$col_cnt}}{$row_cnt} ; 	 
						
					} elsif ($col_cnt == 33) {
						if ($analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}) {
							$pos_cat += 3.5 if $col_widths{$sort_field{$col_cnt}} == 16.5 ;
							&pdf_add_URL_link($pos_cat,$up,"$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}","$htmlpath/img/icons/event_details_pdf_url_icon.PNG")  ;
							$pos_cat -= 3.5 if $col_widths{$sort_field{$col_cnt}} == 16.5 ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1) ; 					
							$up -= 3.5 ;
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1) ; 					
						} else {
							&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1) ; 					
						}
						
					} else {
						&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"$analytics_saved_values{$analytics_id}{$row_cnt}{$sort_field{$col_cnt}}",10,$pos_cat,'small','small_black',1)  ;
					}
					
					for ($rows_required{$row_cnt}{$col_cnt} + 1 .. $max_rows_required{$row_cnt}) {
						$up -= 3.5 ;
						&pdf_bar($pos_cat,$up+1,$pos_cat+$col_widths{$sort_field{$col_cnt}},$up+1,'#EEEEEE',"",10,$pos_cat,'small','small_black',1) ;
					}
					
					$up = $up_orig ; 
					$pos_cat += $col_widths{$sort_field{$col_cnt}} + 1 ;
					# $up -= 3.5 ;
					
				}
				
				$up -= 3.5*($max_rows_required{$row_cnt} - 1) ;
				
			}
			
			$up -= 5 ;
			
			&pdf_box_block_bottom(10,200,'#969696') ; # end block -------------------------------------

		}
		
		if ($up < 52) {
			&pdf_box_block_bottom(10,200,'#969696') ; # end block -------------------------------------
			&pdf_check_value_of_up(52) ;
			&pdf_box_block_top(10,200,'#969696') ; # start block -------------------------------------
			$up -= 6 ;
		}
		$up -= 5 ;
		&pdf_small_bold_text (15,$up,"Please follow these guidelines:") ;
		$up -= 5 ;
			
		&pdf_small_text(15,$up,"1. Please ensure you have been added to the temporary WhatsApp group called \"Streams for Analytics\" before game day.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"2. Ensure the start of the game is captured.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"3. Ensure the final whistle of the game is captured.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"4. For quarter-finals, semi-finals and finals, a penalty shoot-out may occur - end times should be extended to") ; $up -= 4 ;
		&pdf_small_text(15,$up,"5. Team colours must be accurately reflected on the scoreboard.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"6. The scoreboard must reflect the score accurately at all times, as best as possible.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"7. Stream-forwarding details have been added to the event to allow live coding from YouTube. If the event needs to be recreated, the support team") ; $up -= 4 ;
		&pdf_small_text(15,$up,"   must be informed so that the stream-forwarding details can be re-applied.") ; $up -= 4 ;
		&pdf_small_text(15,$up,"8. If there is a delay to the match start time, the support team must be informed so the analysts can be updated.") ; 

		# &pdf_small_text(15,$up,"1. Capture start of the game.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"2. Capture the final whistle of the game.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"3. Quarters, semis and finals there could be a penalty shoot out - please extend your end time to include these in your same stream.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"4. Team colours should reflect accurately on the scoreboard.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"5. Scoreboard to reflect accurately as best you can.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"6. We have added stream forward details to your event so we can code live from YouTube - if you need to recreate your event please let me know") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"    so I can read stream forwarding details.") ; $up -= 4 ;
		# &pdf_small_text(15,$up,"7. If there is a delay in the start time of your match please let me know so I can update the analysts.") ;
		
		# $up -= 4 ;
		# $up = 10 ;
		# &pdf_box_block_bottom(10,200,'#969696') ; # end block -------------------------------------
	
	}
	 
	# my $page = $pdf->page;
	# my $font = $pdf->corefont('Helvetica', -encoding => 'latin1');

	# my $text = $page->text;
	
	# my $size = 12;*
	# $text->font($font, $size);0*-/-++
	# $text->fillcolor('blue');

	# # Position in points
	# my $x = 50;
	# my $y = 700;

	# # Write the link text
	# my $label = "Click Here";
	# $text->translate($x, $y);
	# $text->text($label);

	# # Width/height for the annotation box
	# # Bounding box for the link
	
	# my $width  = $font->width($label) * $size / 1000;
	# my $height = $size;
	
	# # Add the clickable annotation (note: use 'uri' not '-uri')
	
	# $page->annotation(
		# 50, 700, 250, 720,
		# -uri => 'https://www.example.com',
	# );
	
	# my $page = $pdf->page();
 
	# my ($llx, $lly, $urx, $ury) = (50, 700, 250, 720) ;
	# my $annot = $page->annotation();
	# $annot->url('https://www.example.com',-rect => [ $llx, $lly, $urx, $ury ]) ;

	# my $font = $pdf->corefont('Helvetica');
	# my $text = $page->text();
	# $text->font($font, 12);
	# $text->translate($llx, $lly + 5);
	# $text->text('Visit Example.com');
	 
} #------------------------------------------------------------------------------------------

sub pdf_add_URL_link {

    my ($x1,$y1,$url,$icon_path) = @_ ;

    return if !$x1 || !$y1 || !$url || !$pdf || !$page || !$icon_path ;
    
	return unless -e $icon_path ;

    my $gfx = $page->gfx ;
    my $icon = $pdf->image_png($icon_path) ;

    my $icon_width  = 1 ;
    my $icon_height = 1 ;

    my $x2 = $x1 + $icon_width ;
    my $y2 = $y1 + $icon_height ;
	
    $gfx->image($icon,($x1+1.25)/mm,($y1-4)/mm, $icon_width/25.4) ;
	
    my $annot = $page->annotation() ;
    $annot->url($url, -rect => [($x1+1.25)/mm,($y1-4)/mm,($x1+7.25)/mm,($y1+2)/mm]) ;
 
} #-------------------------------------------------------------

# sub pdf_add_URL_link {
	
	# my ($x1,$y1,$url) = @_ ;
	
	# return if !$x1 || !$y1 || !$url ; 
	
	# my $total_line_width = $small_text->advancewidth("Click Here");	
	
	# $total_line_width = $total_line_width / 3 ;
	
	# my $x2 = $x1 + $total_line_width ; 
	# my $y2 = $y1 + 1.7 ; 
	 
	# my $annot = $page->annotation() ; 
	# $annot->url("$url",-rect => [$x1/mm,$y1/mm,$x2/mm,$y2/mm]) ;
  
	# &pdf_small_blue_text($x1,$y1,"Click Here") ;
	# &pdf_small_blue_text($x1+0.25,$y1,"________") ;
					
# } #------------------------------------------------------------------------------------------

sub display_text_block {
	
	my ($name,$list_ids,$table_ids,$name_from_ids,$l_pos,$r_pos,$top_frame,$left_or_right,$split_by,$name_from_ids_2,$list_ids_2,$table_ids_2,$name_from_list_ids_2) = @_ ; 
	
	&pdf_small_bold_text ($pos_cat,$up,$name) ;
	
	my @list_ids_2 = () ; 
	@list_ids_2 = split($split_by,$list_ids_2) if $list_ids_2 ;
	
	$list_ids =~ s/$split_by/\\n/g;
	
	my $cnt = 0 ; 
	
} #------------------------------------------------------------------------------------------

sub display_text {
	
	# my ($left_or_right,$heading,$text) = @_ ; 
	my ($heading,$text,$line_width) = @_ ; 

	# my $text_ = $page->text;
	# my $font = $pdf->corefont('Helvetica');   # built-in font
	# my $size = 8/pt ;
	# $text_->font($font, $size);


	$line_width = (!$line_width) ? 195 : $line_width ;
	my $cnt_lines = 0 ; my $text_new = '' ; my $text_with_new_line = 0 ; 
	foreach my $line (split(/\n/,$text)) { 
		my $wrapped_line = '' ; $text_with_new_line++ ;
		foreach my $word (split(/ /,$line)) {
			my $word_length = length($word) ;
			
			# my $word_length1 = $text->advancewidth("$word") ;
			# print "\n word_length1 : $word_length1" ;
			
			my $wrapped_line_length = length($wrapped_line) ;
			if (length($wrapped_line) + length($wrapped_line) > $line_width) {
				$cnt_lines++ ; $wrapped_line = '' ; $text_new .= '
' . $word ;				
			} else {
				$wrapped_line .= $word . ' ' ;
				$text_new .= $word . ' ' ;
			}
		}
		$cnt_lines++ ;
		$text_new .= $word . '
' ;	

	}
	chomp $text_new if $text_new ;
	$up = $up - $next_line_space ;
	&pdf_small_bold_text ($pos_cat,$up,"$heading") ;
	&pdf_bar($pos_des-2,$up+0.75,195,$up+0.75,'#EEEEEE',"$text_new",10,$pos_des,'small','small_black',1) if $cnt_lines == 1  ;
	&pdf_bar($pos_des-2,$up+0.75-1.625*($cnt_lines-1),195,$up+0.75-1.625*($cnt_lines-1),'#EEEEEE',"$text_new",10+9*($cnt_lines-1),$pos_des,'small','small_black',2,$line_width) if $cnt_lines > 1  ;
	# &pdf_bar($pos_des-2,$up-2.5,195,$up-2.5,'#EEEEEE',"[$text_new]",10+9*($cnt_lines-1),$pos_des,'small','small_black',2,150) if $cnt_lines == 3  ;
	# &pdf_bar($pos_des-2,$up-4.125,195,$up-4.125,'#EEEEEE',"[$text_new]",10+9*($cnt_lines-1),$pos_des,'small','small_black',2,150) if $cnt_lines == 4  ;
	# &pdf_bar($pos_des-2,$up-5.75,195,$up-5.75,'#EEEEEE',"[$text_new]",10+9*($cnt_lines-1),$pos_des,'small','small_black',2,150) if $cnt_lines == 5  ;
	# return if $cnt_lines == 1  ;
	# &pdf_bar($pos_des-2,$up+1,195,$up+1,'#EEEEEE',$text,10*$cnt_lines,$pos_des,'small','small_black',$cnt_lines,120) if $cnt_lines > 1 ;
	$up+=1.25 if $cnt_lines > 1 ;
	
} #------------------------------------------------------------------------------------------

sub vertical_lines_inner_box {
	
	&pdf_thin_black_line ($blocks[1],$top,$blocks[1],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($blocks[2],$top,$blocks[2],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($blocks[3],$top,$blocks[3],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($blocks[4],$top,$blocks[4],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($blocks[5],$top,$blocks[5],$up,'#969696') ; # vertical	
	
} #----------------------------------------------------------------------------------------------------

sub vertical_lines_inner_box_t {
	
	&pdf_thin_black_line ($tblocks[1],$top,$tblocks[1],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($tblocks[2],$top,$tblocks[2],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($tblocks[3],$top,$tblocks[3],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($tblocks[4],$top,$tblocks[4],$up,'#969696') ; # vertical
	&pdf_thin_black_line ($tblocks[5],$top,$tblocks[5],$up,'#969696') ; # vertical	
	
} #----------------------------------------------------------------------------------------------------

sub quote_pdf_footer {
	
	&pdf_check_value_of_up(60);
	$up = 90;
	my $txt = qq~The parties hereby accept and agree to this quote, which incorporates by reference all the terms and conditions set forth in the Interactive Television Africa's Terms and Conditions document, attached hereto as Annexure A and the Service Level Agreement attached hereto as Annexure B (all, collectively with this quote, the "Agreement") effective as of the later of the signature dates below.~;
	&pdf_text_block (10,$txt,120,3) ;
	$up = $up - 10;
	&pdf_medium_bold_text (10, $up, "Name:")  ; &pdf_thin_black_line (30,$up,100,$up,'#969696') ; #&pdf_tiny_text (25, $up, "________________________________________________") ;
	&pdf_medium_bold_text (110, $up, "Date:") ; &pdf_thin_black_line (130,$up,200,$up,'#969696') ;
	$up = $up - 5;
	&pdf_small_text (10, $up, "(Duly Authorised)") ;
	$up = $up - 10;
	&pdf_medium_bold_text (10, $up, "Company:") ;    &pdf_thin_black_line (30,$up,100,$up,'#969696') ;
	&pdf_medium_bold_text (110, $up, "Signature:") ; &pdf_thin_black_line (130,$up,200,$up,'#969696') ;
	$up = $up - 15;
	&pdf_medium_bold_text (10, $up, "Name:")  ;     &pdf_thin_black_line (30,$up,100,$up,'#969696') ;
	&pdf_medium_bold_text (110, $up, "Date:") ;     &pdf_thin_black_line (130,$up,200,$up,'#969696') ;
	$up = $up - 5;
	&pdf_small_text (10, $up, "(Duly Authorised on behalf of Interactive Television Africa)") ;
	$up = $up - 10;
	&pdf_medium_bold_text (110, $up, "Signature:") ; 
	&pdf_thin_black_line (130,$up,200,$up,'#969696') ;
	
} #------------------------------------------------------------------------------------------

sub quote_pdf_vars {

	our @rboxtxt  = (0,103,116,143,170,197) ;
	our @boxtxt   = (0,12,106,120,147,174) ;
	our @blocks   = (0,10,104,118,145,172) ;

	our @tboxrtxt = (0,77,107,137,167,197) ;
	our @tboxtxt  = (0,12,82,112,142,172) ;
	our @tblocks  = (0,10,80,110,140,170) ;
} #-------------------------------------------------------------------------------

sub custom_date_txt {

	my ($date) = @_ ;
	
	return "Unknown" if not $date; 
	
	my $dt_txt = Date_to_Text(substr($date,0,4),substr($date,5,2),substr($date,8,2));

	$dt_txt =  substr($dt_txt,4) ;

	return ($dt_txt) ;
} #------------------------------------------------------------------------------------------

sub check_space_on_page_custom {

	my ($value) = @_ ;

	if ($up < $value) {
		&pdf_thin_black_line (10,$top,10,$up) ; 
		&vertical_lines_table; # draw vertical_lines on prematurely ended table
		&pdf_initialise_page ;
		$up=282 ; 
		$top=$up; 
		&pdf_thin_black_line(10,$up,200,$up) ; 
		$across = 1 ;
	}
} #----------------------------------------------------------------------------------------------------
  
sub get_val {

	my ($val,$cur) = @_ ;

	my $disp_val = $val ;

	if ($val eq '0.00') { 
		$disp_val = '' ; 
	
	} elsif ($val) {
		$disp_val = $cur . ' ' . $val ;
	}
	# &common_min_debug($val);
	
	return($disp_val);
} #------------------------------------------------------------------------------------------
  
sub vertical_lines_table {

	unless ($exclude_rate) {
		&pdf_thin_black_line ($blocks[2],$top,$blocks[2],$up) ; # vertical
		&pdf_thin_black_line ($blocks[3],$top,$blocks[3],$up) ; # vertical
	}

	unless ($exclude_vat) {
		&pdf_thin_black_line ($blocks[4],$top,$blocks[4],$up) ; # vertical
	}

	&pdf_thin_black_line ($blocks[5],$top,$blocks[5],$up) ; # vertical
	&pdf_thin_black_line ($blocks[6],$top,$blocks[6],$up) ; # vertical

} #------------------------------------------------------------------------------------------
  
sub screen2 {

	print <<ENDOFTEXT;
	$dialog{'common'}{'head'}    
		<div id="content" class="col-lg-12 col-sm-12">                       
			<CENTER>
			<table height='100%' width='100%'>
			<tr>
				<td align='center'>
					<iframe src='$useropts{'$domain'}/pdf/event_details/$pdfname' width='100%' height='100%' frameborder='0'></iframe>
				</td>
			</tr>
			</table>    
		</div>
	</body>
	</html>
ENDOFTEXT
#

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

use db ;
use db_min ;
use dialog ;
use today ;
use common ;
use pdf ;
use tabs ;

1;