spacecp_search.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: spacecp_search.php 28292 2012-02-27 07:23:14Z monkey $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. $myfields = array('uid','gender','birthyear','birthmonth','birthday','birthprovince','birthcity','resideprovince','residecity', 'residedist', 'residecommunity');
  12. loadcache('profilesetting');
  13. $fields = array();
  14. foreach ($_G['cache']['profilesetting'] as $key => $value) {
  15. if($value['title'] && $value['available'] && $value['allowsearch'] && !in_array($key, $myfields)) {
  16. $fields[$value['fieldid']] = $value;
  17. }
  18. }
  19. $nowy = dgmdate($_G['timestamp'], 'Y');
  20. $_GET = daddslashes($_GET);
  21. if(!empty($_GET['searchsubmit']) || !empty($_GET['searchmode'])) {
  22. $_GET['searchsubmit'] = $_GET['searchmode'] = 1;
  23. $wherearr = $fromarr = $uidjoin = array();
  24. $fsql = '';
  25. $fromarr['member'] = DB::table('common_member').' s';
  26. if($searchkey = stripsearchkey($_GET['searchkey'])) {
  27. $wherearr[] = 's.'.DB::field('username', $searchkey);
  28. $searchkey = dhtmlspecialchars($searchkey);
  29. } else {
  30. foreach (array('uid','username','videophotostatus','avatarstatus') as $value) {
  31. if($_GET[$value]) {
  32. if($value == 'username' && empty($_GET['precision'])) {
  33. $_GET[$value] = stripsearchkey($_GET[$value]);
  34. $wherearr[] = 's.'.DB::field($value, '%'.$_GET[$value].'%', 'like');
  35. } else {
  36. $wherearr[] = 's.'.DB::field($value, $_GET[$value]);
  37. }
  38. }
  39. }
  40. }
  41. $startage = $endage = 0;
  42. if($_GET['endage']) {
  43. $startage = $nowy - intval($_GET['endage']);
  44. }
  45. if($_GET['startage']) {
  46. $endage = $nowy - intval($_GET['startage']);
  47. }
  48. if($startage && $endage && $endage > $startage) {
  49. $wherearr[] = 'sf.'.DB::field('birthyear', $startage, '>=').' AND sf.'.DB::field('birthyear', $endage, '<=');
  50. } else if($startage && empty($endage)) {
  51. $wherearr[] = 'sf.'.DB::field('birthyear', $startage, '>=');
  52. } else if(empty($startage) && $endage) {
  53. $wherearr[] = 'sf.'.DB::field('birthyear', $endage, '<=');
  54. }
  55. $havefield = 0;
  56. foreach ($myfields as $fkey) {
  57. $_GET[$fkey] = trim($_GET[$fkey]);
  58. if($_GET[$fkey]) {
  59. $havefield = 1;
  60. $wherearr[] = 'sf.'.DB::field($fkey, $_GET[$fkey]);
  61. }
  62. }
  63. foreach ($fields as $fkey => $fvalue) {
  64. $_GET['field_'.$fkey] = empty($_GET['field_'.$fkey])?'':stripsearchkey($_GET['field_'.$fkey]);
  65. if($_GET['field_'.$fkey]) {
  66. $havefield = 1;
  67. $wherearr[] = 'sf.'.DB::field($fkey, '%'.$_GET['field_'.$fkey].'%', 'like');
  68. }
  69. }
  70. if($havefield || $startage || $endage) {
  71. $fromarr['profile'] = DB::table('common_member_profile').' sf';
  72. $wherearr['profile'] = "sf.uid=s.uid";
  73. }
  74. $list = array();
  75. if($wherearr) {
  76. $space['friends'] = array();
  77. $query = C::t('home_friend')->fetch_all_by_uid($_G['uid'], 0, 0);
  78. foreach($query as $value) {
  79. $space['friends'][$value['fuid']] = $value['fuid'];
  80. }
  81. foreach(C::t('common_member')->fetch_all_for_spacecp_search($wherearr, $fromarr, 0, 100) as $value) {
  82. $value['isfriend'] = ($value['uid']==$space['uid'] || $space['friends'][$value['uid']])?1:0;
  83. $list[$value['uid']] = $value;
  84. }
  85. $follows = C::t('home_follow')->fetch_all_by_uid_followuid($_G['uid'], array_keys($list));
  86. foreach($list as $uid => $value) {
  87. $list[$uid]['follow'] = isset($follows[$uid]) ? 1 : 0;
  88. }
  89. }
  90. } else {
  91. $yearhtml = '';
  92. for ($i=0; $i<50; $i++) {
  93. $they = $nowy - $i;
  94. $yearhtml .= "<option value=\"$they\">$they</option>";
  95. }
  96. $sexarr = array($space['sex']=>' checked=\"checked\"');
  97. $birthyeayhtml = '';
  98. for ($i=0; $i<100; $i++) {
  99. $they = $nowy - $i;
  100. if(empty($_GET['all'])) $selectstr = $they == $space['birthyear']?' selected=\"selected\"':'';
  101. $birthyeayhtml .= "<option value=\"$they\"$selectstr>$they</option>";
  102. }
  103. $birthmonthhtml = '';
  104. for ($i=1; $i<13; $i++) {
  105. if(empty($_GET['all'])) $selectstr = $i == $space['birthmonth']?' selected=\"selected\"':'';
  106. $birthmonthhtml .= "<option value=\"$i\"$selectstr>$i</option>";
  107. }
  108. $birthdayhtml = '';
  109. for ($i=1; $i<29; $i++) {
  110. if(empty($_GET['all'])) $selectstr = $i == $space['birthday']?' selected=\"selected\"':'';
  111. $birthdayhtml .= "<option value=\"$i\"$selectstr>$i</option>";
  112. }
  113. $bloodhtml = '';
  114. foreach (array('A','B','O','AB') as $value) {
  115. if(empty($_GET['all'])) $selectstr = $value == $space['blood']?' selected=\"selected\"':'';
  116. $bloodhtml .= "<option value=\"$value\"$selectstr>$value</option>";
  117. }
  118. $marryarr = array($space['marry'] => ' selected');
  119. include_once libfile('function/profile');
  120. $birthcityhtml = showdistrict(array(0,0), array('birthprovince', 'birthcity'), 'birthcitybox', null, 'birth');
  121. $residecityhtml = showdistrict(array(0,0, 0, 0), array('resideprovince', 'residecity', 'residedist', 'residecommunity'), 'residecitybox', null, 'reside');
  122. foreach ($fields as $fkey => $fvalue) {
  123. if(empty($fvalue['choices'])) {
  124. $fvalue['html'] = '<input type="text" name="field_'.$fkey.'" class="px" value="" />';
  125. } else {
  126. $fvalue['html'] = "<select name=\"field_$fkey\"><option value=\"\">---</option>";
  127. $optionarr = explode("\n", $fvalue['choices']);
  128. foreach ($optionarr as $ov) {
  129. $ov = trim($ov);
  130. if($ov) {
  131. $fvalue['html'] .= "<option value=\"$ov\">$ov</option>";
  132. }
  133. }
  134. $fvalue['html'] .= "</select>";
  135. }
  136. $fields[$fkey] = $fvalue;
  137. }
  138. }
  139. $navtitle = lang('core', 'title_search_friend');
  140. $actives = array($op=>' class="a"', 'search'=>' class="a"');
  141. include template('home/spacecp_search');
  142. ?>