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