<?php 

if (isset($_GET['delete']) && isset($_GET['success'])) {
  if (isset($_SESSION['token']) && $_SESSION['token'] == $_GET['success']) {
  	mysql_query("DELETE FROM `treats` WHERE `id` = '" . (int) $_GET['delete'] . "' AND `id_send` = '$user[id]' LIMIT 1");
  	$_SESSION['message'] = __('Действие успешно удалено');
  	header('Location: ?func=user');
  	exit;
  }
}

unset($err);
$_SESSION['token'] = mt_rand(1, 999);
moduleHeader($config['title_user'][$from]);

?>
<div class="foot">
  <a href="<?= $config['return'][$from]?>"><img src="/<?= $config['icons_patch']?>/arrow-180.png" /> <?= $config['return_name'][$from]?></a><br />
</div>
<?
if (isset($user) && $user['id'] != $anketa['id']) { 
  ?>
  <div class="foot">
    <a href="?func=category">
      <img src="/<?= $config['icons_patch']?>/cake.png" /> <?= __('Сделать действие')?>
    </a>
  </div>
  <? 
}

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `treats` WHERE `id_send` = '$anketa[id]' AND `type` = '$from'"),0);

if ($k_post == 0) {
  ?>
  <div class="mess"><?= __('Действий еще никто не делал')?></div>
  <?
}
else 
{
  $k_page = k_page($k_post, $set['p_str']);
  $page = page($k_page);
  $start = $set['p_str'] * $page - $set['p_str'];

  $q = mysql_query("SELECT *
                    FROM `treats` 
                    WHERE `id_send` = '$anketa[id]' AND `type` = '$from' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

  while($post = mysql_fetch_assoc($q)) 
  {
    ?>
    <div class="nav<?= ($num % 2 ? 1 : 2)?>">
      <?= user::avatar($post['id_user'], 2) . user::nick($post['id_user'], 1, 1, 1)?> (<?= vremja($post['time'])?>) <br />
      <?= output_text($post['msg'])?> 
      <? if (isset($user) && $anketa['id'] == $user['id']) { ?>
        <a href="?func=user&amp;delete=<?= $post['id']?>&amp;success=<?= $_SESSION['token']?>"><img src="/style/icons/delete.gif" alt="*"></a>
      <? } ?>
    </div>
    <?
  }
  unset($q, $post);

  if ($k_page > 1) { 
    str('?func=category&amp;id=' . $category['id'] . '&amp;', $k_page, $page);
  }  
}
?>
<div class="foot">
  <a href="<?= $config['return'][$from]?>"><img src="/<?= $config['icons_patch']?>/arrow-180.png" /> <?= $config['return_name'][$from]?></a><br />
</div>