forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CL_brands.php
266 lines (217 loc) · 8.41 KB
/
CL_brands.php
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?
//************************************************************************
// Leonardo XC Server, http://www.leonardoxc.net
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: CL_brands.php,v 1.14 2010/03/16 13:00:12 manolis Exp $
//
//************************************************************************
require_once dirname(__FILE__).'/FN_brands.php';
class brands {
function makeWhereClause($brandID,$returnLegend=0) {
// global $CONF;
if ( $brandID) {
$where_clause=' AND gliderBrandID='.$brandID ;
$legend='';
} else {
$where_clause='';
$legend='';
}
if ($returnLegend)
return array($where_clause,$legend);
else
return $where_clause;
}
function getBrandText($brandID,$gliderName='',$glidetCat=0){
global $moduleRelPath,$CONF_abs_path,$CONF;
if (!$brandID) {
$brandID=brands::guessBrandID($gliderName);
$brandName='';
}
if ($brandID) {
if (!isset($brandName) ) $brandName=$CONF['brands']['list'][$brandID];
$gliderBrandImg="$brandName $gliderName";
} else
$gliderBrandImg="$gliderName";
return $gliderBrandImg;
}
function getBrandImg($brandID,$gliderName='',$glidetCat=0){
global $moduleRelPath,$CONF_abs_path,$CONF;
if (!$brandID) {
$brandID=brands::guessBrandID($gliderName);
$brandName='';
}
if ($brandID) {
if (!isset($brandName) ) $brandName=$CONF['brands']['list'][$brandID];
if (is_file("$CONF_abs_path/img/brands/".sprintf("%03d",$brandID).".gif") ) {
$gliderBrandImg="<img align='absmiddle' src='$moduleRelPath/img/brands/".sprintf("%03d",$brandID).".gif' title='$brandName $gliderName' alt='$brandName $gliderName' border='0' />";
$gliderBrandImg=leoHtml::img(sprintf("%03d",$brandID).".gif",0,0,'absmiddle',"$brandName $gliderName",'brands');
// $gliderBrandImg="<img align='absmiddle' class='brands sprite-".sprintf("%03d",$brandID)."' src='$moduleRelPath/img/space.gif' title='$brandName $gliderName' alt='$brandName $gliderName' border='0' />";
} else {
$gliderBrandImg="<img align='absmiddle' src='$moduleRelPath/img/space.gif' width=6 height=16 title='$brandName $gliderName' alt='$brandName $gliderName' border='0' />";
}
} else
$gliderBrandImg="<img align='absmiddle' src='$moduleRelPath/img/brands/unknown_".sprintf("%03d",$glidetCat).".gif' title='$gliderName' alt='$gliderName' border='0' />";
return $gliderBrandImg;
}
static function getGliderName($gliderID,$showBrand=0,$showCert=0,$showSize=1){
global $db,$CONF_glider_certification_categories;
$row=brands::getGliderInfo($gliderID);
if ($row['gliderName']) {
if ($showBrand) {
$gBrand=$row['brandName'];
if ($gBrand) $gBrand=$gBrand.' ';
}
if ($showSize) {
$gSize= $row['gliderSize'];
if ($gSize) $gSize=" - "+$gSize;
}
if ($showCert) {
$gCert= $row['gliderCert'];
if ($gCert) $gCert=" ["+$CONF_glider_certification_categories[$gCert]+"]";
}
return $row['gliderName']."$gSize$gCert";
}
return '';
}
static function getGliderInfo($gliderID){
global $db,$CONF_glider_certification_categories;
$query="SELECT * FROM leonardo_gliders,leonardo_brands
Where leonardo_gliders.brandID =leonardo_brands.brandID
AND gliderID=$gliderID";
$res= $db->sql_query($query);
$rows = array();
if($res > 0){
if ($row = mysql_fetch_assoc($res)) {
$info['brandName']=$row['brandName'];
$info['gliderSize']=$row['gliderSize'];
$info['gliderCert']=$row['gliderCert'];
$info['gliderName']=$row['gliderName'];
$info['brandID']=$row['brandID'];
return $info;
}
}
return array();
}
function getBrandsListFromDB(){
global $CONF,$db;
$CONF['brands']['list']=array();
$query="SELECT * FROM leonardo_brands order by brandID ASC";
$res= $db->sql_query($query);
$rows = array();
if($res > 0){
while ($row = mysql_fetch_assoc($res)) {
$CONF['brands']['list'][$row['brandID']] = $row['brandName'];
}
}
}
function getBrandsList($forFilterUse=0){
global $CONF;
if ($forFilterUse && ! $CONF['brands']['showAll']) {
foreach( $CONF['brands']['filterList'] as $id ) {
$brandsList[ $CONF['brands']['list'][$id] ]=$id;
}
} else {
foreach( $CONF['brands']['list'] as $id=>$brand ) {
$brandsList[$brand]=$id;
}
}
ksort($brandsList);
return $brandsList;
}
function isValidBrandForFilter($brandID) {
global $CONF;
if (!$CONF['brands']['filter_brands']) return 0;
if ( in_array($brandID,$CONF['brands']['filterList']) || $CONF['brands']['showAll'] ) return 1;
else return 0;
}
function removeBrandFromName($gliderDesc,$brandID){
global $CONF;
$gliderDesc=str_ireplace($CONF['brands']['list'][$brandID],'',$gliderDesc);
return trim($gliderDesc);
}
function guessBrandID($gliderDesc){
global $CONF;
// if (!is_array($brandsList[$gliderType]) ) return 0;
$gliderDesc=strtolower($gliderDesc);
//$gliderDesc=str_replace(" ","",$gliderDesc);
$gliderDesc=preg_replace('/[^\w]/','',$gliderDesc);
//echo "detect for $gliderDesc : ";
foreach($CONF['brands']['list'] as $brandID=>$brandName) {
//echo "trying $brandID=>$brandName <BR>";
if ( ! ( strpos($gliderDesc,strtolower($brandName) ) === false ) ) {
// echo "found ID $brandID<BR>";
return $brandID;
}
}
return 0;
}
function sanitizeGliderName($gliderName) {
global $CONF;
$gliderNameNorm=trim( preg_replace("/[\/\-\,\.]/",' ',$gliderName) );
$gliderNameNorm=preg_replace("/( )+/",' ',$gliderNameNorm);
$gliderNameNorm=preg_replace("/(III)/",'3',$gliderNameNorm);
$gliderNameNorm=preg_replace("/(II)/",'2',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](one)/",'1',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](two)/",'2',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](three)/",'3',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](four)/",'4',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](five)/",'5',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](six)/",'6',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](seven)/",'7',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](eight)/",'8',$gliderNameNorm);
$gliderNameNorm=preg_replace("/[^\w](nine)/",'9',$gliderNameNorm);
$gliderNameNorm=ucwords(strtolower($gliderNameNorm));
return $gliderNameNorm;
}
static function find_similar_gliders($gliderName,$threshold=50) {
global $db;
$max_percent=0;
$best_match_Name='';
$best_match_id=0;
$query="SELECT * FROM leonardo_gliders, leonardo_brands WHERE leonardo_gliders.brandID = leonardo_brands.brandID";
// echo $query;
$res= $db->sql_query($query);
$gliderList = array();
if($res > 0){
while ($row = mysql_fetch_assoc($res)) {
$gliderList[ $row['gliderID'] ] = $row;
}
}
$list=array();
foreach ( $gliderList as $gliderID=>$row) {
$tmpName=$row['gliderName'];
// $tmpName=$row['gliderName'];
$similar_index = similar_text ( $gliderName, $tmpName , $percent );
// echo "$percent <BR>";
if ($percent>$threshold) {
$row['percent']=$percent;
$list[]=$row;
}
/*
if ($percent>$max_percent) {
$max_percent=$percent;
$best_match_id=$gliderID;
$best_match_Name=$tmpName;
}
*/
}
// echo count ($list);
usort($list,"percent_sort_compare");
return $list;
// return array($best_match_Name,$max_percent, $best_match_id);
}
}
function percent_sort_compare ($a,$b) {
if ($a['percent'] == $b['percent']) {
return 0;
}
//descending order
return ($a['percent'] < $b['percent']) ? 1 : -1;
}
?>