PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/statistics.php

https://github.com/minea94/DboorZ
PHP | 373 lines | 356 code | 10 blank | 7 comment | 180 complexity | b952ac3a3fb42e61bba8fc5127bd0edc MD5 | raw file
  1. <?php
  2. /*********************/
  3. /* */
  4. /* Version : 5.1.0 */
  5. /* Author : RM */
  6. /* Comment : 071223 */
  7. /* */
  8. /*********************/
  9. require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
  10. require_once( MODEL_PATH."statistics.php" );
  11. class GPage extends securegamepage
  12. {
  13. public $selectedTabIndex = NULL;
  14. public $selectedRank = NULL;
  15. public $dataList = NULL;
  16. public $pageSize = 20;
  17. public $pageCount = NULL;
  18. public $pageIndex = NULL;
  19. public $generalData = NULL;
  20. public $top10Result = NULL;
  21. public $isAdmin = FALSE;
  22. public $adminActionMessage = "";
  23. public $_tb = NULL;
  24. public $tatarRaised = NULL;
  25. public function GPage( )
  26. {
  27. parent::securegamepage( );
  28. $this->viewFile = "statistics.phtml";
  29. $this->contentCssClass = "statistics";
  30. }
  31. public function load( )
  32. {
  33. parent::load( );
  34. $this->selectedTabIndex = isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && 0 <= intval( $_GET['t'] ) && intval( $_GET['t'] ) <= 11 ? intval( $_GET['t'] ) : 0;
  35. $this->isAdmin = $this->data['player_type'] == PLAYERTYPE_ADMIN;
  36. $this->_tb = isset( $_GET['tb'] ) ? intval( $_GET['tb'] ) : 0;
  37. $m = new StatisticsModel( );
  38. $this->tatarRaised = $m->tatarRaised( );
  39. if ( $this->selectedTabIndex == 11 && !$this->tatarRaised )
  40. {
  41. $this->selectedTabIndex = 0;
  42. }
  43. $this->selectedRank = 0;
  44. if ( $this->selectedTabIndex == 0 )
  45. {
  46. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  47. {
  48. if ( trim( $_POST['name'] ) != "" )
  49. {
  50. $this->selectedRank = intval( $m->getPlayerRankByName( trim( $_POST['name'] ), $this->_tb ) );
  51. }
  52. else if ( 0 < intval( $_POST['rank'] ) )
  53. {
  54. $this->selectedRank = intval( $_POST['rank'] );
  55. }
  56. }
  57. else if ( !isset( $_GET['p'] ) )
  58. {
  59. $this->selectedRank = 0 < $this->_tb && $this->data['tribe_id'] != $this->_tb ? 1 : intval( $m->getPlayerRankById( $this->player->playerId, $this->_tb ) );
  60. }
  61. if ( $this->isAdmin && !$this->isPost( ) )
  62. {
  63. if ( isset( $_GET['_cs'] ) && 0 < intval( $_GET['_cs'] ) )
  64. {
  65. $m->togglePlayerStatus( intval( $_GET['_cs'] ) );
  66. $this->adminActionMessage = statistics_p_playerstatusch;
  67. }
  68. else if ( isset( $_GET['_dp'] ) && 0 < intval( $_GET['_dp'] ) )
  69. {
  70. if ( $m->getPlayerType( intval( $_GET['_dp'] ) ) == PLAYERTYPE_NORMAL )
  71. {
  72. $qm = new QueueJobModel( );
  73. $qm->deletePlayer( intval( $_GET['_dp'] ) );
  74. $this->adminActionMessage = statistics_p_playerdeleted;
  75. }
  76. }
  77. else if ( isset( $_GET['_gd'] ) && 0 < intval( $_GET['_gd'] ) && isset( $_GET['_g'] ) && 0 <= intval( $_GET['_g'] ) )
  78. {
  79. $m->setPlayerGold( intval( $_GET['_gd'] ), intval( $_GET['_g'] ) );
  80. $this->adminActionMessage = statistics_p_goldwaschanged;
  81. }
  82. }
  83. }
  84. else if ( $this->selectedTabIndex == 1 )
  85. {
  86. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  87. {
  88. if ( trim( $_POST['name'] ) != "" )
  89. {
  90. $this->selectedRank = intval( $m->getAllianceRankByName( trim( $_POST['name'] ) ) );
  91. }
  92. else if ( 0 < intval( $_POST['rank'] ) )
  93. {
  94. $this->selectedRank = intval( $_POST['rank'] );
  95. }
  96. }
  97. else if ( !isset( $_GET['p'] ) )
  98. {
  99. $this->selectedRank = intval( $m->getAllianceRankById( intval( $this->data['alliance_id'] ) ) );
  100. }
  101. }
  102. else if ( $this->selectedTabIndex == 2 )
  103. {
  104. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  105. {
  106. if ( trim( $_POST['name'] ) != "" )
  107. {
  108. $this->selectedRank = intval( $m->getVillageRankByName( trim( $_POST['name'] ) ) );
  109. }
  110. else if ( 0 < intval( $_POST['rank'] ) )
  111. {
  112. $this->selectedRank = intval( $_POST['rank'] );
  113. }
  114. }
  115. else if ( !isset( $_GET['p'] ) )
  116. {
  117. $this->selectedRank = intval( $m->getVillageRankById( $this->data['selected_village_id'] ) );
  118. }
  119. }
  120. else if ( $this->selectedTabIndex == 3 )
  121. {
  122. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  123. {
  124. if ( trim( $_POST['name'] ) != "" )
  125. {
  126. $this->selectedRank = intval( $m->getHeroRankByName( trim( $_POST['name'] ) ) );
  127. }
  128. else if ( 0 < intval( $_POST['rank'] ) )
  129. {
  130. $this->selectedRank = intval( $_POST['rank'] );
  131. }
  132. }
  133. else if ( !isset( $_GET['p'] ) )
  134. {
  135. $this->selectedRank = intval( $m->getHeroRankById( $this->player->playerId ) );
  136. }
  137. }
  138. else if ( $this->selectedTabIndex == 6 || $this->selectedTabIndex == 7 )
  139. {
  140. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  141. {
  142. if ( trim( $_POST['name'] ) != "" )
  143. {
  144. $this->selectedRank = intval( $m->getPlayersPointsByName( trim( $_POST['name'] ), $this->selectedTabIndex == 6 ) );
  145. }
  146. else if ( 0 < intval( $_POST['rank'] ) )
  147. {
  148. $this->selectedRank = intval( $_POST['rank'] );
  149. }
  150. }
  151. else if ( !isset( $_GET['p'] ) )
  152. {
  153. $this->selectedRank = intval( $m->getPlayersPointsById( $this->player->playerId, $this->selectedTabIndex == 6 ) );
  154. }
  155. }
  156. else if ( $this->selectedTabIndex == 9 || $this->selectedTabIndex == 10 )
  157. {
  158. if ( $this->isPost( ) && isset( $_POST['rank'] ) && isset( $_POST['name'] ) )
  159. {
  160. if ( trim( $_POST['name'] ) != "" )
  161. {
  162. $this->selectedRank = intval( $m->getAlliancePointsRankByName( trim( $_POST['name'] ), $this->selectedTabIndex == 9 ) );
  163. }
  164. else if ( 0 < intval( $_POST['rank'] ) )
  165. {
  166. $this->selectedRank = intval( $_POST['rank'] );
  167. }
  168. }
  169. else if ( !isset( $_GET['p'] ) )
  170. {
  171. $this->selectedRank = intval( $m->getAlliancePointsRankById( intval( $this->data['alliance_id'] ), $this->selectedTabIndex == 9 ) );
  172. }
  173. }
  174. if ( $this->selectedTabIndex == 0 )
  175. {
  176. $rowsCount = $m->getPlayerListCount( $this->_tb );
  177. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  178. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  179. if ( $this->pageCount <= $this->pageIndex )
  180. {
  181. $this->pageIndex = $this->pageCount - 1;
  182. $this->selectedRank = 0 - 1;
  183. }
  184. $this->dataList = $m->getPlayerList( $this->pageIndex, $this->pageSize, $this->_tb );
  185. }
  186. else if ( $this->selectedTabIndex == 1 )
  187. {
  188. $rowsCount = $m->getAllianceListCount( );
  189. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  190. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  191. if ( $this->pageCount <= $this->pageIndex )
  192. {
  193. $this->pageIndex = $this->pageCount - 1;
  194. $this->selectedRank = 0 - 1;
  195. }
  196. $this->dataList = $m->getAlliancesList( $this->pageIndex, $this->pageSize );
  197. }
  198. else if ( $this->selectedTabIndex == 2 )
  199. {
  200. $rowsCount = $m->getVillageListCount( );
  201. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  202. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  203. if ( $this->pageCount <= $this->pageIndex )
  204. {
  205. $this->pageIndex = $this->pageCount - 1;
  206. $this->selectedRank = 0 - 1;
  207. }
  208. $this->dataList = $m->getVillagesList( $this->pageIndex, $this->pageSize );
  209. }
  210. else if ( $this->selectedTabIndex == 3 )
  211. {
  212. $rowsCount = $m->getHeroListCount( );
  213. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  214. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  215. if ( $this->pageCount <= $this->pageIndex )
  216. {
  217. $this->pageIndex = $this->pageCount - 1;
  218. $this->selectedRank = 0 - 1;
  219. }
  220. $this->dataList = $m->getHerosList( $this->pageIndex, $this->pageSize );
  221. }
  222. else if ( $this->selectedTabIndex == 4 )
  223. {
  224. $this->generalData = $m->getGeneralSummary( );
  225. }
  226. else if ( $this->selectedTabIndex == 6 || $this->selectedTabIndex == 7 )
  227. {
  228. $rowsCount = $m->getPlayersPointsListCount( );
  229. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  230. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  231. if ( $this->pageCount <= $this->pageIndex )
  232. {
  233. $this->pageIndex = $this->pageCount - 1;
  234. $this->selectedRank = 0 - 1;
  235. }
  236. $this->dataList = $m->getPlayersPointsList( $this->pageIndex, $this->pageSize, $this->selectedTabIndex == 6 );
  237. }
  238. else if ( $this->selectedTabIndex == 9 || $this->selectedTabIndex == 10 )
  239. {
  240. $rowsCount = $m->getAlliancePointsListCount( );
  241. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  242. $this->pageIndex = 0 < $this->selectedRank ? floor( ( $this->selectedRank - 1 ) / $this->pageSize ) : isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) ? intval( $_GET['p'] ) : 0;
  243. if ( $this->pageCount <= $this->pageIndex )
  244. {
  245. $this->pageIndex = $this->pageCount - 1;
  246. $this->selectedRank = 0 - 1;
  247. }
  248. $this->dataList = $m->getAlliancePointsList( $this->pageIndex, $this->pageSize, $this->selectedTabIndex == 9 );
  249. }
  250. else if ( $this->selectedTabIndex == 5 || $this->selectedTabIndex == 8 )
  251. {
  252. if ( $this->selectedTabIndex == 5 )
  253. {
  254. }
  255. $this->top10Result = array(
  256. "URL" => $this->selectedTabIndex == 5 ? "profile.php?uid=" : "alliance.php?id=",
  257. "TARGETNAME" => $this->selectedTabIndex == 5 ? $this->data['name'] : $this->data['alliance_name'],
  258. "TARGETID" => $this->selectedTabIndex == 5 ? $this->player->playerId : intval( $this->data['alliance_id'] ),
  259. "TARGEPOINT_ATTACK" => $this->selectedTabIndex == 5 ? $this->data['week_attack_points'] : $m->getAlliancePoint( intval( $this->data['alliance_id'] ), "week_attack_points" ),
  260. "TARGEPOINT_DEFENSE" => $this->selectedTabIndex == 5 ? $this->data['week_defense_points'] : $m->getAlliancePoint( intval( $this->data['alliance_id'] ), "week_defense_points" ),
  261. "TARGEPOINT_DEV" => $this->selectedTabIndex == 5 ? $this->data['week_dev_points'] : $m->getAlliancePoint( intval( $this->data['alliance_id'] ), "week_dev_points" ),
  262. "TARGEPOINT_THIEF" => $m->getAlliancePoint( intval( $this->data['alliance_id'] ), "week_thief_points" ),
  263. "ATTACK" => $m->getTop10( $this->selectedTabIndex == 5, "week_attack_points" ),
  264. "DEFENSE" => $m->getTop10( $this->selectedTabIndex == 5, "week_defense_points" ),
  265. "DEV" => $m->getTop10( $this->selectedTabIndex == 5, "week_dev_points" ),
  266. "THIEF" => $m->getTop10( $this->selectedTabIndex == 5, "week_thief_points" )
  267. );
  268. }
  269. else if ( $this->selectedTabIndex == 11 )
  270. {
  271. $this->dataList = $m->getTatarVillagesList( );
  272. }
  273. $m->dispose( );
  274. }
  275. public function preRender( )
  276. {
  277. parent::prerender( );
  278. if ( 0 <= $this->selectedTabIndex )
  279. {
  280. $this->villagesLinkPostfix .= "&t=".$this->selectedTabIndex;
  281. }
  282. }
  283. public function getNextLink( )
  284. {
  285. $text = text_nextpage_lang." »";
  286. if ( $this->pageIndex + 1 == $this->pageCount )
  287. {
  288. return $text;
  289. }
  290. $link = "";
  291. if ( 0 < $this->selectedTabIndex )
  292. {
  293. $link .= "t=".$this->selectedTabIndex;
  294. }
  295. if ( $link != "" )
  296. {
  297. $link .= "&";
  298. }
  299. $link .= "p=".( $this->pageIndex + 1 );
  300. if ( 0 < $this->_tb )
  301. {
  302. $link .= "&tb=".$this->_tb;
  303. }
  304. $link = "statistics.php?".$link;
  305. return "<a href=\"".$link."\">".$text."</a>";
  306. }
  307. public function getPreviousLink( )
  308. {
  309. $text = "« ".text_prevpage_lang;
  310. if ( $this->pageIndex == 0 )
  311. {
  312. return $text;
  313. }
  314. $link = "";
  315. if ( 0 < $this->selectedTabIndex )
  316. {
  317. $link .= "t=".$this->selectedTabIndex;
  318. }
  319. if ( 0 < $this->pageIndex )
  320. {
  321. if ( $link != "" )
  322. {
  323. $link .= "&";
  324. }
  325. $link .= "p=".( $this->pageIndex - 1 );
  326. }
  327. if ( 0 < $this->_tb )
  328. {
  329. if ( $link != "" )
  330. {
  331. $link .= "&";
  332. }
  333. $link .= "tb=".$this->_tb;
  334. }
  335. if ( $link != "" )
  336. {
  337. $link = "?".$link;
  338. }
  339. $link = "statistics.php".$link;
  340. return "<a href=\"".$link."\">".$text."</a>";
  341. }
  342. public function getWonderLandLevel( $builds )
  343. {
  344. $b_arr = explode( ",", $builds );
  345. $indx = 0;
  346. foreach ( $b_arr as $b_str )
  347. {
  348. ++$indx;
  349. $b2 = explode( " ", $b_str );
  350. $itemId = $b2[0];
  351. $level = $b2[1];
  352. if ( !( $itemId == 40 ) )
  353. {
  354. continue;
  355. }
  356. return $level;
  357. }
  358. return 0;
  359. }
  360. }
  361. $p = new GPage( );
  362. $p->run( );
  363. ?>