<?php
/*
 * JohnCMS NEXT Mobile Content Management System (http://johncms.com)
 *
 * For copyright and license information, please see the LICENSE.md
 * Installing the system or redistributions of files must retain the above copyright notice.
 *
 * @link        http://johncms.com JohnCMS Project
 * @copyright   Copyright (C) JohnCMS Community
 * @license     GPL-3
 */

define('_IN_JOHNCMS', 1);

require('../system/bootstrap.php');

/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();

/** @var Johncms\Api\UserInterface $systemUser */
$systemUser = $container->get(Johncms\Api\UserInterface::class);

/** @var Johncms\Api\BbcodeInterface $bbcode */
$bbcode = $container->get(Johncms\Api\BbcodeInterface::class);


/** @var Johncms\Api\ToolsInterface $tools */
$tools = $container->get(Johncms\Api\ToolsInterface::class);

/** @var Johncms\Api\ConfigInterface $config */
$config = $container->get(Johncms\Api\ConfigInterface::class);

/** @var Zend\I18n\Translator\Translator $translator */
$translator = $container->get(Zend\I18n\Translator\Translator::class);
$translator->addTranslationFilePattern('gettext', __DIR__ . '/locale', '/%s/default.mo');

$textl = _t('Quoted Messages');
$headmod = 'forum_quotes';
require('../system/head.php');

