CODE
<?
ob_start();
session_start();
define('INSIDE', true);
include 'includes/header.php';
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
include 'includes/function.php';
switch($a){
case "comment":
if($_SESSION['zalogowany'] != 1){
message('Nie jeste¶ zalogowany.');
header("Refresh:3;video.php?video=$_GET[video]");
}
if(strlen($_POST['text']) > $max_comment){
message('Opis posiada za dużo znaków');
header("Refresh:3;video.php?video=$_GET[video]");
}elseif(ereg('[^a-zA-Z0-9:

message('Komentarz posiada niedozwolone znaki.');
header("Refresh:3;video.php?video=$_GET[video]");
}elseif(!$_POST['text']){
message('Musisz uzupełnić wszystkie pola');
header("Refresh:3;video.php?video=$_GET[video]");
}else{
$add = "INSERT INTO comments (text, add_by, add_date, v_id) VALUES ('$_POST[text]', '$_SESSION[login]', '$date', '$_GET[video]')";
$go = $db->query($add);
message('Komentarz dodany.');
header("Refresh:3;video.php?video=$_GET[video]");
}
break;
case "bad":
$select = "SELECT * FROM bad_video WHERE v_id = '$_GET[id]'";
$go_select = $db->query($select);
$wynik = $db->num($go_select);
if($_SESSION['zalogowany'] != 1){
message('Nie jeste¶ zalogowany.');
}elseif($wynik != 0){
message('Kto¶ już zgłosił ten film.');
}else{
$update = "INSERT INTO bad_video (v_id, add_by, add_time) VALUES ('$_GET[id]', '$_SESSION[login]', '$date')";
$goupdate = $db->query($update);
message('Dziękujemy za zgłoszenie filmu.');
header("Refresh:3;video.php?video=$_GET[id]");
}
break;
case "vote":
$s = $_GET['video'];
$v = $_POST['vote'];
if($v > 10){
$v = '10';
}
if($_COOKIE[vote][$s] == $s){
message('Głosowałe¶ już na ten film.');
header("Refresh:3;video.php?video=$s");
}else{
$vote="UPDATE video SET points=points+$v, glosowalo=glosowalo+1 WHERE id='$s'";
$query = $db->query($vote);
$wygasniecie = time() + (60 * 60 * 24);
setCookie ("vote[$s]", "".$s."",$wygasniecie);
message('Dziękujemy za głos.');
header("Refresh:3;video.php?video=$s");
}
break;
default:
$select = "SELECT * FROM video WHERE id = '$_GET[video]'";
$goselect = $db->query($select);
$wynik = $db->num($goselect);
if($wynik == 0){
message('Film o podanym ID nie istnieje.');
}else{
while($video = $db->fetch($goselect)){
if($video['points'] == 0){
$points = 0;
}else{
$points = $video['points']/$video['glosowalo'];
}
$smarty->assign(array(
"v_id" => $video['id'],
"v_name" => $video['name'],
"v_category" => $video['category'],
"v_date" => $video['add_date'],
"v_description" => $video['description'],
"v_add_by" => $video['add_by'],
"v_points" => $points,
"v_tags" => $video['tags'],
"v_home_site" => $video['home_site'],
"v_img" => $video['img'],
"v_looked" => $video['looked'],
"v_video" => $video['video']));
}//while
// komentarze
if (!$_GET['limit']) $_GET['limit'] = 0;
$comments = "SELECT * FROM comments WHERE v_id = '$_GET[video]' ORDER BY add_date DESC LIMIT $_GET[limit],$max_on_video";
$go = $db->query($comments);
$comm = $db->num($go);
if($comm == 0){
$smarty->assign("comment", 'Nikt jeszcze nie skomentował tego filmu');
}
$i = 0;
while($comment= $db->fetch($go)){
$com_name[$i] = $comment['name'];
$com_date[$i] = $comment['add_date'];
$com_by[$i] = $comment['add_by'];
$com_text[$i] = $comment['text'];
$i++;
}
$smarty->assign(array(
"com_name" => $com_name,
"com_date" => $com_date,
"com_text" => $com_text,
"com_by" => $com_by));
$com = mysql_num_rows(mysql_query("SELECT id FROM comments WHERE v_id = '$_GET[video]'"));
if ($com > $max_on_video && ($_GET['limit']+$max_on_video) < $com)
$smarty -> assign("dalej", "<a href=video.php?video=".$_GET['video']."&limit=".($_GET['limit']+$max_on_video).">Następne ".$max_on_video." komentarzy</a>");
if ($_GET['limit'] >= $max_on_video)
$smarty -> assign("wstecz", "<a href=video.php?video=".$_GET['video']."&limit=".($_GET['limit']-$max_on_video).">Poprzednie ".$max_on_video." komentarzy</a>");
//Dodaje wy¶wietlenie
$update = "UPDATE video SET looked=looked+1 WHERE id = '$_GET[video]'";
$goupdate = $db->query($update);
}
break;
}
$smarty->assign(array('a' => $_GET['a'],
'video' => $_GET['video']
));
$smarty->display("video.tpl");
include "includes/footer.php";
?>