root/trunk/inc/search.inc.php

Revision 15, 4.7 KB (checked in by alexx, 7 years ago)
  • fix last bug in communities (see [14])
  • execute a "conversion smarty style" script ;) : for i in find . -type f | grep "\.php$" | grep -v "\.svn"; do perl -pi -e "s/\\\$smarty->assign\((.*),(.*)\);/\\\$_SMARTY\[\$1\] = \$2;/" $i; done
Line 
1<?php
2/****************************************************** Open .node ***
3 * Description:   
4 * Status:        Stable.
5 * Author:        Alexandre Dath <alexandre@dotnode.com>
6 * $Id$
7 *
8 * Copyright (C) 2005 Alexandre Dath <alexandre@dotnode.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 ******************** http://opensource.ikse.net/projects/dotnode ***/
24
25include(INCLUDESPATH.'/countries_list.inc.php');
26$labels['profile']['country'] = $db->getAssoc('SELECT DISTINCT country, country  FROM user_contact');
27$_SMARTY['Title'] =  'Find your soul mate';
28
29$pagination['elmt_by_page'] = 20;
30
31if(is_numeric($token[1]) &&
32   $token[1] > 0 )
33        $pagination['current_page'] = $token[1];
34else
35        $pagination['current_page'] = 1;
36
37error_log($token[1]);
38
39$search = array(
40    'photo' => array ('y'=> _('only member with photo') ),
41);
42
43$idx=0;
44foreach($labels['profile']['here_for'] as $key=>$value)
45{
46    $search['here_for'][pow(2, $idx++)] = $value;
47}
48
49    $idx++;
50if(!is_numeric($_GET['search']['agemin']) && $_GET['search']['agemin'] < 1 && $_GET['search']['agemin'] > 99)
51    unset($_GET['search']['agemin']);
52elseif(is_numeric($_GET['search']['agemin']) )
53{
54    $where[] = 'age>=?';
55    $where_array[] = $_GET['search']['agemin'];
56}
57
58if(!is_numeric($_GET['search']['agemax']) && $_GET['search']['agemax'] < 1 && $_GET['search']['agemax'] > 99)
59        unset($_GET['search']['agemax']);
60elseif(is_numeric($_GET['search']['agemax']) )
61{
62        $where[] = 'age<=?';
63        $where_array[] = $_GET['search']['agemax'];
64}
65
66if($_GET['search']['country'] != "(null)" && $_GET['search']['country'] != "" && isset($_GET['search']['country']))
67{
68    $where[] = "country=?";
69    $where_array[] = $_GET['search']['country'];
70}
71
72if($_GET['search']['photo'][0] == 'y')
73{
74        $where[] = "photo=?";
75        $where_array[] = 'y';
76}
77
78
79if(count($_GET['search']['gender']) == 2)
80    unset($_GET['search']['gender']);
81if(count($_GET['search']['here_for']) == 4)
82        unset($_GET['search']['here_for']);
83if(count($_GET['search']['relationship_status']) == 3)
84        unset($_GET['search']['relationship_status']);
85
86$list_item = array('gender', 'relationship_status');
87
88foreach($list_item as $field)
89    if(is_array($_GET['search'][$field]))
90    {
91        $idx=0;
92        foreach($_GET['search'][$field] as $item)
93        {
94            $where_array[] = $_GET['search'][$field][$idx];
95            $idx++;
96        }
97        $where[] = $field.' IN ('.implode(',', @array_fill(0,count($_GET['search'][$field]), '?')).')';
98        unset($temp);
99    }
100
101if(is_array($_GET['search']['here_for']))
102{
103    $where[] = 'here_for=here_for|?';
104    $where_array[] = array_sum($_GET['search']['here_for']);
105}               
106
107
108
109if(is_array($where))
110{
111    $where_str = implode(' AND ', $where);
112
113    $pagination['nb_elements'] = $db->getOne('SELECT COUNT(id) FROM cache_user WHERE '.$where_str.'', $where_array);
114    $where_array[] = ($pagination['elmt_by_page'] - 1)  * $pagination['current_page'];
115    $where_array[] = $pagination['elmt_by_page'];
116    $r0 = $db->query('SELECT id, fname, lname, here_for, gender, country, relationship_status FROM cache_user WHERE '.$where_str.' ORDER BY join_date DESC LIMIT !,!', $where_array);
117}
118else
119    $r0 = $db->query('SELECT id, fname, lname, here_for, gender, country, relationship_status FROM cache_user WHERE photo=? ORDER BY join_date DESC LIMIT 20', 'y');
120
121while($item = $r0->fetchRow())
122{
123    $item_id = $item['id'];
124    unset($item['id']);
125
126    $result[$item_id] = $item;
127    $result[$item_id]['gender_t'] = translate_list($item['gender'], $labels['profile']['gender']);
128    $result[$item_id]['here_for_t'] = translate_list($item['here_for'], $labels['profile']['here_for']);
129    $result[$item_id]['relationship_status_t'] = translate_list($item['relationship_status'], $labels['profile']['relationship_status']);
130
131    $result[$item_id]['photo'] = build_thumb_url($item_id);
132}
133
134if($pagination['nb_elements'] > 0)
135        $pagination['nb_pages'] = ceil($pagination['nb_elements']/$pagination['elmt_by_page']);
136else
137        $pagination['nb_pages'] = 1;
138
139$pagination['pages'] = @array_fill(1,$pagination['nb_pages'], NULL);
140
141$_SMARTY['pagination'] =  $pagination;
142$_SMARTY['search'] =  $search;
143$_SMARTY['result'] =  $result;
144
145if(!$_GET['do'])
146     $_GET['search']['photo'] = 'y';
147
148
149 ?>
Note: See TracBrowser for help on using the browser.