<?php

include_once '../../sys/inc/home.php';
include_once H . 'sys/inc/start.php';
include_once H . 'sys/inc/compress.php';
include_once H . 'sys/inc/sess.php';
include_once H . 'sys/inc/settings.php';
include_once H . 'sys/inc/db_connect.php';
include_once H . 'sys/inc/ipua.php';
include_once H . 'sys/inc/fnc.php';
include_once H . 'sys/inc/user.php';


if (isset($_GET['id']))
    $public['id'] = intval($_GET['id']);
$public = mysql_fetch_array(mysql_query("SELECT * FROM `public` WHERE `id` = '" . $public['id'] . ")'"));
if ($public['id'] == intval($_GET['id'])) {


    if (isset($_POST['mess']) && $_POST['mess'] != "" && $_POST['mess'] != " " && $_POST['us']) {
        //Принимаем переменные
        $us = intval($_POST['us']);
        $mess = $_POST['mess'];
        $ank = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '" . $us . ")'"));
        //Добавляем все в таблицу
        if (isset($user) && $user['id'] == $public['id_user']) {
            mysql_query("INSERT INTO `wall` (`id_public`, `link`, `ras`, `name`, `opis`, `id_ank`) values('" . $public['id'] . "', '" . $ID_FILE . "', '" . $ras . "', '" . $public['name'] . "', '" . $msg . "', '" . $us . "')");
        } else {
            mysql_query("INSERT INTO `wall` (`id_public`, `link`, `ras`, `name`, `opis`, `id_ank`) values('" . $public['id'] . "', '" . $ID_FILE . "', '" . $ras . "', '" . $ank['nick'] . "', '" . $msg . "', '" . $us . "')");
            $upub = mysql_fetch_array(mysql_query("SELECT * FROM `public_coint` WHERE `id_user` = '" . $us . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1"));
            mysql_query("UPDATE `public_coint` SET `aktiv` = '" . ($upub['aktiv'] + 1) . "' WHERE `id_user` = '" . $us . "' AND `id_public` = '" . $public['id'] . "' LIMIT 1");
            $sss = mysql_query("SELECT * FROM `public_coint` WHERE `id_public` = '" . $public['id'] . "'");
            while ($podpiska = mysql_fetch_array($sss)) {
                $us_pub = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '" . $podpiska['id_user'] . "' LIMIT 1"));
                mysql_query("INSERT INTO `wall` (`id_wall`, `name`, `opis`, `id_pub`) values('" . $us_pub['id'] . "', '[url=/user/public/index.php?id=" . $public['id'] . "]" . $public['name'] . "[/url]', '" . $msg . "', '" . $public['id'] . "')");
            }
        }


        exit;
    }
} else {
    exit;
}
?>