PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/find_training_partner2.php

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