12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- require_once('include/config.php');
- require_once('include/db.php');
- require_once('include/comment.php');
- switch (@$_POST['mode']) {
- case 'json':
- $mode = 'json';
- break;
- default:
- $mode = 'html';
- break;
- }
- function store_comment() {
- $nick = @$_POST['comment-nick'];
- $email = @$_POST['comment-email'];
- $type = @$_POST['comment-type'];
- $id = @$_POST['comment-id'];
- $content = @$_POST['comment-content'];
- if (empty($nick) || strlen($nick) === 0) {
- throw new Exception('Nie podano nicka');
- }
- if (empty($type) || strlen($type) === 0 || empty($id) || strlen($id) === 0) {
- throw new Exception('Niepoprawne żądanie');
- }
- if (empty($content) || strlen($content) === 0) {
- throw new Exception('Nie wpisano treści');
- }
- db_store_comment($nick, $email, $type, $id, $content);
- return 'OK';
- }
- try {
- $res = store_comment();
- if ($mode == 'html') {
- $output = $res;
- } else {
- $output = array('result' => $res);
- }
- } catch (Exception $e) {
- if ($mode == 'html') {
- $output = 'Błąd: ' . $e->getMessage();
- } else {
- $output = array('result' => 'error', 'error' => $e->getMessage());
- }
- }
- if ($mode == 'json') {
- header('Content-Type: application/json; charset=utf-8');
- echo json_encode($output);
- die();
- }
- ?><!DOCTYPE html>
- <html>
- <head>
- <title>Obrazki: komentarz</title>
- <link rel="stylesheet" href="style.css?<?=$time?>" type="text/css">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- </head>
- <body>
- <?=$output?><br>
- <a href="javascript:history.back()">Powrót</a>
- </body>
- </html>
|