$id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } $comments = []; while($row = $res->fetch(PDO::FETCH_ASSOC)) { $comments[] = $row; } return $comments; } function count_comments($id, $type) { global $pdo; $sql = 'SELECT count(*) AS count FROM comments WHERE ' . get_field_name($type) . ' = :id'; $values = array( ':id' => $id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } if($row = $res->fetch(PDO::FETCH_ASSOC)) { return $row['count']; } return 0; } function count_comments_all_dir_images($id) { global $pdo; $sql = 'SELECT count(*) AS count FROM comments WHERE image IN (SELECT id FROM images WHERE dir = :dir)'; $values = array( ':dir' => $id, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } if($row = $res->fetch(PDO::FETCH_ASSOC)) { return $row['count']; } return 0; } function db_store_comment($nick, $email, $type, $id, $content) { global $pdo; $sql = 'INSERT INTO comments (ip, ' . get_field_name($type) . ', email, author, date, content) VALUES (:ip, :id, :email, :nick, :date, :content)'; $values = array ( ':ip' => $_SERVER['REMOTE_ADDR'], ':id' => $id, ':email' => $email, ':nick' => $nick, ':date' => time(), ':content' => $content, ); try { $res = $pdo->prepare($sql); $res->execute($values); } catch (PDOException $e) { echo 'Query error: ' . $e->getMessage(); die(); } } function generate_comment_field($comments, $type, $id) { $emptytexts = array( 'dir' => 'Brak komentarzy do tego katalogu, możesz być pierwszy!', 'image' => 'Brak komentarzy do tego obrazka, możesz być pierwszy!', ); $headertexts = array( 'dir' => 'Komentarze do katalogu', 'image' => 'Komentarze do obrazka', ); if (count($comments) == 0) { $output = '

' . $emptytexts[$type] . '

'; } else { $output = '

' . $headertexts[$type] . '

'; } foreach ($comments as $comment) { $output .= '
Autor: ' . htmlspecialchars($comment['author']) . ', data: ' . date('j.m.Y G:i:s', $comment['date']) . '
' . htmlspecialchars($comment['content']) . '
'; } $output .= '

Dodaj nowy komentarz

'; $output .= ''; $output .= '
Autor:
E-mail (nie pokażę go nikomu):
'; $output .= ''; $output .= '
'; return $output; } ?>