<?php
set_time_limit(0);
require_once('print_functions.php');
require('fpdf.php');
$pdf = new FPDF('P', 'pt', 'Letter');
$pdf->AddFont('verdanab');
$pdf->AddFont('verdana');
$counter = 0; // used for looping through actors in the csv
$csv_file="test.csv";
$csv_array = importcsv($csv_file);
$max = count($csv_array);
// database connection - removed for presentation
$t10 = mysql_pconnect($hostname_t10, $username_t10, $password_t10) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_t10, $t10);
while ($max > $counter) {
$star_name = ucfirst(trim($csv_array[$counter][0]));
if ($star_name == '') {
$counter++;
continue;
}
$qryActor = "SELECT id, bio, DATE_FORMAT(birthdate,'%M %e, %Y') AS birthdate, DATE_FORMAT(deathdate,'%M %e, %Y') AS deathdate, ranking FROM stars WHERE name='".mysql_real_escape_string($star_name)."'";
$rstActor = mysql_query($qryActor, $t10) or die(mysql_error()."1");
$totalRows_rstActor = mysql_num_rows($rstActor);
if ($totalRows_rstActor < 1) {
$counter++;
continue;
}
$row_rstActor = mysql_fetch_assoc($rstActor);
$star_id = $row_rstActor['id'];
$star_rank = $row_rstActor['ranking'];
$birthdate = $row_rstActor['birthdate'];
$deathdate = $row_rstActor['deathdate'];
if(!$deathdate){
$deathdate = "";
}
$bio = trim_last_sentence(substr(htmlspecialchars(urldecode($row_rstActor['bio'])), 0, 500));
$bio = str_replace("&#34;", "'", $bio);
$bio = str_replace("&#39;", "'", $bio);
$bio = str_replace("&#93;", "'", $bio);
$bio = str_replace("&#91;", "'", $bio);
$bio = str_replace("&#38;", "&", $bio);
$bio = str_replace("&#233;", "&", $bio);
$bio = str_replace(""", "'", $bio);
$bio = trim_last_sentence(substr($bio, 0, 390));
//print "$bio<br>";
mysql_free_result($rstActor);
$decade_2000 = getDecadeTable($star_id, '2000 and 2009', $t10);
$decade_1990 = getDecadeTable($star_id, '1990 and 1999', $t10);
$decade_1980 = getDecadeTable($star_id, '1980 and 1989', $t10);
$decade_1970 = getDecadeTable($star_id, '1970 and 1979', $t10);
$decade_1960 = getDecadeTable($star_id, '1960 and 1969', $t10);
$decade_1950 = getDecadeTable($star_id, '1950 and 1959', $t10);
$decade_1940 = getDecadeTable($star_id, '1940 and 1949', $t10);
$decade_1930 = getDecadeTable($star_id, '1930 and 1939', $t10);
$decade_1920 = getDecadeTable($star_id, '1920 and 1929', $t10);
// set empty decade values, used later for no reviews vs. display count and average
$total_count_1920 = '';
$total_count_1930 = '';
$total_count_1940 = '';
$total_count_1950 = '';
$total_count_1960 = '';
$total_count_1970 = '';
$total_count_1980 = '';
$total_count_1990 = '';
$total_count_2000 = '';
$total_count_1920 = getDecade_total_count('1920 and 1929', $decade_1920, $star_id, $t10);
$total_count_1930 = getDecade_total_count('1930 and 1939', $decade_1930, $star_id, $t10);
$total_count_1940 = getDecade_total_count('1940 and 1949', $decade_1940, $star_id, $t10);
$total_count_1950 = getDecade_total_count('1950 and 1959', $decade_1950, $star_id, $t10);
$total_count_1960 = getDecade_total_count('1960 and 1969', $decade_1960, $star_id, $t10);
$total_count_1970 = getDecade_total_count('1970 and 1979', $decade_1970, $star_id, $t10);
$total_count_1980 = getDecade_total_count('1980 and 1989', $decade_1980, $star_id, $t10);
$total_count_1990 = getDecade_total_count('1990 and 1999', $decade_1990, $star_id, $t10);
$total_count_2000 = getDecade_total_count('2000 and 2009', $decade_2000, $star_id, $t10);
if (($decade_2000 != 'no reviews') && ($total_count_2000 > 0)){
$decade_2000 = round($decade_2000, 4);
}
if (($decade_1990 != 'no reviews') && ($total_count_1990 > 0)){
$decade_1990 = round($decade_1990, 4);
}
if (($decade_1980 != 'no reviews') && ($total_count_1980 > 0)){
$decade_1980 = round($decade_1980, 4);
}
if (($decade_1970 != 'no reviews') && ($total_count_1970 > 0)){
$decade_1970 = round($decade_1970, 4);
}
if (($decade_1960 != 'no reviews') && ($total_count_1960 > 0)){
$decade_1960 = round($decade_1960, 4);
}
if (($decade_1950 != 'no reviews') && ($total_count_1950 > 0)){
$decade_1950 = round($decade_1950, 4);
}
if (($decade_1940 != 'no reviews') && ($total_count_1940 > 0)){
$decade_1940 = round($decade_1940, 4);
}
if (($decade_1930 != 'no reviews') && ($total_count_1930 > 0)){
$decade_1930 = round($decade_1930, 4);
}
if (($decade_1920 != 'no reviews') && ($total_count_1920 > 0)){
$decade_1920 = round($decade_1920, 4);
}
$start_decade = get_first_decade($total_count_1920, $total_count_1930, $total_count_1940, $total_count_1950, $total_count_1960, $total_count_1970, $total_count_1980, $total_count_1990, $total_count_2000);
$end_decade = get_last_decade($total_count_1920, $total_count_1930, $total_count_1940, $total_count_1950, $total_count_1960, $total_count_1970, $total_count_1980, $total_count_1990, $total_count_2000);
$card_num = 1;
$card_num_total = 1;
$dvd_avail = '';
$rank = 0;
$movie_rank = 0;
$qry = "SELECT Distinct movie_stars.movie_id, movies.name, movies.ranking FROM movie_stars, movies, movie_status where (movies.lang_id=0) AND (movie_status.movie_data_id >= 0) AND (movies.year <= 2006) AND (star_id=$star_id) AND (movie_status.movie_id=movies.id) AND (movie_stars.movie_id=movies.id) order by ranking desc";
$result = mysql_query($qry, $t10);
$totalRows_movies = mysql_num_rows($result);
$card_num_total = getPageNumber($totalRows_movies);
while ($card_num <= $card_num_total) {
$pdf->AddPage();
$page = print_PDF_Page($pdf, $card_num, $card_num_total, $star_id, $star_name, $star_rank, $birthdate, $deathdate, $bio); // prints top of page
$decades = print_PDF_decades ($pdf, $start_decade, $end_decade, $decade_1920, $decade_1930, $decade_1940, $decade_1950, $decade_1960, $decade_1970, $decade_1980, $decade_1990, $decade_2000, $total_count_1920, $total_count_1930, $total_count_1940, $total_count_1950, $total_count_1960, $total_count_1970, $total_count_1980, $total_count_1990, $total_count_2000);
if ($movie_rank < $totalRows_movies) {
$movie_rank = print_PDF_movie_col($pdf, $movie_rank, $result, 1, $t10, $totalRows_movies);
if ($movie_rank != 0) {
$movie_rank = print_PDF_movie_col($pdf, $movie_rank, $result, 2, $t10, $totalRows_movies);
}
}
$card_num++;
}
mysql_free_result($result);
$counter++;
}
$pdf->Output(); // prints to browser
$pdf->Output('test.pdf', 'F'); // prints to file
print "complete";
?>
function print_PDF_page ($pdf, $page_num, $card_num_total, $star_id, $star_name, $star_rank, $birthdate, $deathdate, $bio) {
$pdf->SetXY(0,30);
$pdf->SetFont('verdanab','',40);
$pdf->Cell(0,10,$star_name,0,0,'C');
$pdf->SetXY(0,56);
$pdf->SetFont('verdanab','',10);
$pdf->Cell(0,15,"$page_num of $card_num_total",0,0,'C');
$jpg_name = 'actors/a'.$star_id.'.jpg';
$image_info = getimagesize($jpg_name);
$img_width = $image_info[0];
$img_height = $image_info[1];
//$img_ratio = ($img_height/72)/($img_height/300);
$new_img_height = 117;
$img_ratio = ($new_img_height/$img_height);
$new_img_width = $img_width * $img_ratio;
$pdf->Image($jpg_name, 30, 96, $new_img_width, $new_img_height);
$star_info_offset = 128;
$pdf->SetFont('Arial','',8.68);
$pdf->Text($star_info_offset, 104, 'Actor Score');
$jpg_name = get_rank_image($star_rank);
$image_info = getimagesize($jpg_name);
$img_width = $image_info[0];
$img_height = $image_info[1];
$new_img_height = 6.5;
$img_ratio = ($new_img_height/$img_height);
$new_img_width = $img_width * $img_ratio;
$pdf->Image($jpg_name, $star_info_offset, 110, $new_img_width, $new_img_height);
$pdf->SetFont('Arial','',8.68);
$pdf->Text($star_info_offset, 127, $star_rank);
$pdf->SetFont('Arial','B',8.68);
$pdf->Text($star_info_offset, 154, 'Birth:');
$pdf->SetFont('Arial','',8.68);
$pdf->Text($star_info_offset, 164, $birthdate);
if ($deathdate != '') {
$pdf->SetFont('Arial','B',8.68);
$pdf->Text($star_info_offset, 184, 'Death:');
$pdf->SetFont('Arial','',8.68);
$pdf->Text($star_info_offset, 194, $deathdate);
}
$pdf->SetFont('verdanab','',8);
$pdf->Text(228, 104, 'Biography:');
$pdf->SetXY(226,108);
$pdf->SetFont('verdana','',8);
$pdf->MultiCell(170,10,$bio, 0, 'J');
return (true);
}
//************************************************************************************************************************
function print_PDF_decades ($pdf, $start_decade, $end_decade, $decade_1920, $decade_1930, $decade_1940, $decade_1950, $decade_1960, $decade_1970, $decade_1980, $decade_1990, $decade_2000, $total_count_1920, $total_count_1930, $total_count_1940, $total_count_1950, $total_count_1960, $total_count_1970, $total_count_1980, $total_count_1990, $total_count_2000) {
$decade_offset = 424;
$pdf->SetFont('Arial','B',9);
$pdf->Text($decade_offset, 108, 'CAREER SPAN');
$pdf->SetFont('verdanab','',7);
$pdf->Text($decade_offset, 118, 'Decade # Movies Movie Score');
$pdf->Line($decade_offset, 120, 582, 120);
$current_total = 0;
$current_score = 0;
for ($i = 0; $i <= 70; $i+=12) { // start decade loop, 56 * 7 rows
switch($start_decade) {
case 1920:
$current_total = $total_count_1920;
$current_score = $decade_1920;
break;
case 1930:
$current_total = $total_count_1930;
$current_score = $decade_1930;
break;
case 1940:
$current_total = $total_count_1940;
$current_score = $decade_1940;
break;
case 1950:
$current_total = $total_count_1950;
$current_score = $decade_1950;
break;
case 1960:
$current_total = $total_count_1960;
$current_score = $decade_1960;
break;
case 1970:
$current_total = $total_count_1970;
$current_score = $decade_1970;
break;
case 1980:
$current_total = $total_count_1980;
$current_score = $decade_1980;
break;
case 1990:
$current_total = $total_count_1990;
$current_score = $decade_1990;
break;
case 2000:
$current_total = $total_count_2000;
$current_score = $decade_2000;
break;
} // switch
$pdf->SetFont('verdana','',8);
if ($current_total >= 10) {
$pdf->Text($decade_offset, 132+$i, $start_decade."s..... ".$current_total." ........");
} else {
$pdf->Text($decade_offset, 132+$i, $start_decade."s..... ".$current_total." .........");
}
if (($current_total > 0) && ($current_score > 0)) {
$jpg_name = get_rank_image($current_score);
$image_info = getimagesize($jpg_name);
$img_width = $image_info[0];
$img_height = $image_info[1];
$new_img_height = 6.5;
$img_ratio = ($new_img_height/$img_height);
$new_img_width = $img_width * $img_ratio;
$pdf->Image($jpg_name, $decade_offset+87, 126+$i, $new_img_width, $new_img_height);
$pdf->Text($decade_offset+125, 132+$i, $current_score);
} else {
$pdf->Text($decade_offset+87, 132+$i, 'no reviews');
}
$start_decade = $start_decade + 10;
if ($start_decade > $end_decade) {
break;
}
} // for loop
return (true);
}
//************************************************************************************************************************
function getDecade_total_count($decade_range, $decade, $star_id, $t10) {
if ($decade == 'no reviews'){
$qry_career_decade_count = "SELECT COUNT(`year`) AS decade_count FROM movie_stars, movies, movie_status where (star_id = $star_id) and (movie_stars.movie_id = movies.id) and (movies.id = movie_status.movie_id) and (movie_status.movie_data_id >=0) and (movies.lang_id = 0) and (movies.year between ".$decade_range.") order by year";
$rst_decade_count = mysql_query($qry_career_decade_count, $t10) or die(mysql_error());
$row_decade_count = mysql_fetch_assoc($rst_decade_count);
mysql_free_result($rst_decade_count);
return (number_format($row_decade_count['decade_count']));
} elseif($decade != 'no reviews'){
$qry_career_decade_count = "SELECT COUNT(`year`) AS decade_count FROM movie_stars, movies, movie_status where (star_id = $star_id) and (movie_stars.movie_id = movies.id) and (movies.id = movie_status.movie_id) and (movie_status.movie_data_id >=0) and (movies.lang_id = 0) and (movies.year between ".$decade_range.") order by year";
$rst_decade_count = mysql_query($qry_career_decade_count, $t10) or die(mysql_error());
$row_decade_count = mysql_fetch_assoc($rst_decade_count);
mysql_free_result($rst_decade_count);
return (number_format($row_decade_count['decade_count']));
}
}
//************************************************************************************************************************
function print_PDF_movie_col ($pdf, $movie_rank, $result, $column, $t10, $totalRows_movies) {
if ($column == 1) {
$left_offset = 32;
} else {
$left_offset = 329;
}
$y_offset = 315;
// a colmun is 28 times the line point height ($i), just be under that
for ($i = 0; $i < 479; $i+=17.15) {
$movie_rank++;
$dvd_avail = false; // reset values
//print "step 1 - $column<br>";
$row_result = mysql_fetch_assoc($result);
$movie_id = $row_result['movie_id'];
$movie_name = $row_result['name'];
if (strlen($movie_name) > 28) {
$movie_name = substr($movie_name, 0, 19)."...".substr($movie_name, strlen($movie_name)-7, 7);
}
$movie_score = $row_result['ranking'];
//print "step 2 - $column<br>";
$qry_dvd = "SELECT serial_number FROM pricing where (product_id=$movie_id) AND (serial_type_id=1)";
$result_dvd = mysql_query($qry_dvd, $t10);
$totalRows_dvd = mysql_num_rows($result_dvd);
if ($totalRows_dvd > 0) {
$row_dvd = mysql_fetch_assoc($result_dvd);
$dvd_avail = true;
} else {
$dvd_avail = false;
}
mysql_free_result($result_dvd);
//print "step 3 - $column<br>";
$pdf->SetFont('verdanab','', 9);
if ($movie_rank < 10) {
$pdf->Text($left_offset, $y_offset+$i, " ".$movie_rank);
} elseif ($movie_rank < 100) {
$pdf->Text($left_offset, $y_offset+$i, " ".$movie_rank);
} else {
$pdf->Text($left_offset, $y_offset+$i, $movie_rank);
}
if ($movie_score > 0) {
$jpg_name = get_rank_image($movie_score);
$image_info = getimagesize($jpg_name);
$img_width = $image_info[0];
$img_height = $image_info[1];
$new_img_height = 6.5;
$img_ratio = ($new_img_height/$img_height);
$new_img_width = $img_width * $img_ratio;
$pdf->Image($jpg_name, $left_offset+30, $y_offset+$i-7, $new_img_width, $new_img_height);
} else {
$pdf->SetFont('verdana','', 8);
$pdf->Text($left_offset+24.8, $y_offset+$i-1, "no reviews");
}
if ($dvd_avail) {
$jpg_name = 'check_printer.jpg';
$image_info = getimagesize($jpg_name);
$img_width = $image_info[0];
$img_height = $image_info[1];
$new_img_height = 6.5;
$img_ratio = ($new_img_height/$img_height);
$new_img_width = $img_width * $img_ratio;
$pdf->Image($jpg_name, $left_offset+84, $y_offset+$i-7, $new_img_width, $new_img_height);
}
$pdf->SetFont('verdana','', 9);
$pdf->Text($left_offset+112, $y_offset+$i, $movie_name);
if ($totalRows_movies == $movie_rank) {
return (0);
}
}
return ($movie_rank);
}