1
<?php
2
/**
3
 *   File functions:
4
 *   Show game news
5
 *
6
 *   @name				 : news.php
7
 *   @copyright			: (C) 2007 Ordlin Team based on Vallheru ver 1.3
8
 *   @author			   : thindil <thindil@users.sourceforge.net>
9
 *   @author			   : eyescream <tduda@users.sourceforge.net>
10
 *   @version			  : 0.1
11
 *   @since				: 13.10.2007
12
 *
13
 */
14
15
//
16
//
17
//   This program is free software; you can redistribute it and/or modify
18
//   it under the terms of the GNU General Public License as published by
19
//   the Free Software Foundation; either version 2 of the License, or
20
//   (at your option) any later version.
21
//
22
//   This program is distributed in the hope that it will be useful,
23
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
24
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
//   GNU General Public License for more details.
26
//
27
//   You should have received a copy of the GNU General Public License
28
//   along with this program; if not, write to the Free Software
29
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
//
31
// $Id$
32
33
$title = 'Miejskie Plotki';
34
require_once('includes/head.php');
35
36
/**
37
* Get the localization for game
38
*/
39
require_once('languages/'.$player -> lang.'/news.php');
40
$db->SetFetchMode(ADODB_FETCH_NUM);
41
/**
42
* Display one news
43
*/
44
if (!isset ($_GET['view']))
45
{
46
	$upd = $db -> GetRow('SELECT `id`, `title`, `starter`, `news` FROM `news` WHERE `lang`=\''.$player -> lang.'\' AND `added`=\'Y\' AND `show`=\'Y\' ORDER BY `id` DESC');
47
	if (isset($upd[0]))
48
	{
49
		$arrQuery = $db -> GetRow('SELECT count(*) FROM `news_comments` WHERE `newsid`='.$upd[0]);
50
		$smarty -> assign(array('Title1' => $upd[1],
51
								'Starter' => $upd[2],
52
								'News' => $upd[3],
53
								'Comments' => $arrQuery[0],
54
								'Newsid' => $upd[0]));
55
	}
56
	$arrWaiting = $db -> GetRow('SELECT count(*) FROM `news` WHERE `lang`=\''.$player -> lang.'\' AND `added`=\'N\'');
57
	$arrAccepted = $db -> GetRow('SELECT count(*) FROM `news` WHERE `lang`=\''.$player -> lang.'\' AND `show`=\'N\'');
58
	$smarty -> assign(array('Accepted' => $arrAccepted[0],
59
							'Waiting' => $arrWaiting[0]));
60
}
61
else
62
{
63
/**
64
* Display last 10 news
65
*/
66
	$upd = $db -> GetAll('SELECT `id`, `title`, `starter`, `news` FROM `news` WHERE `lang`=\''.$player -> lang.'\' AND `added`=\'Y\' AND `show`=\'Y\'  ORDER BY `id` DESC LIMIT 10');
67
	for($i = 0, $max = sizeof($upd); $i < $max; ++$i)
68
	{
69
		$arrComments = $db -> GetRow('SELECT count(*) FROM `news_comments` WHERE `newsid`='.$upd[$i][0]);
70
		$upd[$i][] = $arrComments[0];
71
	}
72
	$smarty -> assign_by_ref('LastNews', $upd);
73
}
74
75
/**
76
* Comments to text
77
*/
78
if (isset($_GET['step']) && $_GET['step'] == 'comments')
79
{
80
	$smarty -> assign('Amount', '');
81
	require_once('includes/comments.php');
82
	/**
83
	* Display comments
84
	*/
85
	if (!isset($_GET['action']))
86
	{
87
		displaycomments($_GET['text'], 'news', 'news_comments', 'newsid');
88
		$smarty -> assign(array('Tauthor' => $arrAuthor,
89
								'Tbody' => $arrBody,
90
								'Amount' => $i,
91
								'Cid' => $arrId,
92
								'Tdate' => $arrDate));
93
	}
94
95
	/**
96
	* Add comment
97
	*/
98
	if (isset($_GET['action']) && $_GET['action'] == 'add')
99
	{
100
		addcomments($_POST['tid'], 'news_comments', 'newsid');
101
	}
102
103
	/**
104
	* Delete comment
105
	*/
106
	if (isset($_GET['action']) && $_GET['action'] == 'delete')
107
	{
108
		deletecomments('news_comments');
109
	}
110
}
111
112
/**
113
* Add news (simple user)
114
*/
115
if (isset($_GET['step']) && $_GET['step'] == 'add')
116
{
117
	$path = 'languages/';
118
	$dir = opendir($path);
119
	$arrLanguage = array();
120
	while ($file = readdir($dir))
121
	{
122
		if (!ereg(".htm*$", $file) && !ereg("\.$", $file))
123
		{
124
			$arrLanguage[] = $file;
125
		}
126
	}
127
	closedir($dir);
128
129
	$smarty -> assign('Llang', $arrLanguage);
130
131
	if (!empty($_POST['ttitle']) && !empty($_POST['body']))
132
	{
133
		require_once('includes/bbcode.php');
134
		$_POST['body'] = censorship($_POST['body']);
135
		$_POST['body'] = bbcodetohtml($_POST['body']);
136
		$_POST['ttitle'] = censorship($_POST['ttitle']);
137
		$strAuthor = $player -> user.' ('.$player -> id.')';
138
		$strBody = $db -> qstr($_POST['body'], get_magic_quotes_gpc());
139
		$strTitle = $db -> qstr($_POST['ttitle'], get_magic_quotes_gpc());
140
		$db -> Execute('INSERT INTO `news` (`title`, `news`, `added`, `lang`, `starter`) VALUES('.$strTitle.', '.$strBody.', \'N\', \''.$_POST['lang'].'\', \''.$strAuthor.'\')');
141
		error(YOU_ADD);
142
	}
143
}
144
145
/**
146
* Initialization of variable
147
*/
148
if (!isset($_GET['view']))
149
{
150
	$_GET['view'] = '';
151
}
152
if (!isset($_GET['step']))
153
{
154
	$_GET['step'] = '';
155
}
156
if (!isset($_GET['text']))
157
{
158
	$_GET['text'] = '';
159
}
160
161
/**
162
* Assign variables to template and display page
163
*/
164
$smarty -> assign (array('View' => $_GET['view'],
165
						 'Step' => $_GET['step'],
166
						 'Rank' => $player -> rank,
167
						 'Text' => $_GET['text']));
168
$smarty -> display ('news.tpl');
169
170
require_once('includes/foot.php');
171
?>