<?php
require "${_SERVER['DOCUMENT_ROOT']}/database.php";


$mysqli = set_mysql ('miteruzo_bbs');

$mysqli -> set_charset ('utf8');

$thread = $_GET['thread'];
$id = $_GET['id'];
$pass = $_GET['pass'];

if ($result = $mysqli -> query ("
        SELECT
          pass, image
        FROM
          responses
        WHERE
          (thread_id = {$_GET['thread']}) AND (response_id = {$_GET['id']})")):
    $row = $result -> fetch_assoc ();

    if ($_GET['pass'] == $row['pass']):
        $mysqli -> query ("
                UPDATE
                  responses
                SET
                  deleted = 1
                WHERE
                  (thread_id = $thread) AND (response_id = $id)");

        echo "消しましたぁ!!<br /><br /><img style='border: solid 1px' src='/images/{$row['image']}' />";
    else:
        echo '残念．<br />削除用パスワードが違います．';
    endif;

    echo "<br /><br />5 秒後に元のページに戻ります．<br /><br /><a href='/?thread=$thread#$id'>戻らない場合はこちら</a><script>setTimeout (function () {window.location.href = `/?thread=$thread#$id`}, 5000)</script>";
endif;

