PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/log.php

https://bitbucket.org/marecki/orodlin-v.1
PHP | 230 lines | 170 code | 17 blank | 43 comment | 38 complexity | bad57fcfb49fff8ab5ffe29da56dcf03 MD5 | raw file
  1. <?php
  2. /**
  3. * File functions:
  4. * Player log - events
  5. *
  6. * @name : log.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.3
  10. * @since : 16.10.2006
  11. *
  12. */
  13. //
  14. //
  15. // This program is free software; you can redistribute it and/or modify
  16. // it under the terms of the GNU General Public License as published by
  17. // the Free Software Foundation; either version 2 of the License, or
  18. // (at your option) any later version.
  19. //
  20. // This program is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. // GNU General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU General Public License
  26. // along with this program; if not, write to the Free Software
  27. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. //
  29. // $Id: log.php 725 2006-10-16 15:47:57Z thindil $
  30. $title = "Dziennik";
  31. require_once("includes/head.php");
  32. /**
  33. * Get the localization for game
  34. */
  35. require_once("languages/".$player -> lang."/log.php");
  36. $db -> Execute("UPDATE log SET unread='T' WHERE unread='F' AND owner=".$player -> id);
  37. if (!isset($_GET['limit']))
  38. {
  39. $_GET['limit'] = 0;
  40. }
  41. if (!ereg("^[0-9]*$", $_GET['limit']))
  42. {
  43. error(ERROR);
  44. }
  45. $objTest = $db -> Execute("SELECT count(*) FROM `log` WHERE `owner`=".$player -> id." ORDER BY `id` DESC");
  46. $intAmount = $objTest -> fields['count(*)'];
  47. $objTest -> Close();
  48. if ($intAmount < $_GET['limit'])
  49. {
  50. error(ERROR);
  51. }
  52. $smarty -> assign(array("Previous" => '',
  53. "Next" => ''));
  54. $log = $db -> SelectLimit("SELECT `id`, `log`, `czas` FROM `log` WHERE `owner`=".$player -> id." ORDER BY `id` DESC", 30, $_GET['limit']);
  55. $arrdate = array();
  56. $arrtext = array();
  57. $arrid1 = array(0);
  58. $i = 0;
  59. while (!$log -> EOF)
  60. {
  61. $arrdate[$i] = $log -> fields['czas'];
  62. $arrtext[$i] = $log -> fields['log'];
  63. $arrid1[$i] = $log -> fields['id'];
  64. $log -> MoveNext();
  65. $i = $i + 1;
  66. }
  67. $log -> Close();
  68. if ($_GET['limit'] >= 30)
  69. {
  70. $intLimit = $_GET['limit'] - 30;
  71. $smarty -> assign("Previous", "<form method=\"post\" action=\"log.php?limit=".$intLimit."\"><input type=\"submit\" value=\"".A_PREVIOUS."\" /></form> ");
  72. }
  73. $_GET['limit'] = $_GET['limit'] + 30;
  74. if ($intAmount > 30 && $_GET['limit'] < $intAmount)
  75. {
  76. $smarty -> assign("Next", "<form method=\"post\" action=\"log.php?limit=".$_GET['limit']."\"><input type=\"submit\" value=\"".A_NEXT."\" /></form>");
  77. }
  78. if (isset($_GET['akcja']) && $_GET['akcja'] == 'wyczysc')
  79. {
  80. $db -> Execute("DELETE FROM log WHERE owner=".$player -> id);
  81. error ("<br />".YOU_CLEAR." (<a href=\"log.php\">".A_REFRESH."</a>)");
  82. }
  83. if (isset($_GET['send']))
  84. {
  85. $sid = $db -> Execute("SELECT id, user FROM players WHERE rank='Admin' OR rank='Staff'");
  86. $arrname = array();
  87. $arrid = array();
  88. $i = 0;
  89. while (!$sid -> EOF) {
  90. $arrname[$i] = $sid -> fields['user'];
  91. $arrid[$i] = $sid -> fields['id'];
  92. $sid -> MoveNext();
  93. $i = $i + 1;
  94. }
  95. $sid -> Close();
  96. $smarty -> assign(array("Name" => $arrname,
  97. "StaffId" => $arrid,
  98. "Sendthis" => SEND_THIS,
  99. "Asend" => A_SEND));
  100. if (isset ($_GET['step']) && $_GET['step'] == 'send')
  101. {
  102. if (!ereg("^[1-9][0-9]*$", $_POST['staff']))
  103. {
  104. error (ERROR);
  105. }
  106. if (!ereg("^[1-9][0-9]*$", $_POST['lid']))
  107. {
  108. error (ERROR);
  109. }
  110. $arrtest = $db -> Execute("SELECT id, user, rank FROM players WHERE id=".$_POST['staff']);
  111. if (!$arrtest -> fields['id'])
  112. {
  113. error (NO_PLAYER);
  114. }
  115. if ($arrtest -> fields['rank'] != 'Admin' && $arrtest -> fields['rank'] != 'Staff')
  116. {
  117. error (NOT_STAFF);
  118. }
  119. $arrmessage = $db -> Execute("SELECT * FROM log WHERE id=".$_POST['lid']);
  120. if (!$arrmessage -> fields['id'])
  121. {
  122. error (NO_EVENT);
  123. }
  124. if ($arrmessage -> fields['owner'] != $player -> id)
  125. {
  126. error (NOT_YOUR);
  127. }
  128. $strDate = $db -> DBDate($newdate);
  129. $db -> Execute("INSERT INTO log (owner, log, czas) VALUES(".$arrtest -> fields['id'].",'".L_PLAYER."<a href=view.php?view=".$player -> id.">".$player -> user."</a>".L_ID.$player -> id.SEND_YOU."', ".$strDate.")");
  130. $db -> Execute("INSERT INTO mail (sender,senderid,owner,subject,body) values('".$player -> user."','".$player -> id."',".$arrtest -> fields['id'].",'".L_TITLE."','".$arrmessage -> fields['czas']."<br />".$arrmessage -> fields['log']."')");
  131. error (YOU_SEND.$arrtest -> fields['user'].". <a href=log.php>".A_REFRESH."</a>");
  132. }
  133. }
  134. /**
  135. * Delete selected logs
  136. */
  137. if (isset($_GET['action']) && $_GET['action'] == 'delete')
  138. {
  139. $objLid = $db -> Execute("SELECT id FROM log WHERE owner=".$player -> id);
  140. $arrId = array();
  141. $i = 0;
  142. while (!$objLid -> EOF)
  143. {
  144. $arrId[$i] = $objLid -> fields['id'];
  145. $i = $i + 1;
  146. $objLid -> MoveNext();
  147. }
  148. $objLid -> Close();
  149. foreach ($arrId as $bid)
  150. {
  151. if (isset($_POST[$bid]))
  152. {
  153. $db -> Execute("DELETE FROM log WHERE id=".$bid);
  154. }
  155. }
  156. error(DELETED);
  157. }
  158. /**
  159. * Delete old logs
  160. */
  161. if (isset($_GET['step']) && $_GET['step'] == 'deleteold')
  162. {
  163. $arrAmount = array(7, 14, 30);
  164. if (!in_array($_POST['oldtime'], $arrAmount))
  165. {
  166. error(ERROR);
  167. }
  168. $arrDate = explode("-", $data);
  169. $arrDate[0] = date("Y");
  170. $arrDate[2] = $arrDate[2] - $_POST['oldtime'];
  171. if ($arrDate[2] < 1)
  172. {
  173. $arrDays = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  174. $arrDate[1] = $arrDate[1] - 1;
  175. if ($arrDate[1] == 0)
  176. {
  177. $arrDate[1] = 12;
  178. }
  179. $intKey = $arrDate[1] - 1;
  180. $arrDate[2] = $arrDays[$intKey] + $arrDate[2];
  181. }
  182. $strDate = implode("-", $arrDate);
  183. $strDate = $db -> DBDate($strDate);
  184. $db -> Execute("DELETE FROM `log` WHERE `owner`=".$player -> id." AND `czas`<".$strDate);
  185. error(DELETED2);
  186. }
  187. /**
  188. * Initialization of variable
  189. */
  190. if (!isset($_GET['send']))
  191. {
  192. $_GET['send'] = '';
  193. }
  194. /**
  195. * Assign variables to template and display page
  196. */
  197. $smarty -> assign(array("Date" => $arrdate,
  198. "Text" => $arrtext,
  199. "LogId" => $arrid1,
  200. "Send" => $_GET['send'],
  201. "Loginfo" => LOG_INFO2,
  202. "Event" => EVENT,
  203. "Edate" => E_DATE,
  204. "Sendevent" => SEND_EVENT,
  205. "Clearlog" => CLEAR_LOG,
  206. "Adeleteold" => A_DELETE_OLD,
  207. "Aweek" => A_WEEK,
  208. "A2week" => A_2WEEK,
  209. "Amonth" => A_MONTH,
  210. "Adelete" => A_DELETE));
  211. $smarty -> display ('log.tpl');
  212. require_once("includes/foot.php");
  213. ?>