Source code taken from cacert-20130716.tar.bz2
[cacert-devel.git] / pages / wot / 12.php
1 <? /*
2 LibreSSL - CAcert web application
3 Copyright (C) 2004-2008 CAcert Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; version 2 of the License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */ ?>
18
19 <? if(!array_key_exists('location',$_REQUEST) || $_REQUEST['location'] == "") { ?>
20 <script language="javascript" src="/ac.js"></script>
21 <script language="javascript">
22 <!--
23 function oncomplete() {
24 document.f.submit();
25 }
26 // -->
27 </script>
28 <p><?=_("Please enter your town or suburb name, followed by region or state or province and then the country (please separate by commas)")?><br />
29 <?=_("eg Sydney, New South Wales, Australia")?></p>
30 <p><?=_("This is an AJAX form which depends heavily on javascript for auto-complete functionality and while it will work without javascript the usability will be heavily degraded.")?></p>
31 <form name="f" action="wot.php" method="post">
32 <input type='hidden' name='oldid' value='12' />
33 <table>
34 <tr>
35 <td align=right valign=middle><?=_("Maximum Distance:")?></td>
36 <td><select name="maxdist">
37 <?
38 $arr = array(10, 25, 50, 100, 250, 500, 1000);
39 foreach($arr as $val)
40 {
41 echo "<option value='$val'";
42 if(array_key_exists('maxdist',$_REQUEST) && $val == $_REQUEST['maxdist'])
43 echo " selected";
44 echo ">${val}km</option>\n";
45 }
46 ?>
47 </td>
48 </tr>
49 <tr>
50 <td align=right valign=middle><?=_("Location:")?></td>
51 <td><input autocomplete="off" type="text" id="location" name="location" value="" size="50" /> <input type="submit" name="process" value="Go"></td>
52 </tr>
53 </table>
54
55 </form>
56 <script language="javascript">
57 <!--
58 var ac1 = new AC('location', 'location', oncomplete);
59 ac1.enable_unicode();
60 document.f.location.focus();
61 // -->
62 </script>
63 <? } else {
64 if(intval($_REQUEST['location']) == 0)
65 {
66 $bits = explode(",", $_REQUEST['location']);
67
68 $loc = trim(mysql_escape_string($bits['0']));
69 $reg = ""; if(array_key_exists('1',$bits)) $reg=trim(mysql_escape_string($bits['1']));
70 $ccname = ""; if(array_key_exists('2',$bits)) $ccname=trim(mysql_escape_string($bits['2']));
71
72 $query = "select `locations`.`id` as `locid` from `locations`, `regions`, `countries` where
73 `locations`.`name` like '$loc%' and `regions`.`name` like '$reg%' and `countries`.`name` like '$ccname%' and
74 `locations`.`regid`=`regions`.`id` and `locations`.`ccid`=`countries`.`id`
75 order by `locations`.`name` limit 1";
76 $res = mysql_query($query);
77 if($reg != "" && $ccname == "" && mysql_num_rows($res) <= 0)
78 {
79 $query = "select `locations`.`id` as `locid` from `locations`, `regions`, `countries` where
80 `locations`.`name` like '$loc%' and `countries`.`name` like '$reg%' and
81 `locations`.`regid`=`regions`.`id` and `locations`.`ccid`=`countries`.`id`
82 order by `locations`.`name` limit 1";
83 $res = mysql_query($query);
84 }
85 if(mysql_num_rows($res) <= 0)
86 die(_("Unable to find suitable location"));
87 $row = mysql_fetch_assoc($res);
88 $_REQUEST['location'] = $row['locid'];
89 }
90
91 $maxdist = intval($_REQUEST['maxdist']);
92
93 $locid = intval($_REQUEST['location']);
94 $query = "select * from `locations` where `id`='$locid'";
95 $loc = mysql_fetch_assoc(mysql_query($query));
96 if($maxdist <= 10)
97 {
98 $query = "SELECT ROUND(6378.137 * ACOS(0.9999999*((SIN(PI() * $loc[lat] / 180) * SIN(PI() * `locations`.`lat` / 180)) + (COS(PI() * $loc[lat] / 180 ) *
99 COS(PI() * `locations`.`lat` / 180) * COS(PI() * `locations`.`long` / 180 - PI() * $loc[long] / 180)))), -1) AS `distance`,
100 `locations`.`name` AS `location`, concat(`users`.`fname`, ' ', LEFT(`users`.`lname`, 1)) AS `name`, `long`, `lat`,
101 `users`.`id` as `uid`, `contactinfo` FROM `locations`, `users` WHERE `users`.`locid` = `locations`.`id` AND
102 `users`.`assurer` = 1 AND `users`.`listme` = 1 HAVING `distance` <= '$maxdist' ORDER BY `distance`";
103 } else {
104 $query = "SELECT ROUND(6378.137 * ACOS(0.9999999*((SIN(PI() * $loc[lat] / 180) * SIN(PI() * `locations`.`lat` / 180)) + (COS(PI() * $loc[lat] / 180 ) *
105 COS(PI() * `locations`.`lat` / 180) * COS(PI() * `locations`.`long` / 180 - PI() * $loc[long] / 180)))), -1) AS `distance`,
106 `locations`.`name` AS `location`, concat(`users`.`fname`, ' ', LEFT(`users`.`lname`, 1)) AS `name`, `long`, `lat`,
107 `users`.`id` as `uid`, `contactinfo` FROM `locations`, `users` WHERE `users`.`locid` = `locations`.`id` AND
108 `users`.`assurer` = 1 AND `users`.`listme` = 1 HAVING `distance` <= '$maxdist' ORDER BY `distance` LIMIT 50";
109 //echo $query;
110 }
111 $res = mysql_query($query);
112 ?><table align="center" valign="middle" border="0" cellspacing="0" cellpadding="0" class="wrapper" width="700">
113 <tr>
114 <td class="title"><?=_("Name")?></td>
115 <td class="title"><?=_("Distance")?></td>
116 <td class="title"><?=_("Max Points")?></td>
117 <td class="title"><?=_("Contact Details")?></td>
118 <td class="title"><?=_("Email Assurer")?></td>
119 </tr>
120 <? while($row = mysql_fetch_assoc($res))
121 {
122 $points = maxpoints($row['uid']);
123 if($points > 35)
124 $points = 35;
125 ?>
126 <tr>
127 <td class="DataTD" width="100"><nobr><?=$row['name']?></nobr></td>
128 <td class="DataTD"><?=$row['distance']?>km</td>
129 <td class="DataTD"><?=$points?></td>
130 <td class="DataTD"><?=$row['contactinfo']?></td>
131 <td class="DataTD"><a href="wot.php?id=9&amp;userid=<?=$row['uid']?>"><?=_("Email Me")?></a></td>
132 </tr>
133 <? } ?>
134 </table>
135 <? } ?>