HomeHelpTrac

source: tags/6.1/browse.php @ 10242

Revision 10242, 11.0 KB checked in by Alexander Trofimov, 3 years ago (diff)

dolphin 6.1.5, initial commit

Line 
1<?
2
3/***************************************************************************
4*                            Dolphin Smart Community Builder
5*                              -----------------
6*     begin                : Mon Mar 23 2006
7*     copyright            : (C) 2006 BoonEx Group
8*     website              : http://www.boonex.com/
9* This file is part of Dolphin - Smart Community Builder
10*
11* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
12* http://creativecommons.org/licenses/by/3.0/
13*
14* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16* See the Creative Commons Attribution 3.0 License for more details.
17* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
18* see license.txt file; if not, write to marketing@boonex.com
19***************************************************************************/
20
21
22require_once( 'inc/header.inc.php' );
23require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
24require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );
25
26$_page['name_index'] = 60;
27$_page['header'] = _t("_Browse Profiles", $site['title']);
28$_page['header_text'] = _t("_Browse Profiles");
29$_page['css_name'] = 'browse.css';
30
31check_logged();
32
33// ================================================ parse variables ================
34// =================================================================================
35
36    foreach( $_GET as $key => $value )
37    {
38        if ( 'sex' == substr($key,0,3) )
39            $sex_sel .= $value . ',';
40        else if ( 'country' == $key )
41            $country_sel = $value;
42        else if ( 'age' == substr($key,0,3) )
43        {
44            if ( 'start' == substr($key,4) )
45                $age_start_sel = (int)$value;
46
47            if ( 'end' == substr($key,4) )
48                $age_end_sel = (int)$value;
49        }
50        else if ( 'online_only' == $key )
51            $onl_only = 'on';
52        else if ( 'photo_only' == $key )
53            $pic_only = 'on';
54    }
55
56
57// =================================================================================
58// =================================================================================
59
60$_ni = $_page['name_index'];
61$_page_cont[$_ni]['page_main_code'] = PageCompPageMainCode();
62
63
64PageCode();
65
66
67function PageCompPageMainCode()
68{
69    global $sex_sel;
70    global $country_sel;
71    global $age_start_sel;
72    global $age_end_sel;
73    global $onl_only;
74    global $pic_only;
75
76    global $site;
77
78    global $p_num;
79    global $page;
80    global $pages_num;
81    global $p_per_page;
82    global $page_first_p;
83    global $pages_num;
84
85    global $search_start_age;
86    global $search_end_age;
87    global $max_thumb_width;
88    global $max_thumb_height;
89   
90   
91    $sex_options = makeCheckbox( 'sex', 'Sex', ( $sex_sel ? $sex_sel : 'male,female' ) );
92    $country_options = makeList( 'country', '' , 'Country', ( $country_sel ? $country_sel : 'all' ), 'onchange="javascript: flagImage = document.getElementById(\'flagImageId\'); if (this.value == \'all\') {flagImage.src = \''. $site['images'] .'spacer.gif\';} else {flagImage.src = \''. $site['flags'] .'\' + this.value.toLowerCase() + \'.gif\';}"' );
93   
94    $age_start_sel = $age_start_sel ? $age_start_sel : $search_start_age;
95    $age_end_sel = $age_end_sel ? $age_end_sel : $search_end_age;
96
97    $age_option_start = makeList( 'age_start', "{$search_start_age}-{$search_end_age}", '', $age_start_sel);
98    $age_option_end = makeList( 'age_end', "{$search_start_age}-{$search_end_age}", '', $age_end_sel);
99
100    $photo_only_check = '<input type="checkbox" name="photo_only" id="photo_only_id" ' . ( $pic_only ? 'checked="checked"' : '' ) . ' /><label for="photo_only_id"><b>' . _t('_With photos only') . '</b></label>';
101    $online_only_check = '<input type="checkbox" name="online_only" id="online_only_id" ' . ( $onl_only ? 'checked="checked"' : '' ) . ' /><label for="online_only_id"><b>' . _t('_online only') . '</b></label>';
102
103    $country_def_flag = strlen($country_sel) == 0 || $country_sel == 'all' ? $site['images'].'spacer.gif' : $site['flags'] . strtolower($country_sel).'.gif';
104
105    $ret = '
106        <form id="browse_form" action="' . $_SERVER['PHP_SELF'] . '" method="get">
107            <div class="browse_form_wrapper">
108           
109                <div class="browse_form_row">
110                    <div class="clear_both"></div>
111                        <div class="label">' . _t('_Sex') . ':</div>
112                        <div class="value">' . $sex_options .'</div>
113                    <div class="clear_both"></div>
114                </div>
115               
116                <div class="browse_form_row">
117                    <div class="clear_both"></div>
118                        <div class="label">' . _t('_DateOfBirth') . ':</div>
119                        <div class="value">' .
120                            _t("_from") . '&nbsp;' . $age_option_start .    '&nbsp;' . _t("_to") . '&nbsp;' . $age_option_end .
121                        '</div>
122                    <div class="clear_both"></div>
123                </div>
124
125                <div class="browse_form_row">
126                    <div class="clear_both"></div>
127                        <div class="label">' . _t('_Country') . ':</div>'.
128                        '<div class="value">' .
129                            $country_options .'&nbsp;<img id="flagImageId" src="'. $country_def_flag .'" alt="flag" />
130                        </div>
131                    <div class="clear_both"></div>
132                </div>
133
134                <div class="only">
135                    ' . $photo_only_check . '
136                    ' . $online_only_check . '
137                </div>
138
139                <div class="submit">
140                    <input id="search" name="search" type="submit" value="'. _t('_Show') .'" />
141                </div>
142
143            </div>
144        </form>
145        ';
146
147
148//====================================================================================================
149//----------------------- search results -------------------------------------------------
150//====================================================================================================
151
152
153    $page = (int)$_GET[page];
154    $p_per_page = (int)$_GET[p_per_page];
155
156    $aVar = array(30,60,90);
157    if ( !$page )
158    $page = 1;
159
160    if ( !$p_per_page )
161        $p_per_page = 30;
162
163    $real_first_p = (int)($page - 1) * $p_per_page;
164    $page_first_p = $real_first_p + 1;
165
166
167    $temp_arr = explode(',', $sex_sel);
168    foreach ( $temp_arr as $value )
169        if ( $value ) {
170            $value = process_db_input( $value );
171            $sex_add .= " `Sex` = '$value' OR ";
172        }
173
174
175    if ( $country_sel && 'all' != $country_sel ) {
176        $country_sel = process_db_input( $country_sel );
177        $country_add = " `Country` = '{$country_sel}' AND ";
178    }
179
180
181    if ( $age_start_sel )
182        //$age_add .= " ( (YEAR(NOW()) - {$age_start_sel}) >= YEAR(`DateofBirth`) ) AND ";
183        $age_add .= " DATEDIFF( NOW(), `Profiles`.`DateOfBirth` ) >= ". ($age_start_sel * 365.25) ." AND ";
184
185
186
187    if ( $age_end_sel )
188        //$age_add .= " ( (YEAR(NOW()) - {$age_end_sel}) <= YEAR(`DateofBirth`) ) AND ";
189        $age_add .= " DATEDIFF( NOW(), `Profiles`.`DateOfBirth` ) <= " . ($age_end_sel * 365.25) . " AND ";
190
191    if ( $pic_only )
192        $pic_add = " AND `PrimPhoto` <> '0' ";
193    if ( $onl_only )
194        $onl_add = " AND (DateLastNav > SUBDATE(NOW(), INTERVAL " . getParam( "member_online_time" ) . " MINUTE)) ";
195
196
197    $sex_add = $sex_add ? '(' . $sex_add . ' 1=0 ) AND ' : '';
198    $age_add = $age_add ? '(' . $age_add . ' 1=1 )' : '';
199
200    $sql_add = $sex_add . $country_add . $age_add . $pic_add . $onl_add . " AND (`Profiles`.`Couple`='0' OR `Profiles`.`Couple`>`Profiles`.`ID`)";
201
202    $p_num = db_arr( "SELECT COUNT(*) FROM `Profiles` WHERE {$sql_add} AND `Profiles`.`Status` = 'Active'" );
203    $p_num = $p_num[0];
204    $pages_num = ceil( $p_num / $p_per_page );
205
206    $profiles_list_query = "SELECT `ID`, `NickName`, `Sex`, `DateOfBirth`, `Couple` FROM `Profiles` WHERE {$sql_add} AND `Profiles`.`Status`='Active' ORDER BY `Couple` ASC, `Picture` DESC LIMIT {$real_first_p}, {$p_per_page}";
207
208    $function = '
209            $ret = \'?\';
210            foreach ( $_GET as $key => $value )
211            if ( $value )
212                $ret .= $key . \'=\' . $value . \'&amp;\';
213
214            return $ret;
215        ';
216
217
218
219
220    $ret .= '<div id="container_result" style="border: 0px solid #000000">';
221
222    $ret .= '<div style="margin-bottom:10px;"><center>' . ResNavigationRet( 'ProfilesUpper', 0, $function, $aVar ) . '</center></div>';
223
224    if ( $p_num > 0)
225    {
226
227    $res = db_res( $profiles_list_query );
228    $iI = 1;
229    while ( $arr = mysql_fetch_array( $res ) )
230    {
231        //$user_is_online = get_user_online_status($arr['ID']);
232
233        $iNewWidth = 0;
234        if (isset($arr['Couple']) && $arr['Couple'] > 0) {
235            $iMaxThumbWidth = getParam('max_thumb_width');
236            $iNewWidth = 2 * ( $iMaxThumbWidth + 10 + 2 ) ;
237            //$templ = str_replace ( "__ext_st__", 'style="width:' . $iNewWidth . 'px;"', $templ );
238        } else {
239            $iMaxThumbWidth = getParam('max_thumb_width');
240            $iNewWidth = 1 * ( $iMaxThumbWidth +12 ) ;
241            //$templ = str_replace ( "__ext_st__", 'style="width:' . $iNewWidth . 'px;"', $templ );
242        }
243        $sWidthStyle = ($iNewWidth>0) ? 'style="width:'.$iNewWidth.'px;"' : '';
244
245        $cont = '<div class="browse_thumb" '.$sWidthStyle.'>';
246        //$cont .= getProfileOnlineStatus( $user_is_online ) . get_member_thumbnail($arr['ID'], 'none' ) . '<div class="browse_nick"><a href="' . getProfileLink($arr['ID']) . '">' . $arr['NickName'] . '</a></div></div>';
247        $cont .= get_member_thumbnail($arr['ID'], 'none', true ) . '<div class="browse_nick"><a href="' . getProfileLink($arr['ID']) . '">' . $arr['NickName'] . '</a></div></div>';
248        $ret .= $cont;
249        $iI++;
250        if( $iI > 6 )
251            $iI = 1;
252    }
253
254    }
255    else
256    {
257        $ret .= '<div class="no_result">';
258            $ret .= '<div>' . _t('_No results found') . '</div>';
259        $ret .= '</div>';
260    }
261
262
263    $ret .= '<div style="clear:both;margin-top:10px;"><center>' . ResNavigationRet( 'ProfilesLower', 0, $function, $aVar ) . '</center></div>';
264
265
266    $ret .= '</div>';
267
268
269    return $ret;
270
271}
272
273function makeCheckbox( $name, $sField, $sSelected ) {
274
275    $arr = getFieldValues( $sField );
276    $aSelected = explode(',', $sSelected);
277
278    $ret = '';
279    foreach ( $arr as $value => $lang_v ) {
280            $sel = ( in_array($value, $aSelected) ) ? 'checked="checked"' : '';
281
282            $ret .= "
283                <span>
284                    <input type=\"checkbox\" name=\"{$name}_{$value}\" id=\"{$name}_{$value}\" value=\"{$value}\" $sel />
285                </span>
286                <span>
287                    <label for=\"{$name}_{$value}\">" . _t($lang_v) . '</label>
288                </span>';
289    }
290
291    return $ret;
292}
293
294
295
296function makeList( $name, $digit_range, $sField, $selected='', $js='' )
297{
298    $ret = '';
299    $ret .= "<select id=\"$name\" name=\"$name\" $js>";
300
301    if ( $digit_range )
302    {
303        list($a, $b) = preg_split( "/[\.,\-]/", $digit_range);
304
305        for ( $i = $a; $i <= $b; $i++ )
306        {
307            if ( $selected && $selected == $i )
308                $sel = "selected=\"selected\"";
309            else
310                $sel = '';
311            $ret .= "<option value=\"$i\" $sel>$i</option>";
312        }
313    }
314    elseif ( $sField )
315    {
316        $arr = getFieldValues( $sField );
317        $arr = array_merge( array('all' => '__All'), $arr);
318
319        foreach ( $arr as $key => $value )
320        {
321            if ( $selected == $key )
322                $sel = "selected=\"selected\"";
323            else
324                $sel = '';
325
326            $ret .= "<option value=\"$key\" $sel>". _t($value) ."</option>";
327        }
328    }
329    else
330        return false;
331
332    $ret .= '</select>';
333
334    return $ret;
335}
336
337?>
Note: See TracBrowser for help on using the repository browser.