PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/report.php

https://github.com/minea94/DboorZ
PHP | 484 lines | 466 code | 11 blank | 7 comment | 142 complexity | 168e9d0f3ed377801501163beba6d86c MD5 | raw file
  1. <?php
  2. /*********************/
  3. /* */
  4. /* Dezend for PHP5 */
  5. /* NWS */
  6. /* Nulled.WS */
  7. /* */
  8. /*********************/
  9. require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
  10. require_once( MODEL_PATH."report.php" );
  11. class GPage extends SecureGamePage
  12. {
  13. public $showList;
  14. public $selectedTabIndex;
  15. public $reportData;
  16. public $dataList;
  17. public $pageSize = 10;
  18. public $pageCount;
  19. public $pageIndex;
  20. public function GPage( )
  21. {
  22. parent::securegamepage( );
  23. $this->viewFile = "report.phtml";
  24. $this->contentCssClass = "reports";
  25. }
  26. public function load( )
  27. {
  28. parent::load( );
  29. $this->showList = !( isset( $_GET['id'] ) && 0 < intval( $_GET['id'] ) );
  30. $this->selectedTabIndex = $this->showList && isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && 1 <= intval( $_GET['t'] ) && intval( $_GET['t'] ) <= 4 ? intval( $_GET['t'] ) : 0;
  31. $m = new ReportModel( );
  32. if ( !$this->isPost( ) )
  33. {
  34. if ( !$this->showList )
  35. {
  36. $this->selectedTabIndex = 0;
  37. $reportId = intval( $_GET['id'] );
  38. $result = $m->getReport( $reportId );
  39. if ( $result->next( ) )
  40. {
  41. $readStatus = $result->row['read_status'];
  42. $deleteStatus = $result->row['delete_status'];
  43. $this->reportData = array( );
  44. $this->reportData['messageDate'] = $result->row['mdate'];
  45. $this->reportData['messageTime'] = $result->row['mtime'];
  46. $this->reportData['from_player_id'] = $from_player_id = intval( $result->row['from_player_id'] );
  47. $this->reportData['to_player_id'] = $to_player_id = intval( $result->row['to_player_id'] );
  48. $this->reportData['from_village_id'] = intval( $result->row['from_village_id'] );
  49. $this->reportData['to_village_id'] = intval( $result->row['to_village_id'] );
  50. $this->reportData['from_player_name'] = $result->row['from_player_name'];
  51. $this->reportData['to_player_name'] = $result->row['to_player_name'];
  52. $this->reportData['to_village_name'] = $result->row['to_village_name'];
  53. $this->reportData['from_village_name'] = $result->row['from_village_name'];
  54. $this->reportData['rpt_body'] = $result->row['rpt_body'];
  55. $this->reportData['rpt_cat'] = $result->row['rpt_cat'];
  56. $this->reportData['mdate'] = $result->row['mdate'];
  57. $this->reportData['mtime'] = $result->row['mtime'];
  58. $this->reportData['to_player_alliance_id'] = $m->getPlayerAllianceId( $to_player_id );
  59. switch ( $this->reportData['rpt_cat'] )
  60. {
  61. case 1 :
  62. $this->reportData['resources'] = explode( " ", $this->reportData['rpt_body'] );
  63. break;
  64. case 2 :
  65. $troopsStr = explode( "|", $this->reportData['rpt_body'] );
  66. list( $troopsStr ) = $troopsStr;
  67. $this->reportData['troopsTable'] = array( "troops" => array( ), "hasHero" => FALSE );
  68. $troopsStrArr = explode( ",", $troopsStr );
  69. foreach ( $troopsStrArr as $t )
  70. {
  71. $tnum = explode( " ", $t );
  72. $tid = explode( " ", $t );
  73. list( $tid, $tnum ) = $tid;
  74. if ( $tnum == 0 - 1 )
  75. {
  76. $this->reportData['troopsTable']['hasHero'] = TRUE;
  77. }
  78. else
  79. {
  80. $this->reportData['troopsTable']['troops'][$tid] = $tnum;
  81. }
  82. }
  83. break;
  84. case 3 :
  85. $bodyArr = explode( "|", $this->reportData['rpt_body'] );
  86. $harvestResources = $bodyArr;
  87. $total_carry_load = $bodyArr;
  88. $defenseTableTroopsStr = $bodyArr;
  89. $attackTroopsStr = $bodyArr;
  90. list( $attackTroopsStr, $defenseTableTroopsStr, $total_carry_load, $harvestResources ) = $attackTroopsStr;
  91. $wallDestructionResult = isset( $bodyArr[4] ) ? $bodyArr[4] : "";
  92. $catapultResult = isset( $bodyArr[5] ) ? $bodyArr[5] : "";
  93. $oasisResult = isset( $bodyArr[6] ) ? $bodyArr[6] : "";
  94. $captureResult = isset( $bodyArr[7] ) ? $bodyArr[7] : "";
  95. $this->reportData['total_carry_load'] = $total_carry_load;
  96. $this->reportData['total_harvest_carry_load'] = 0;
  97. $this->reportData['harvest_resources'] = array( );
  98. $res = explode( " ", $harvestResources );
  99. foreach ( $res as $r )
  100. {
  101. $this->reportData['total_harvest_carry_load'] += $r;
  102. $this->reportData['harvest_resources'][] = $r;
  103. }
  104. $attackTroopsStrArr = explode( ",", $attackTroopsStr );
  105. $this->reportData['attackTroopsTable'] = array(
  106. "troops" => array( ),
  107. "heros" => array( "number" => 0, "dead_number" => 0 )
  108. );
  109. $totalAttackTroops_live = 0;
  110. $totalAttackTroops_dead = 0;
  111. $attackWallDestrTroopId = 0;
  112. $attackCatapultTroopId = 0;
  113. $kingTroopId = 0;
  114. foreach ( $attackTroopsStrArr as $s )
  115. {
  116. $deadNum = explode( " ", $s );
  117. $num = explode( " ", $s );
  118. $tid = explode( " ", $s );
  119. list( $tid, $num, $deadNum ) = $tid;
  120. $totalAttackTroops_live += $num;
  121. $totalAttackTroops_dead += $deadNum;
  122. if ( $tid == 7 || $tid == 17 || $tid == 27 || $tid == 106 || $tid == 57 )
  123. {
  124. $attackWallDestrTroopId = $tid;
  125. }
  126. else if ( $tid == 8 || $tid == 18 || $tid == 28 || $tid == 107 || $tid == 58 )
  127. {
  128. $attackCatapultTroopId = $tid;
  129. }
  130. else if ( $tid == 9 || $tid == 19 || $tid == 29 || $tid == 108 || $tid == 59 )
  131. {
  132. $kingTroopId = $tid;
  133. }
  134. if ( $tid == 0 - 1 )
  135. {
  136. $this->reportData['attackTroopsTable']['heros']['number'] = $num;
  137. $this->reportData['attackTroopsTable']['heros']['dead_number'] = $deadNum;
  138. }
  139. else
  140. {
  141. $this->reportData['attackTroopsTable']['troops'][$tid] = array( "number" => $num, "dead_number" => $deadNum );
  142. }
  143. }
  144. $this->reportData['all_attackTroops_dead'] = $totalAttackTroops_live <= $totalAttackTroops_dead;
  145. $this->reportData['defenseTroopsTable'] = array( );
  146. $troopsTableStrArr = trim( $defenseTableTroopsStr ) == "" ? array( ) : explode( "#", $defenseTableTroopsStr );
  147. $j = 0 - 1;
  148. foreach ( $troopsTableStrArr as $defenseTableTroopsStr2 )
  149. {
  150. ++$j;
  151. $defenseTroopsStrArr = explode( ",", $defenseTableTroopsStr2 );
  152. $this->reportData['defenseTroopsTable'][$j] = array( "troops" => array( ), "heros" => array( "number" => 0, "dead_number" => 0 ) );
  153. foreach ( $defenseTroopsStrArr as $s )
  154. {
  155. $deadNum = explode( " ", $s );
  156. $num = explode( " ", $s );
  157. $tid = explode( " ", $s );
  158. list( $tid, $num, $deadNum ) = $tid;
  159. if ( $tid == 0 - 1 )
  160. {
  161. $this->reportData['defenseTroopsTable'][$j]['heros']['number'] = $num;
  162. $this->reportData['defenseTroopsTable'][$j]['heros']['dead_number'] = $deadNum;
  163. }
  164. else
  165. {
  166. $this->reportData['defenseTroopsTable'][$j]['troops'][$tid] = array( "number" => $num, "dead_number" => $deadNum );
  167. }
  168. }
  169. }
  170. if ( $captureResult != "" )
  171. {
  172. $wstr = "";
  173. if ( $captureResult == "+" )
  174. {
  175. $wstr = report_p_villagecaptured;
  176. }
  177. else
  178. {
  179. $warr = explode( "-", $captureResult );
  180. $wstr = report_p_allegiancelowered." ".$warr[0]." ".report_p_to." ".$warr[1];
  181. }
  182. if ( $wstr != "" )
  183. {
  184. $wstr = "<img src=\"assets/x.gif\" class=\"unit u".$kingTroopId."\" align=\"center\" /> ".$wstr;
  185. }
  186. $this->reportData['captureResult'] = $wstr;
  187. }
  188. if ( $oasisResult != "" )
  189. {
  190. $wstr = "";
  191. if ( $oasisResult == "+" )
  192. {
  193. $wstr = report_p_oasiscaptured;
  194. }
  195. else
  196. {
  197. $warr = explode( "-", $oasisResult );
  198. $wstr = report_p_allegiancelowered." ".$warr[0]." ".report_p_to." ".$warr[1];
  199. }
  200. if ( $wstr != "" )
  201. {
  202. $wstr = "<img src=\"assets/x.gif\" class=\"unit uhero\" align=\"center\" /> ".$wstr;
  203. }
  204. $this->reportData['oasisResult'] = $wstr;
  205. }
  206. if ( $wallDestructionResult != "" )
  207. {
  208. $wstr = "";
  209. if ( $wallDestructionResult == "-" )
  210. {
  211. $wstr = report_p_wallnotdestr;
  212. }
  213. else if ( $wallDestructionResult == "+" )
  214. {
  215. $wstr = report_p_nowall;
  216. }
  217. else
  218. {
  219. $warr = explode( "-", $wallDestructionResult );
  220. if ( intval( $warr[1] ) == 0 )
  221. {
  222. $wstr = report_p_walldestr;
  223. }
  224. $wstr = report_p_walllowered." ".$warr[0]." ".report_p_to." ".$warr[1];
  225. }
  226. if ( $wstr != "" )
  227. {
  228. $wstr = "<img src=\"assets/x.gif\" class=\"unit u".$attackWallDestrTroopId."\" align=\"center\" /> ".$wstr;
  229. }
  230. $this->reportData['wallDestructionResult'] = $wstr;
  231. }
  232. if ( $catapultResult != "" )
  233. {
  234. $bdestArr = array( );
  235. if ( $catapultResult == "+" )
  236. {
  237. $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u".$attackCatapultTroopId."\" align=\"center\" /> ".report_p_totallydestr;
  238. }
  239. else
  240. {
  241. $catapultResultArr = explode( "#", $catapultResult );
  242. foreach ( $catapultResultArr as $catapultResultInfo )
  243. {
  244. $toLevel = explode( " ", $catapultResultInfo );
  245. $fromLevel = explode( " ", $catapultResultInfo );
  246. $itemId = explode( " ", $catapultResultInfo );
  247. list( $itemId, $fromLevel, $toLevel ) = $itemId;
  248. if ( $toLevel == 0 - 1 )
  249. {
  250. $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u".$attackCatapultTroopId."\" align=\"center\" /> ".report_p_notdestr." ".constant( "item_".$itemId );
  251. }
  252. else if ( $toLevel == 0 )
  253. {
  254. $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u".$attackCatapultTroopId."\" align=\"center\" /> ".report_p_wasdestr." ".constant( "item_".$itemId );
  255. }
  256. else
  257. {
  258. $bdestArr[] = "<img src=\"assets/x.gif\" class=\"unit u".$attackCatapultTroopId."\" align=\"center\" /> ".report_p_waslowered." ".constant( "item_".$itemId )." ".report_p_fromlevel." ".$fromLevel." ".report_p_to." ".$toLevel;
  259. }
  260. }
  261. }
  262. $this->reportData['buildingDestructionResult'] = $bdestArr;
  263. }
  264. break;
  265. case 4 :
  266. $spyType = explode( "|", $this->reportData['rpt_body'] );
  267. $harvestInfo = explode( "|", $this->reportData['rpt_body'] );
  268. $harvestResources = explode( "|", $this->reportData['rpt_body'] );
  269. $defenseTableTroopsStr = explode( "|", $this->reportData['rpt_body'] );
  270. $attackTroopsStr = explode( "|", $this->reportData['rpt_body'] );
  271. list( $attackTroopsStr, $defenseTableTroopsStr, $harvestResources, $harvestInfo, $spyType ) = $attackTroopsStr;
  272. if ( trim( $harvestResources ) != "" && $spyType == 1 )
  273. {
  274. $this->reportData['harvest_resources'] = explode( " ", trim( $harvestResources ) );
  275. }
  276. if ( trim( $harvestInfo ) != "" && $spyType == 2 )
  277. {
  278. $level = explode( " ", $harvestInfo );
  279. $itemId = explode( " ", $harvestInfo );
  280. list( $itemId, $level ) = $itemId;
  281. $this->reportData['harvest_info'] = constant( "item_".$itemId )." ".level_lang." ".$level;
  282. }
  283. $this->reportData['all_spy_dead'] = FALSE;
  284. if ( $spyType == 3 )
  285. {
  286. $this->reportData['all_spy_dead'] = TRUE;
  287. $this->reportData['harvest_info'] = report_p_allkilled;
  288. }
  289. $attackTroopsStrArr = explode( ",", $attackTroopsStr );
  290. $this->reportData['attackTroopsTable'] = array( "troops" => array( ), "heros" => array( "number" => 0, "dead_number" => 0 ) );
  291. foreach ( $attackTroopsStrArr as $s )
  292. {
  293. $deadNum = explode( " ", $s );
  294. $num = explode( " ", $s );
  295. $tid = explode( " ", $s );
  296. list( $tid, $num, $deadNum ) = $tid;
  297. if ( $tid == 0 - 1 )
  298. {
  299. $this->reportData['attackTroopsTable']['heros']['number'] = $num;
  300. $this->reportData['attackTroopsTable']['heros']['dead_number'] = $deadNum;
  301. }
  302. else
  303. {
  304. $this->reportData['attackTroopsTable']['troops'][$tid] = array( "number" => $num, "dead_number" => $deadNum );
  305. }
  306. }
  307. $this->reportData['defenseTroopsTable'] = array( );
  308. $troopsTableStrArr = trim( $defenseTableTroopsStr ) == "" ? array( ) : explode( "#", $defenseTableTroopsStr );
  309. $j = 0 - 1;
  310. foreach ( $troopsTableStrArr as $defenseTableTroopsStr2 )
  311. {
  312. ++$j;
  313. $defenseTroopsStrArr = explode( ",", $defenseTableTroopsStr2 );
  314. $this->reportData['defenseTroopsTable'][$j] = array( "troops" => array( ), "heros" => array( "number" => 0, "dead_number" => 0 ) );
  315. foreach ( $defenseTroopsStrArr as $s )
  316. {
  317. $deadNum = explode( " ", $s );
  318. $num = explode( " ", $s );
  319. $tid = explode( " ", $s );
  320. list( $tid, $num, $deadNum ) = $tid;
  321. if ( $tid == 0 - 1 )
  322. {
  323. $this->reportData['defenseTroopsTable'][$j]['heros']['number'] = $num;
  324. $this->reportData['defenseTroopsTable'][$j]['heros']['dead_number'] = $deadNum;
  325. }
  326. else
  327. {
  328. $this->reportData['defenseTroopsTable'][$j]['troops'][$tid] = array( "number" => $num, "dead_number" => $deadNum );
  329. }
  330. }
  331. }
  332. }
  333. $isDeleted = FALSE;
  334. if ( !$isDeleted )
  335. {
  336. $canOpenReport = TRUE;
  337. if ( $this->player->playerId != $from_player_id && $this->player->playerId != $to_player_id )
  338. {
  339. $canOpenReport = 0 < intval( $this->data['alliance_id'] ) && ( $this->data['alliance_id'] == $m->getPlayerAllianceId( $to_player_id ) || $this->data['alliance_id'] == $m->getPlayerAllianceId( $from_player_id ) );
  340. }
  341. if ( $canOpenReport )
  342. {
  343. if ( !$this->player->isSpy )
  344. {
  345. if ( $to_player_id == $this->player->playerId )
  346. {
  347. if ( $readStatus == 0 || $readStatus == 2 )
  348. {
  349. $m->markReportAsReaded( $this->player->playerId, $to_player_id, $reportId, $readStatus );
  350. --$this->data['new_report_count'];
  351. }
  352. }
  353. else
  354. {
  355. if ( $from_player_id == $this->player->playerId && ( $readStatus == 0 || $readStatus == 1 ) )
  356. {
  357. $m->markReportAsReaded( $this->player->playerId, $to_player_id, $reportId, $readStatus );
  358. --$this->data['new_report_count'];
  359. }
  360. }
  361. }
  362. }
  363. else
  364. {
  365. $this->showList = TRUE;
  366. }
  367. }
  368. else
  369. {
  370. $this->showList = TRUE;
  371. }
  372. }
  373. else
  374. {
  375. $this->showList = TRUE;
  376. }
  377. $result->free( );
  378. }
  379. }
  380. else if ( isset( $_POST['dr'] ) && isset( $_POST['dr'] ) )
  381. {
  382. foreach ( $_POST['dr'] as $reportId )
  383. {
  384. if ( $m->deleteReport( $this->player->playerId, $reportId ) )
  385. {
  386. --$this->data['new_report_count'];
  387. }
  388. }
  389. }
  390. if ( $this->showList )
  391. {
  392. $rowsCount = $m->getReportListCount( $this->player->playerId, $this->selectedTabIndex );
  393. $this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
  394. $this->pageIndex = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) && intval( $_GET['p'] ) < $this->pageCount ? intval( $_GET['p'] ) : 0;
  395. $this->dataList = $m->getReportList( $this->player->playerId, $this->selectedTabIndex, $this->pageIndex, $this->pageSize );
  396. if ( 0 < $this->data['new_report_count'] )
  397. {
  398. $this->data['new_report_count'] = $m->syncReports( $this->player->playerId );
  399. }
  400. }
  401. $m->dispose( );
  402. }
  403. public function getVillageName( $playerId, $villageName )
  404. {
  405. return 0 < intval( $playerId ) ? $villageName : "<span class=\"none\">[?]</span>";
  406. }
  407. public function preRender( )
  408. {
  409. parent::prerender( );
  410. if ( isset( $_GET['id'] ) )
  411. {
  412. $this->villagesLinkPostfix .= "villagesLinkPostfix";
  413. }
  414. if ( isset( $_GET['p'] ) )
  415. {
  416. $this->villagesLinkPostfix .= "villagesLinkPostfix";
  417. }
  418. if ( 0 < $this->selectedTabIndex )
  419. {
  420. $this->villagesLinkPostfix .= "villagesLinkPostfix";
  421. }
  422. }
  423. public function getNextLink( )
  424. {
  425. $text = "Âť";
  426. if ( $this->pageIndex + 1 == $this->pageCount )
  427. {
  428. return $text;
  429. }
  430. $link = "";
  431. if ( 0 < $this->selectedTabIndex )
  432. {
  433. $link .= "t=".$this->selectedTabIndex;
  434. }
  435. if ( $link != "" )
  436. {
  437. $link .= "&";
  438. }
  439. $link .= "p=".( $this->pageIndex + 1 );
  440. $link = "report.php?".$link;
  441. return "<a href=\"".$link."\">".$text."</a>";
  442. }
  443. public function getPreviousLink( )
  444. {
  445. $text = "ÂŤ";
  446. if ( $this->pageIndex == 0 )
  447. {
  448. return $text;
  449. }
  450. $link = "";
  451. if ( 0 < $this->selectedTabIndex )
  452. {
  453. $link .= "t=".$this->selectedTabIndex;
  454. }
  455. if ( 1 < $this->pageIndex )
  456. {
  457. if ( $link != "" )
  458. {
  459. $link .= "&";
  460. }
  461. $link .= "p=".( $this->pageIndex - 1 );
  462. }
  463. if ( $link != "" )
  464. {
  465. $link = "?".$link;
  466. }
  467. $link = "report.php".$link;
  468. return "<a href=\"".$link."\">".$text."</a>";
  469. }
  470. }
  471. $p = new GPage( );
  472. $p->run( );
  473. ?>