PageRenderTime 29ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/search.php

https://github.com/darkzmii/SuperNova
PHP | 126 lines | 107 code | 5 blank | 14 comment | 8 complexity | ef71b62a4817462186b3daf355032f59 MD5 | raw file
  1. <?php
  2. /**
  3. * search.php
  4. *
  5. * 1.3 copyright (c) 2009-2010 by Gorlum for http://supernova.ws
  6. * [%] Fixed search of players without alliance
  7. * 1.2 - Security checks & tests by Gorlum for http://supernova.ws
  8. * @version 1.1
  9. * @copyright 2009 by angelus_ira for Project. XNova
  10. * @copyright 2008 by ??????? for XNova
  11. */
  12. include('common.' . substr(strrchr(__FILE__, '.'), 1));
  13. $searchtext = mysql_real_escape_string($_POST['searchtext']);
  14. $type = sys_get_param_str('type');
  15. $dpath = (!$user["dpath"]) ? DEFAULT_SKINPATH : $user["dpath"];
  16. lng_include('search');
  17. $i = 0;
  18. //creamos la query
  19. switch($type){
  20. case "playername":
  21. $table = gettemplate('search_user_table');
  22. $row = gettemplate('search_user_row');
  23. $sql = "SELECT
  24. u.id as uid, u.username, u.ally_id, u.id_planet,
  25. p.*, p.name as planet_name,
  26. s.total_points, s.total_rank,
  27. a.ally_tag, a.ally_name
  28. FROM {{table}}planets as p,
  29. {{table}}statpoints as s,
  30. {{table}}users as u LEFT JOIN {{table}}alliance as a ON a.id = u.ally_id
  31. WHERE
  32. username LIKE '%{$searchtext}%'
  33. AND p.id_owner = u.id AND p.id=u.id_planet
  34. AND s.id_owner = u.id AND stat_type = 1 AND stat_code = 1 LIMIT 30;";
  35. $search = doquery($sql, '');
  36. break;
  37. case "planetname":
  38. $table = gettemplate('search_user_table');
  39. $row = gettemplate('search_user_row');
  40. $sql = "SELECT
  41. p.*, p.name as planet_name,
  42. u.id as uid, u.username, u.ally_id, u.id_planet,
  43. s.total_points, s.total_rank,
  44. a.ally_tag, a.ally_name
  45. FROM {{table}}planets as p,
  46. {{table}}users as u,
  47. {{table}}alliance as a,
  48. {{table}}statpoints as s
  49. WHERE
  50. name LIKE '%{$searchtext}%'
  51. AND u.id=p.id_owner
  52. AND a.id = u.ally_id
  53. AND s.id_owner = p.id_owner AND stat_type = 1 AND stat_code = 1 LIMIT 30;";
  54. $search = doquery($sql, '');
  55. break;
  56. case "allytag":
  57. $table = gettemplate('search_ally_table');
  58. $row = gettemplate('search_ally_row');
  59. $search = doquery("SELECT * FROM {{table}}alliance inner join {{table}}statpoints on {{table}}alliance.`id`={{table}}statpoints.`id_owner` WHERE ally_tag LIKE '%{$searchtext}%' AND STAT_type=2 LIMIT 30",'');
  60. break;
  61. case "allyname":
  62. $table = gettemplate('search_ally_table');
  63. $row = gettemplate('search_ally_row');
  64. $search = doquery("SELECT * FROM {{table}}alliance inner join {{table}}statpoints on {{table}}alliance.`id`={{table}}statpoints.`id_owner` WHERE ally_name LIKE '%{$searchtext}%' AND STAT_type=2 LIMIT 30",'');
  65. break;
  66. default:
  67. $table = gettemplate('search_user_table');
  68. $row = gettemplate('search_user_row');
  69. $sql = "SELECT
  70. u.id as uid, u.username, u.ally_id, u.id_planet,
  71. p.*, p.name as planet_name,
  72. s.total_points, s.total_rank,
  73. a.ally_tag, a.ally_name
  74. FROM {{table}}users as u,
  75. {{table}}planets as p,
  76. {{table}}alliance as a,
  77. {{table}}statpoints as s
  78. WHERE
  79. username LIKE '%{$searchtext}%'
  80. AND p.id_owner = u.id AND p.id=u.id_planet
  81. AND a.id = u.ally_id
  82. AND s.id_owner = u.id AND stat_type = 1 AND stat_code = 1 LIMIT 30;";
  83. $search = doquery($sql, '');
  84. }
  85. if(isset($searchtext) && isset($type)){
  86. while($r = mysql_fetch_assoc($search)){
  87. if($type=='playername'||$type=='planetname'){
  88. $s=$r;
  89. //para obtener el nombre del planeta
  90. $s['ally_name'] = ($s['ally_name']!='')?"<a href=\"alliance.php?mode=ainfo&tag={$s['ally_tag']}\">{$s['ally_name']}</a>":'';
  91. $s['position'] = "<a href=\"stat.php?start=".$s['total_rank']."\">".$s['total_rank']."</a>";
  92. $s['dpath'] = $dpath;
  93. $s['coordinated'] = "{$s['galaxy']}:{$s['system']}:{$s['planet']}";
  94. $s['buddy_request'] = $lang['buddy_request'];
  95. $s['write_a_messege'] = $lang['write_a_messege'];
  96. $s['u_id'] = $s[uid];
  97. $result_list .= parsetemplate($row, $s);
  98. }elseif($type=='allytag'||$type=='allyname'){
  99. $s=$r;
  100. $s['ally_points'] = pretty_number($s['total_points']);
  101. $s['ally_tag'] = "<a href=\"alliance.php?mode=ainfo&tag={$s['ally_tag']}\">{$s['ally_tag']}</a>";
  102. $result_list .= parsetemplate($row, $s);
  103. }
  104. }
  105. if($result_list!=''){
  106. $lang['result_list'] = $result_list;
  107. $search_results = parsetemplate($table, $lang);
  108. }
  109. }
  110. //el resto...
  111. $lang['type_playername'] = ($type == "playername") ? " SELECTED" : "";
  112. $lang['type_planetname'] = ($type == "planetname") ? " SELECTED" : "";
  113. $lang['type_allytag'] = ($type == "allytag") ? " SELECTED" : "";
  114. $lang['type_allyname'] = ($type == "allyname") ? " SELECTED" : "";
  115. $lang['searchtext'] = $searchtext;
  116. $lang['u_id'] = $r[uid];
  117. $lang['search_results'] = $search_results;
  118. //esto es algo repetitivo ... w
  119. $page = parsetemplate(gettemplate('search_body'), $lang);
  120. display($page,$lang['Search']);
  121. ?>