<?php
function calculate_differences($takings, $cost) {
$difference = $takings - $cost;
if ($difference < 0) {
$difference = substr($difference, 1
); $font_color = 'red';
$profit_or_loss = "$" . $difference . "m";
} elseif ($difference > 0) {
$font_color ='green';
$profit_or_loss = "$" . $difference . "m";
} else {
$font_color = 'blue';
$profit_or_loss = "Równowaga";
}
return "<font color="$font_color">" . $profit_or_loss . "</font>";
}
function get_director() {
$query_d = "SELECT people_fullname
FROM people
WHERE people_id='$movie_director'";
$director = $people_fullname;
}
function get_leadactor() {
$query_a = "SELECT people_fullname
FROM people
WHERE people_id='$movie_leadactor'";
$leadactor = $people_fullname;
}
$movie_query = "SELECT * FROM movie
WHERE movie_id ='" . $_GET['movie_id'] . "'";
$movie_table_headings=<<<EOD
<tr>
<th>Tytuł filmu</th>
<th>Rok produkcji</th>
<th>Reżyser</th>
<th>Główny aktor</th>
<th>Czas trwania</th>
<th>Zysk lub strata</th>
</tr>
EOD;
$review_table_headings=<<<EOD
<tr>
<th>Data wystawienia</th>
<th>Tytuł recenzji</th>
<th>Recenzent</th>
<th>Treść recenzji</th>
<th>Ocena</th>
</tr>
EOD;
$review_query = "SELECT * FROM reviews
WHERE review_movie_id ='" . $_GET['movie_id'] . "'
ORDER BY review_date DESC";
$review_flag =1;
$review_title[] = $review_row['review_name'];
$reviewer_name[] = ucwords($review_row['review_reviewer_name']); $review[] = $review_row['review_comment'];
$review_date[] = $review_row['review_date'];
$review_rating[] = generate_ratings($review_row['review_rating']);
}
$i = 0;
$review_details = '';
while ($i<sizeof($review)) {
$review_details .=<<<EOD
<tr>
<td width="15%" valign="top" align="center">$review_date[$i]</td>
<td width="15%" valign="top">$review_title[$i]</td>
<td width="10%" valign="top">$reviewer_name[$i]</td>
<td width="50%" valign="top">$review[$i]</td>
<td width="10%" valign="top" align="center">$review_rating[$i]</td>
</tr>
EOD;
$i++;
}
$movie_name = $row['movie_name'];
$movie_director = $row['movie_director'];
$movie_leadactor = $row['movie_leadactor'];
$movie_year = $row['movie_year'];
$movie_running_time = $row['movie_running_time']." min.";
$movie_takings = $row['movie_takings'];
$movie_cost = $row['movie_cost'];
get_director();
get_leadactor();
}
$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =<<<EOD
<html>
<head>
<title>Szczegóły i recenzja dla: $movie_name</title>
</head>
<body>
EOD;
$movie_details =<<<EOD
<table width="70%" border="0" cellspacing="2"
cellpadding="2" align="center">
<tr>
<th colspan="6"><u><h2>$movie_name: szczegóły</h2></u></th>
</tr>
$movie_table_headings
<tr>
<td width="33%" align="center">$movie_name</td>
<td align="center">$movie_year</td>
<td align="center">$director</td>
<td align="center">$leadactor</td>
<td align="center">$movie_running_time</td>
<td>$movie_health</td>
</tr>
</table>
<br>
<br>
EOD;
if ($review_flag) {
$movie_details .=<<<EOD
<table width="95%" border="0" cellspacing="2"
cellpadding="20" align="center">
$review_table_headings
$review_details
</table>
EOD;
}
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
$page_start
$movie_details
$page_end
EOD;
echo $detailed_movie_info;
function generate_ratings($review_rating) {
$movie_rating = '';
for($i=0; $i<$review_rating; $i++) {
$movie_rating .= "<img src="thumbsup.gif"> ";
}
return $movie_rating;
}
?>