PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/find_training_partner.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 290 lines | 232 code | 43 blank | 15 comment | 41 complexity | 6f60e3ec50a534a3d54670aa126fc8a8 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. session_start();
  3. unset($_SESSION['sql']);
  4. unset($_SESSION['sort']);
  5. unset($_SESSION['sqlOrder']);
  6. unset($_SESSION['sqlPart']);
  7. $page_name=basename($_SERVER['SCRIPT_FILENAME']);
  8. $IsPreserved = 'Y';
  9. $IsProcess = $_REQUEST['IsProcess'];
  10. $action = $_REQUEST['action'];
  11. $action_arr = array("getSrchResult");
  12. //############## Added By Chandan
  13. if(isset($_REQUEST['game_id'])){
  14. $_SESSION['game_id'] = $_REQUEST['game_id'];
  15. $game_id = $_SESSION['game_id'];
  16. }else{
  17. $game_id = $_SESSION['game_id'];
  18. }
  19. if(is_array($game_id)){
  20. $game_id = $game_id[0];
  21. $_SESSION['game_id'] = $game_id;
  22. }
  23. //############# Added By Chandan
  24. if(in_array($action,$action_arr))
  25. {
  26. $IsProcess = 'Y';
  27. }
  28. include("general_include.php");
  29. $username = $_REQUEST['unm'];
  30. $sort_by = $_REQUEST['sorting_by'];
  31. $list_for = $_REQUEST['list_for'];
  32. //$availability_country = $_REQUEST['availability_country'];
  33. $availability_city = $_REQUEST['availability_city'];
  34. $language_id = $_REQUEST['language_id'];
  35. if($language_id == '')
  36. $language_id = array();
  37. //if($price == '')
  38. // $price = '0;100';
  39. //$prop_id = $_REQUEST['prop_id'];
  40. if(isset($_REQUEST['prop_id'])){
  41. $prop_id = $_REQUEST['prop_id'];
  42. $_SESSION['prop_id'] = $prop_id;
  43. }else{
  44. $prop_id = $_SESSION['prop_id'];
  45. }
  46. if($prop_id == '')
  47. $prop_id = array();
  48. if(count($prop_id)>0&& is_array($prop_id)&& !empty($prop_id)){
  49. $prop_ids = implode(',',$prop_id);
  50. $smarty->assign('prop_ids',$prop_ids);
  51. $sqlPart .= " AND u.user_id IN (SELECT user_id FROM nk_user_game_property WHERE ";// 1=1 property_id IN ($prop_ids))";
  52. $aux = "";
  53. $numProps = count($prop_id);
  54. for ($i = 0; $i <= $numProps; $i++) {
  55. $id = $prop_id[$i];
  56. $aux .= $aux.$i==0?"":" AND "." property_id = ".$id;
  57. }
  58. $sqlPart .= $aux;
  59. logToFile($sqlPart);
  60. }
  61. if(count($language_id)>0&& is_array($language_id)&& !empty($language_id))
  62. {
  63. $language_ids = implode(',',$language_id);
  64. $smarty->assign('languages',$language_ids);
  65. foreach($language_id as $val)
  66. $sqlPart .= " AND FIND_IN_SET($val,u.language_ids)";
  67. }
  68. if(count($availability)>0&& is_array($availability)&& !empty($availability))
  69. {
  70. $availabilitys = implode(',',$availability);
  71. $smarty->assign('availabilitys',$availabilitys);
  72. foreach($availability as $val)
  73. $sqlPart .= " AND FIND_IN_SET('$val',u.availability_type)";
  74. }
  75. /*if(!empty($availability_country))
  76. {
  77. $sqlPart .= " AND u.availability_country ='$availability_country'";
  78. }*/
  79. if(!empty($availability_city))
  80. {
  81. $sqlPart .= " AND u.availability_city ='$availability_city'";
  82. }
  83. if(!empty($username))
  84. {
  85. $sqlPart .= " AND u.name like '$username%'";
  86. }
  87. if($IsProcess <> 'Y')
  88. {
  89. include "top.php";
  90. }
  91. if($game_id==''|| empty($game_id)){
  92. $Sql = "SELECT * FROM ".TABLEPREFIX."_game WHERE is_default=1";
  93. $idRow = $UserManagerObjAjax->GetRecords("Row",$Sql);
  94. $game_id = $idRow['game_id'];
  95. }
  96. $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE game_id='$game_id'";
  97. $gamerow = $UserManagerObjAjax->GetRecords("Row",$GameSql);
  98. $game_id = $gamerow['game_id'];
  99. $game_name = $gamerow['game_name'];
  100. function findlanguage($language_id){
  101. if($language_id=='')
  102. return false;
  103. $SelectTypeSql = "SELECT language_name FROM ".TABLEPREFIX."_language WHERE language_id=$language_id";
  104. $SelectType = mysql_fetch_array(mysql_query($SelectTypeSql));
  105. return $SelectType[0];
  106. }
  107. function findvalue($table,$fld_name,$fld_value,$find_value){
  108. if($fld_value=='')
  109. return false;
  110. $SelectTypeSql = "SELECT ".$find_value." FROM ".$table." WHERE $fld_name=".$fld_value;
  111. $SelectType = mysql_fetch_array(mysql_query($SelectTypeSql));
  112. return $SelectType[0];
  113. }
  114. $record_per_page = !empty($record_per_page)?$record_per_page:15;
  115. $paginationObj = new PaginationClassFrontAjax($record_per_page,3,1,'Next','Previous');
  116. if($list_for == 'sorting')
  117. {
  118. $sortBy = explode('-',$sort_by);
  119. if($sortBy[0] == 'rating')
  120. {
  121. if($sortBy[1]=="DESC")
  122. $sqlPart.=" ORDER BY ur.overall_rating DESC,u.name ASC";
  123. else
  124. $sqlPart.=" ORDER BY ur.overall_rating ASC,u.name ASC";
  125. }
  126. }
  127. else
  128. $sqlPart.=" ORDER BY u.date_registered DESC";
  129. $SelectcoachSQL="SELECT DISTINCT u.*,ur.*,ug.* FROM ".TABLEPREFIX."_user u ,".TABLEPREFIX."_user_type_user_relation ur ,
  130. ".TABLEPREFIX."_user_game ug WHERE ur.user_type_id=3 and ur.user_id=u.user_id and u.is_active='Y' and ug.user_id=u.user_id
  131. and ug.game_id=$game_id and ug.is_active='Y' and ug.user_type_id=3".$sqlPart;
  132. $pagination_arr = $paginationObj->PaginationFrontAjaxALL('PaginationSearch',$SelectcoachSQL,$page_name.'?'.$catLink);
  133. $CoachArr=$UserManagerObjAjax->GetRecords("All",$pagination_arr[0]);
  134. //echo $pagination_arr[0];
  135. $friendsSql = "SELECT * FROM ".TABLEPREFIX."_user_friends_list WHERE friend_status = 2 AND (nk_user_id_owner='".$_SESSION['user_id']."' or nk_user_id_friend='".$_SESSION['user_id']."')";
  136. $friendsArr = $UserManagerObjAjax->GetRecords("All",$friendsSql);
  137. $NumCoach=count($CoachArr);
  138. $gameCategoriesSql = "SELECT * FROM ".TABLEPREFIX."_game_categories WHERE game_id=".$game_id;
  139. $gameCategoriesArr = $UserManagerObjAjax->GetRecords("All",$gameCategoriesSql);
  140. $NumGameCategories=count($gameCategoriesArr);
  141. for($i=0;$i<$NumCoach;$i++){
  142. $coach_id = $CoachArr[$i]['user_id'];
  143. $CoachArr[$i]['isfriend'] = "n";//count($friendsArr)." | ".$coach_id." || ";
  144. for($t=0;$t<count($friendsArr);$t++){
  145. if($friendsArr[$t]['nk_user_id_friend'] == $coach_id || $friendsArr[$t]['nk_user_id_owner'] == $coach_id){
  146. $CoachArr[$i]['isfriend'] = "y";
  147. break;
  148. }
  149. }
  150. $CoachArr[$i]['status'] = getUserStatus($CoachArr[$i]);
  151. $CoachArr[$i]['name']=show_to_control($CoachArr[$i]['name']);
  152. // $CoachArr[$i]['about']=show_to_control($CoachArr[$i]['user_about']);
  153. $Clanguage = explode(",",$CoachArr[$i]['language_ids']);
  154. $language='';
  155. for($l=0;$l<count($Clanguage);$l++)
  156. {
  157. if($Clanguage[$l]<>'')
  158. $language .=findlanguage($Clanguage[$l]).' , ';
  159. }
  160. $CoachArr[$i]['language']=substr($language,0,-2);
  161. $CoachArr[$i]['rating']=substr($rating,0,-2);
  162. $CoachArr[$i]['overall_rating']=number_format($CoachArr[$i]['overall_rating'], 1, '.', '');
  163. for($x=0; $x<$NumGameCategories; $x++){
  164. $userCategoriesPropSql = "SELECT * FROM ".TABLEPREFIX."_user_game_property p, nk_game_categories_properties c WHERE p.user_type_id = 3 AND p.user_id='".$coach_id."' AND p.user_type_id = 3
  165. AND p.category_id = ".$gameCategoriesArr[$x]['category_id']." AND c.property_id = p.property_id";
  166. $userCategoriesPropArr = $UserManagerObjAjax->GetRecords("All",$userCategoriesPropSql);
  167. $NumuserCategoriesProp=count($userCategoriesPropArr);
  168. $prop ='';
  169. for($y=0; $y<$NumuserCategoriesProp; $y++){
  170. $prop .= (($y > 0)?', ':'').$userCategoriesPropArr[$y]['property_name'];
  171. }
  172. $gameCategoriesArr[$x]['properties'] = $prop;
  173. }
  174. $CoachArr[$i]['categoriesArr'] = $gameCategoriesArr;
  175. $avail_type = explode(',',$CoachArr[$i]['availability_type']);
  176. if($avail_type[1]=='')
  177. {
  178. if($avail_type[0]=='O')
  179. $CoachArr[$i]['availability_type'] = 'Online';
  180. if($avail_type[0]=='L')
  181. {
  182. $CoachArr[$i]['availability_type'] = 'Local meet-up';
  183. $CoachArr[$i]['avail_local'] = 'Y';
  184. }
  185. }
  186. else
  187. {
  188. $CoachArr[$i]['availability_type'] = 'Online , Local meet-up';
  189. $CoachArr[$i]['avail_local'] = 'Y';
  190. }
  191. $CoachArr[$i]['availability_country'] = findvalue(TABLEPREFIX."_country","country_id",$CoachArr[$i]['availability_country'],"country_name");
  192. $CoachArr[$i]['availability_city'] = findvalue(TABLEPREFIX."_cities","city_id",$CoachArr[$i]['availability_city'],"city_key");
  193. $Sql_overall_tooptip="select rating_overall_tooltip from ".TABLEPREFIX."_default_comision";
  194. $overall_tooptip=$UserManagerObjAjax->GetRecords("Row",$Sql_overall_tooptip);
  195. $CoachArr[$i]['rating_overall_tooltip']=html_entity_decode($overall_tooptip['rating_overall_tooltip']);
  196. $totalReviewSql = "SELECT count(*) FROM ".TABLEPREFIX."_user_review WHERE user_id=".$CoachArr[$i]['user_id']." AND user_type_id=3";
  197. $totalR = $UserManagerObjAjax->GetRecords("Row",$totalReviewSql);
  198. $CoachArr[$i]['totalReview'] = $totalR[0];
  199. $Sql_Individual="select avg(rat.rating) as tot,rat.rcat_id,cat.rating_category,cat.rating_category_tooltip from ".TABLEPREFIX."_user_rating as rat,".TABLEPREFIX."_user_review as rev,".TABLEPREFIX."_rating_category as cat where rat.rcat_id=cat.rcat_id and rat.user_review_id=rev.user_review_id and rev.user_id=".$CoachArr[$i]['user_id']." and rev.user_type_id=3 group by rat.rcat_id";
  200. $Individual=$UserManagerObjAjax->GetRecords("All",$Sql_Individual);
  201. for($j=0;$j<count($Individual);$j++){
  202. $CatIndividualRec[$i][$j]['rating']=number_format($Individual[$j]['tot'], 1, '.', '');
  203. $CatIndividualRec[$i][$j]['rcat_id']=$Individual[$j]['rcat_id'];
  204. $CatIndividualRec[$i][$j]['rating_category']=$Individual[$j]['rating_category'];
  205. $CatIndividualRec[$i][$j]['rating_category_tooltip']=html_entity_decode($Individual[$j]['rating_category_tooltip']);
  206. }
  207. /*echo '<pre>';
  208. print_r($CatIndividualRec);*/
  209. }
  210. $city = findvalue(TABLEPREFIX."_cities","city_id",$availability_city,"city_key");
  211. $gameSql = "SELECT game_id,game_name FROM ".TABLEPREFIX."_game where status=1 ORDER BY game_name";
  212. $GameArr = $UserManagerObjAjax->HtmlOptionArrayCreate($gameSql);
  213. //print_r($ladder_id);
  214. $smarty->assign('prop_id',$prop_id);
  215. $smarty->assign('username',$username);
  216. $smarty->assign('rating_id',$rating_id);
  217. $smarty->assign('language_id',$language_id);
  218. $smarty->assign('availability',$availability);
  219. $smarty->assign("SearchTxt",$SearchTxt);
  220. $smarty->assign("GameArr",$GameArr);
  221. $smarty->assign('page_name',$page_name);
  222. $smarty->assign('sort_by',$sort_by);
  223. $smarty->assign('game_id',$game_id);
  224. $smarty->assign('game_name',$game_name);
  225. $smarty->assign('Numladder',$Numladder);
  226. $smarty->assign('LadderArr',$LadderArr);
  227. $smarty->assign('Numrace',$Numrace);
  228. $smarty->assign('RaceArr',$RaceArr);
  229. $smarty->assign('city',$city);
  230. $smarty->assign('cityid',$availability_city);
  231. $smarty->assign('availability_country',$availability_country);
  232. $smarty->assign('availability_city',$availability_city);
  233. $smarty->assign('Numserver',$Numserver);
  234. $smarty->assign('ServerArr',$ServerArr);
  235. $smarty->assign('Numlanguage',$Numlanguage);
  236. $smarty->assign('LangArr',$LangArr);
  237. $smarty->assign('StarArr',$StarArr);
  238. $smarty->assign("CoachArr",$CoachArr);
  239. $smarty->assign('pagination_arr',$pagination_arr);
  240. $smarty->assign("NumCoach",$NumCoach);
  241. $smarty->assign("CatIndividualRec",$CatIndividualRec);
  242. if($IsProcess <> 'Y')
  243. include "training_partner_leftpanel.php";
  244. $smarty->display('find_training_partner.tpl');
  245. if($IsProcess <> 'Y')
  246. include "footer.php";
  247. ?>