| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Polls in game |
| 5 |
* |
| 6 |
* @name : polls.php |
| 7 |
* @copyright : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @version : 1.1 |
| 10 |
* @since : 10.03.2006 |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
// |
| 15 |
// |
| 16 |
// This program is free software; you can redistribute it and/or modify |
| 17 |
// it under the terms of the GNU General Public License as published by |
| 18 |
// the Free Software Foundation; either version 2 of the License, or |
| 19 |
// (at your option) any later version. |
| 20 |
// |
| 21 |
// This program is distributed in the hope that it will be useful, |
| 22 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
// GNU General Public License for more details. |
| 25 |
// |
| 26 |
// You should have received a copy of the GNU General Public License |
| 27 |
// along with this program; if not, write to the Free Software |
| 28 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
// |
| 30 |
// $Id: polls.php 54 2006-03-14 19:42:02Z thindil $ |
| 31 |
|
| 32 |
$title = "Hala zgromadzeĆ"; |
| 33 |
require_once("includes/head.php"); |
| 34 |
|
| 35 |
/** |
| 36 |
* Get the localization for game |
| 37 |
*/ |
| 38 |
require_once("languages/".$player -> lang."/polls.php"); |
| 39 |
|
| 40 |
if ($player -> location != 'Altara' && $player -> location != 'Ardulith') |
| 41 |
{ |
| 42 |
error (ERROR); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Select active poll |
| 47 |
*/ |
| 48 |
$objPollid = $db -> Execute("SELECT `id` FROM `polls` WHERE `lang`='".$player -> lang."' ORDER BY `id` DESC"); |
| 49 |
|
| 50 |
/** |
| 51 |
* Show active poll |
| 52 |
*/ |
| 53 |
if (!isset($_GET['action'])) |
| 54 |
{ |
| 55 |
if (!$objPollid -> fields['id']) |
| 56 |
{ |
| 57 |
$smarty -> assign("Pollid", 0); |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
$objPoll = $db -> Execute("SELECT `poll`, `votes`, `days`, `members` FROM `polls` WHERE `id`=".$objPollid -> fields['id']); |
| 62 |
$arrPoll = array(); |
| 63 |
$arrVotes = array(); |
| 64 |
$intVotes = 0; |
| 65 |
$i = 0; |
| 66 |
$isAnyAnswer = false; |
| 67 |
while (!$objPoll -> EOF) |
| 68 |
{ |
| 69 |
if ($objPoll -> fields['votes'] < 0) |
| 70 |
{ |
| 71 |
$strQuestion = $objPoll -> fields['poll']; |
| 72 |
$intDays = $objPoll -> fields['days']; |
| 73 |
$intMembers = $objPoll -> fields['members']; |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
$arrPoll[$i] = $objPoll -> fields['poll']; |
| 78 |
$arrVotes[$i] = $objPoll -> fields['votes']; |
| 79 |
$intVotes = $intVotes + $objPoll -> fields['votes']; |
| 80 |
$i++ ; |
| 81 |
$isAnyAnswer = true; |
| 82 |
} |
| 83 |
$objPoll -> MoveNext(); |
| 84 |
} |
| 85 |
/** |
| 86 |
* Count percent for each option |
| 87 |
*/ |
| 88 |
$arrPercentvotes = array(); |
| 89 |
$i = 0; |
| 90 |
foreach ($arrVotes as $intVote) |
| 91 |
{ |
| 92 |
if ($intVote && $intVotes) |
| 93 |
{ |
| 94 |
$arrPercentvotes[$i] = ($intVote / $intVotes) * 100; |
| 95 |
$arrPercentvotes[$i] = round($arrPercentvotes[$i]); |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
$arrPercentvotes[$i] = 0; |
| 100 |
} |
| 101 |
$i++ ; |
| 102 |
} |
| 103 |
/** |
| 104 |
* Count percent for voting players |
| 105 |
*/ |
| 106 |
if ($intDays) |
| 107 |
{ |
| 108 |
$objQuery = $db -> Execute("SELECT count(*) FROM `players`"); |
| 109 |
$intMembers = $objQuery -> fields['count(*)']; |
| 110 |
$objQuery -> Close(); |
| 111 |
$fltVoting = ($intVotes / $intMembers) * 100; |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
$fltVoting = ($intVotes / $intMembers) * 100; |
| 116 |
} |
| 117 |
$fltVoting = round($fltVoting, 2); |
| 118 |
/** |
| 119 |
* Check for aviable for voting |
| 120 |
*/ |
| 121 |
if ($intDays) |
| 122 |
{ |
| 123 |
$strVoting = 'Y'; |
| 124 |
} |
| 125 |
else |
| 126 |
{ |
| 127 |
$strVoting = 'N'; |
| 128 |
} |
| 129 |
if ($player -> poll == 'N' && $strVoting == 'Y') |
| 130 |
{ |
| 131 |
$strVoting = 'Y'; |
| 132 |
} |
| 133 |
else |
| 134 |
{ |
| 135 |
$strVoting = 'N'; |
| 136 |
} |
| 137 |
$objPoll -> Close(); |
| 138 |
/** |
| 139 |
* Check amount of comments to poll |
| 140 |
*/ |
| 141 |
$objComments = $db -> Execute("SELECT count(*) FROM `polls_comments` WHERE `pollid`=".$objPollid -> fields['id']); |
| 142 |
$intComments = $objComments -> fields['count(*)']; |
| 143 |
$objComments -> Close(); |
| 144 |
$smarty -> assign(array("Pollid" => $objPollid -> fields['id'], |
| 145 |
"Question" => $strQuestion, |
| 146 |
"Answers" => $arrPoll, |
| 147 |
"isAnyAnswer" => $isAnyAnswer, |
| 148 |
"Voting" => $strVoting, |
| 149 |
"Votes" => $arrVotes, |
| 150 |
"Summaryvotes" => $intVotes, |
| 151 |
"Percentvotes" => $arrPercentvotes, |
| 152 |
"Summaryvoting" => $fltVoting, |
| 153 |
"Commentsamount" => $intComments, |
| 154 |
"Acomments" => A_COMMENTS, |
| 155 |
"Days" => $intDays)); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Vote in poll |
| 161 |
*/ |
| 162 |
if (isset($_GET['action']) && $_GET['action'] == 'vote') |
| 163 |
{ |
| 164 |
if (!isset($_POST['answer'])) |
| 165 |
{ |
| 166 |
error(ERROR); |
| 167 |
} |
| 168 |
if (!ereg("^[1-9][0-9]*$", $_GET['poll']) || $_GET['poll'] != $objPollid -> fields['id']) |
| 169 |
{ |
| 170 |
error(ERROR); |
| 171 |
} |
| 172 |
if ($player -> poll == 'Y') |
| 173 |
{ |
| 174 |
error(ERROR); |
| 175 |
} |
| 176 |
$strAnswer = $db -> qstr($_POST['answer'], get_magic_quotes_gpc()); |
| 177 |
$db -> Execute("UPDATE `polls` SET `votes`=`votes`+1 WHERE `id`=".$_GET['poll']." AND `poll`=".$strAnswer); |
| 178 |
$db -> Execute("UPDATE `players` SET `poll`='Y' WHERE `id`=".$player -> id); |
| 179 |
$smarty -> assign("Message", VOTE_SUCC); |
| 180 |
} |
| 181 |
|
| 182 |
$objPollid -> Close(); |
| 183 |
|
| 184 |
/** |
| 185 |
* Show last 10 polls |
| 186 |
*/ |
| 187 |
if (isset($_GET['action']) && $_GET['action'] == 'last') |
| 188 |
{ |
| 189 |
$objPollsid = $db -> SelectLimit("SELECT `id` FROM `polls` WHERE `lang`='".$player -> lang."' AND `votes`=-1 ORDER BY `id` DESC", 10) or $db -> ErrorMsg(); |
| 190 |
$arrQuestions = array(); |
| 191 |
$arrPolls = array(array()); |
| 192 |
$arrVotes = array(array()); |
| 193 |
$arrSumvotes = array(); |
| 194 |
$arrPercentvotes = array(array()); |
| 195 |
$arrPercentmembers = array(); |
| 196 |
$arrPercentvoting = array(); |
| 197 |
$arrCommenst = array(); |
| 198 |
$arrPollid = array(); |
| 199 |
$i = 0; |
| 200 |
while (!$objPollsid -> EOF) |
| 201 |
{ |
| 202 |
$j = 0; |
| 203 |
$objPoll = $db -> Execute("SELECT `poll`, `votes`, `members` FROM `polls` WHERE `id`=".$objPollsid -> fields['id']); |
| 204 |
while (!$objPoll -> EOF) |
| 205 |
{ |
| 206 |
if ($objPoll -> fields['votes'] < 0) |
| 207 |
{ |
| 208 |
$arrQuestions[$i] = $objPoll -> fields['poll']; |
| 209 |
$arrSumvotes[$i] = 0; |
| 210 |
if ($objPoll -> fields['members']) |
| 211 |
{ |
| 212 |
$intMembers = $objPoll -> fields['members']; |
| 213 |
} |
| 214 |
else |
| 215 |
{ |
| 216 |
$objQuery = $db -> Execute("SELECT count(*) FROM `players`"); |
| 217 |
$intMembers = $objQuery -> fields['count(*)']; |
| 218 |
$objQuery -> Close(); |
| 219 |
} |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
$arrPolls[$i][$j] = $objPoll -> fields['poll']; |
| 224 |
$arrVotes[$i][$j] = $objPoll -> fields['votes']; |
| 225 |
$arrSumvotes[$i] = $arrSumvotes[$i] + $objPoll -> fields['votes']; |
| 226 |
$j++ ; |
| 227 |
} |
| 228 |
$objPoll -> MoveNext(); |
| 229 |
} |
| 230 |
$objPoll -> Close(); |
| 231 |
/** |
| 232 |
* Count percent for each option |
| 233 |
*/ |
| 234 |
$j = 0; |
| 235 |
foreach ($arrVotes[$i] as $intVote) |
| 236 |
{ |
| 237 |
if ($intVote && $arrSumvotes[$i]) |
| 238 |
{ |
| 239 |
$arrPercentvotes[$i][$j] = ($intVote / $arrSumvotes[$i]) * 100; |
| 240 |
$arrPercentvotes[$i][$j] = round($arrPercentvotes[$i][$j]); |
| 241 |
} |
| 242 |
else |
| 243 |
{ |
| 244 |
$arrPercentvotes[$i][$j] = 0; |
| 245 |
} |
| 246 |
$j++ ; |
| 247 |
} |
| 248 |
/** |
| 249 |
* Count percent for voting players |
| 250 |
*/ |
| 251 |
if ($arrSumvotes[$i] && $intMembers) |
| 252 |
{ |
| 253 |
$arrPercentvoting[$i] = ($arrSumvotes[$i] / $intMembers) * 100; |
| 254 |
$arrPercentvoting[$i] = round($arrPercentvoting[$i], 2); |
| 255 |
} |
| 256 |
else |
| 257 |
{ |
| 258 |
$arrPercentvoting[$i] = 0; |
| 259 |
} |
| 260 |
/** |
| 261 |
* Count comments to poll |
| 262 |
*/ |
| 263 |
$objComments = $db -> Execute("SELECT count(*) FROM `polls_comments` WHERE `pollid`=".$objPollsid -> fields['id']); |
| 264 |
$arrComments[$i] = $objComments -> fields['count(*)']; |
| 265 |
$objComments -> Close(); |
| 266 |
$arrPollid[$i] = $objPollsid -> fields['id']; |
| 267 |
$i++ ; |
| 268 |
$objPollsid -> MoveNext(); |
| 269 |
} |
| 270 |
$smarty -> assign(array("Questions" => $arrQuestions, |
| 271 |
"Answers" => $arrPolls, |
| 272 |
"Votes" => $arrVotes, |
| 273 |
"Lastinfo" => LAST_INFO, |
| 274 |
"Summaryvotes" => $arrSumvotes, |
| 275 |
"Percentvotes" => $arrPercentvotes, |
| 276 |
"Commentsamount" => $arrComments, |
| 277 |
"Acomments" => A_COMMENTS, |
| 278 |
"Pollid" => $arrPollid, |
| 279 |
"Percentvoting" => $arrPercentvoting)); |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* Comments to text |
| 284 |
*/ |
| 285 |
if (isset($_GET['action']) && $_GET['action'] == 'comments') |
| 286 |
{ |
| 287 |
$smarty -> assign(array("Amount" => '', |
| 288 |
"Rank" => $player -> rank)); |
| 289 |
|
| 290 |
require_once('includes/comments.php'); |
| 291 |
/** |
| 292 |
* Display comments |
| 293 |
*/ |
| 294 |
if (!isset($_GET['step'])) |
| 295 |
{ |
| 296 |
displaycomments($_GET['poll'], 'polls', 'polls_comments', 'pollid'); |
| 297 |
$smarty -> assign(array("Tauthor" => $arrAuthor, |
| 298 |
"Tbody" => $arrBody, |
| 299 |
"Amount" => $i, |
| 300 |
"Cid" => $arrId, |
| 301 |
"Tdate" => $arrDate, |
| 302 |
"Poll" => $_GET['poll'], |
| 303 |
"Nocomments" => NO_COMMENTS, |
| 304 |
"Addcomment" => ADD_COMMENT, |
| 305 |
"Adelete" => A_DELETE, |
| 306 |
"Aadd" => A_ADD, |
| 307 |
"Writed" => WRITED)); |
| 308 |
} |
| 309 |
|
| 310 |
/** |
| 311 |
* Add comment |
| 312 |
*/ |
| 313 |
if (isset($_GET['step']) && $_GET['step'] == 'add') |
| 314 |
{ |
| 315 |
addcomments($_POST['pid'], 'polls_comments', 'pollid'); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Delete comment |
| 320 |
*/ |
| 321 |
if (isset($_GET['step']) && $_GET['step'] == 'delete') |
| 322 |
{ |
| 323 |
deletecomments('polls_comments'); |
| 324 |
} |
| 325 |
} |
| 326 |
/** |
| 327 |
* Edit poll |
| 328 |
*/ |
| 329 |
if (isset($_GET['action']) && $_GET['action'] == 'edit'){ |
| 330 |
|
| 331 |
if ($player -> rank != 'Admin') |
| 332 |
{ |
| 333 |
error (NOT_ADMIN); |
| 334 |
} |
| 335 |
$objPoll = $db -> Execute("SELECT `poll`, `votes`, `days` FROM `polls` WHERE `id`=".$objPollid -> fields['id']); |
| 336 |
$arrPoll = array(); |
| 337 |
$arrVotes = array(); |
| 338 |
$indexPoll = 0; |
| 339 |
while (!$objPoll -> EOF) |
| 340 |
{ |
| 341 |
if ($objPoll -> fields['votes'] < 0) |
| 342 |
{ |
| 343 |
$strQuestion = $objPoll -> fields['poll']; |
| 344 |
$intDays = $objPoll -> fields['days']; |
| 345 |
$isAnyAnswer = false; |
| 346 |
} |
| 347 |
else |
| 348 |
{ |
| 349 |
$arrPoll[$indexPoll] = $objPoll -> fields['poll']; |
| 350 |
$indexPoll++ ; |
| 351 |
$isAnyAnswer = true; |
| 352 |
} |
| 353 |
$objPoll -> MoveNext(); |
| 354 |
} |
| 355 |
$smarty -> assign(array("Pollid" => $objPollid -> fields['id'], |
| 356 |
"Question" => $strQuestion, |
| 357 |
"Answers" => $arrPoll, |
| 358 |
"isAnyAnswer" => $isAnyAnswer, |
| 359 |
"Days" => $intDays, |
| 360 |
"Amount" => $indexPoll, |
| 361 |
"LangQuestion" => LANG_QUESTION, |
| 362 |
"Answer" => ANSWER, |
| 363 |
"ApplyChange" => APPLY_CHANGE)); |
| 364 |
|
| 365 |
if (isset($_GET['step']) && $_GET['step'] == 'Apply') { |
| 366 |
|
| 367 |
|
| 368 |
if (empty($_POST['question']) || empty($_POST['amount']) || empty($_POST['days'])) |
| 369 |
{ |
| 370 |
error(EMPTY_FIELDS); |
| 371 |
} |
| 372 |
if (!ereg("^[1-9][0-9]*$", $_POST['amount']) || !ereg("^[1-9][0-9]*$", $_POST['days'])) |
| 373 |
{ |
| 374 |
error(ERROR); |
| 375 |
} |
| 376 |
|
| 377 |
$intPid = $db -> qstr($_POST['pid'], get_magic_quotes_gpc()); |
| 378 |
$strQuestion = $db -> qstr($_POST['question'], get_magic_quotes_gpc()); |
| 379 |
$intDays = $db -> qstr($_POST['days'], get_magic_quotes_gpc()); |
| 380 |
|
| 381 |
$db -> Execute("UPDATE `polls` SET `poll`=".$strQuestion.", `days`=".$intDays." WHERE `id`=".$intPid." AND `votes` < 0"); |
| 382 |
|
| 383 |
for($i = 0; $i < $_POST['amount']; $i++) |
| 384 |
{ |
| 385 |
$strName = "answer".$i; |
| 386 |
if (empty($_POST[$strName])) |
| 387 |
{ |
| 388 |
error(EMPTY_FIELDS); |
| 389 |
} |
| 390 |
$answers[$i] = $_POST[$strName]; |
| 391 |
$strAnswer = $db -> qstr($_POST[$strName], get_magic_quotes_gpc()); |
| 392 |
|
| 393 |
$db -> Execute("UPDATE `polls` SET `poll`=".$strAnswer." WHERE `id`=".$intPid." AND `poll`='".$arrPoll[$i]."'"); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
$smarty -> assign(array("Message" => POLL_EDITED, |
| 398 |
"Answers" => $answers, |
| 399 |
"Days" => $_POST['days'], |
| 400 |
"Question" => $_POST['question'])); |
| 401 |
} |
| 402 |
} |
| 403 |
/** |
| 404 |
* Initialization of variable |
| 405 |
*/ |
| 406 |
if (!isset($_GET['action'])) |
| 407 |
{ |
| 408 |
$_GET['action'] = ''; |
| 409 |
if ($player -> location == 'Altara') |
| 410 |
{ |
| 411 |
$fltLogins = fmod($player -> logins, 2); |
| 412 |
if ($fltLogins) |
| 413 |
{ |
| 414 |
$strPollsinfo = POLLS_INFO; |
| 415 |
} |
| 416 |
else |
| 417 |
{ |
| 418 |
$strPollsinfo = POLLS_INFO2; |
| 419 |
} |
| 420 |
} |
| 421 |
else |
| 422 |
{ |
| 423 |
$strPollsinfo = POLLS_INFO; |
| 424 |
} |
| 425 |
$smarty -> assign(array("Pollsinfo" => $strPollsinfo, |
| 426 |
"Noanswer" => NO_ANSWER, |
| 427 |
"Lastpoll" => LAST_POLL, |
| 428 |
"Asend" => A_SEND, |
| 429 |
"Alast10" => A_LAST_10, |
| 430 |
"Pollend" => POLL_END)); |
| 431 |
} |
| 432 |
|
| 433 |
/** |
| 434 |
* Assign variables to template and display page |
| 435 |
*/ |
| 436 |
$smarty -> assign(array("Action" => $_GET['action'], |
| 437 |
"Aback" => A_BACK, |
| 438 |
"Nopolls" => NO_POLLS, |
| 439 |
"Tvotes" => T_VOTES, |
| 440 |
"Sumvotes" => SUM_VOTES, |
| 441 |
"Tmembers" => T_MEMBERS, |
| 442 |
"Polldays" => POLL_DAYS, |
| 443 |
"Tdays" => T_DAYS, |
| 444 |
"Location" => $player -> location, |
| 445 |
"PlayerRank" => $player -> rank)); |
| 446 |
$smarty -> display('polls.tpl'); |
| 447 |
|
| 448 |
require_once("includes/foot.php"); |
| 449 |
?> |