if (!$systemUser->isValid()) {
    echo 'You are not logged in';
    require ('../system/end.php');
    exit;
}
// Mod. Thanks
$checkthankdau = $db->query('SELECT COUNT(*) FROM `forum_thank` WHERE `userthank` = "' . $systemUser->id . '" and `topic` = "' . $_GET['thanks'] . '" and `user` = "' . $_GET['user'] . '"');
if ($systemUser->isValid() && $systemUser->id != $_GET['user'] && ($checkthankdau->fetchColumn() < 1)) {
if (isset($_GET['thank']) && isset($_GET['user']) && isset($_GET['thanks'])) {
echo '<div class="rmenu" id="thankyou">Your thanks has been received..!!</div>';
$db->exec("INSERT INTO `forum_thank` SET
`user` = '".trim($_GET['user'])."',
`topic` = '".trim($_GET['thanks'])."' ,
`time` = '$realtime',
`userthank` = '$systemUser->id',
`chude` = '".$_GET['id']."'
");
$congcamon = $db->query('SELECT * FROM `users` WHERE `id` = "' . trim($_GET['user']) . '"')->fetch();
$db-exec("UPDATE `users` SET `thank_duoc`='" . ($congcamon['thank_duoc'] + 1) . "' WHERE `id` = '" . trim($_GET['user']) . "'");
$db-exec("UPDATE `users` SET `thank_duoc`='" . ($congcamon['thank_duoc'] + 1) . "' WHERE `id` = '" . trim($_GET['user']) . "'");
$db-exec("UPDATE `users` SET `thank_di`='" . ($systemUser->thank_di + 1) . "' WHERE `id` = '" . $systemUser->id . "'");
}
}
echo '<div class="mainblok"><div class="phdr"><b>Forum Notification</b></div>';
$total = $db->query("SELECT COUNT(*) FROM `forum` WHERE `id_user`='$systemUser->id'" .
    ($systemUser->rights >= 7 ? "" : " AND `close` != '1'"))->fetchColumn();
if ($total > $kmess)
echo '<div class="topmenu">' . $tools->displayPagination('journal.php?', $start, $total, $kmess) . '</div>';
if ($systemUser->journal_forum) {
echo '<div class="gmenu">Post Quoted: ' . $systemUser->journal_forum . '</div>';
$db->exec("UPDATE `users` SET `journal_forum`='0' WHERE `id` = '$systemUser->id'");
}
echo '</div>';

if ($total) {
    $req = $db->query("SELECT `forum`.*, `users`.`sex`, `users`.`rights`, `users`.`lastdate`, `users`.`status`, `users`.`datereg`
     	FROM `forum` LEFT JOIN `users` ON `forum`.`user_id` = `users`.`id`
      	WHERE `forum`.`type` = 'm' AND `forum`.`id_user`='$systemUser->id'" . ($systemUser->rights >=
        7 ? "" : " AND `forum`.`close` != '1'") . " ORDER BY `forum`.`id` DESC LIMIT $start, $kmess");
    while (($res = $req->fetch()) !== false) {
    	if ($res['close'])
        	echo '<div class="orange">';
				else
				echo $i % 2 ? '<div class="mainblok">' : '<div class="mainblok">';
        $theme = $db->query("SELECT `text` FROM `forum` WHERE `id` = '" . $res['refid'] . "' ORDER BY `id` ASC LIMIT 1")->fetch();
       ###
echo '<div class="phdr"><table width="100%" cellpadding="0" cellspacing="0">';
echo '<tr><td width="auto"><b>My Mentions</td>' .
'<td width="auto" align="right"><a href="../forum/index.php?act=post&amp;id=' . $res['id'] . '">View</a></td></tr></table></div>';
echo '<div class="textshout">';

        echo '<b>Quoted by: <a href="profile.php?user=' . $res['user_id'] . '">' . $res['from'] . '</a></b><br/>';
        echo '<b>Topic of Quote: <a href="../forum/index.php?id=' . $res['refid'] . '">' . $theme['text'] . '</a></b>';
        echo '<br/><b>Time Quoted: </b><b>' . date("d.m.Y / g:i:s a", $res['time'] + $config['timeshift'] * 3600) . '</b>';
         echo '<br/><font color="green">Message Quoted:</font><br/>';
					$text = htmlentities($res['text'], ENT_QUOTES, 'UTF-8');
					$text = nl2br($text);
					$text = $bbcode->tags($text);
					$text = $tools->smilies($text, ($res['rights'] >= 1) ? 1 : 0);
        $text = $tools->checkout($res['text'], 1, 1);
        if(mb_strlen($res['text']) > 50)
           $text .= ' ...';
        if ($res['kedit'])
            $text .= '<br /><small>Edited <b>' . $res['edit'] . '</b> (' . date("d.m /H:i", $res['tedit'] + $config['timeshift'] * 3600) . ') <b>[' . $res['kedit'] . ']</b></small>';
    	      echo $text;
					echo '<br/><br/>';
            echo '<td width="auto" align="right"><a href="../forum/index.php?act=post&amp;id=' . $res['id'] . '">Read All</a></td>';
echo '</div><div class="forumb">';
echo '<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="left" valign="">';
$checkthank = $db->query('SELECT COUNT(*) FROM `forum_thank` WHERE `userthank` = "' . $systemUser->id . '" and `topic` = "' . $res['id'] . '" and `user` = "' . $res['user_id'] . '"')->fetchColumn();
if ($systemUser->isValid() && $systemUser->id != $res['user_id'] && ($checkthank < 1)) {
echo '<a href="index.php?id=' . $id . '&amp;thanks=' . $res['id'] . '&amp;user=' . $res['user_id'] . '&amp;start=' . $start . '&amp;thank#thankyou"><img src="../images/thanks.gif" width="55" height="16" alt="thanx"/></a>&#160;';
}
echo '</td><td width="auto" align="right" valign="">';
echo '<a href="../forum/index.php?act=say&amp;id=' . $res['id'] . '&amp;cyt"><img src="../images/quote.gif" width="55" height="16" alt="' . _t('Quote Button') . '" /></a>';
echo '</td></tr></table></div>';
echo '</div>';
++$i;
    }
} else
	echo '<div class="menu"><p>Empty Quoted Messages!</p></div>';

echo '<div class="mainblok"><div class="phdr">Total quoted: ' . $total . '</div>';
if ($total > $kmess) {
echo '<div class="topmenu">' . $tools->displayPagination('journal.php?', $start, $total, $kmess) . '<br>' .
'<form action="index.php" method="get"><input type="text" name="page" size="2"/>' .
'<input type="submit" value="' . _t('Go to page') . ' &gt;&gt;"/></form></div>';
}
echo '<div class="phdr"><a href="' . $config->homeurl . '/profile/?act=office">Back</a></div>';
echo '</div>';
require_once('../system/end.php');
?>