2 //=============================================================================
3 // Script allow do search in database by name, output result in 2 modes
4 // ls - Live Search -> for web script (if user input data on web page)
5 // os - Open Search -> for browser Open Search toolbar
6 // Search in item, itemset, quest, NPC, GO, spell, faction tables
7 //=============================================================================
9 include_once("include/functions.php");
11 function highliteText($text, $sub)
13 return preg_replace('/'.$sub.'/i', '<b>$0</b>', $text);
16 $type = isset($_REQUEST['ls']) ?
$_REQUEST['ls'] : @$_REQUEST['os'];
17 $name = @$_REQUEST['name'];
20 if ($config['locales_lang']) $localised = preg_match($config['locales_charset'], $name);
21 else $localised = false;
22 $locale = $config['locales_lang'];
24 // Result limit from config
25 $limit = $config['ls_limit'];
31 if ($type == 'i' OR $type == 'all')
33 $filter = '`name` like ?';
34 $tables = '`item_template`';
35 $filelds = '`item_template`.`entry`, `Quality`, `displayid`, `name`';
38 $tables = '`item_template` LEFT JOIN `locales_item` ON `item_template`.`entry` = `locales_item`.`entry`';
39 $filter = str_replace('`name`', '`name_loc'.$locale.'`', $filter);
40 $filelds= str_replace('`name`', '`locales_item`.`name_loc'.$locale.'` AS `name`', $filelds);
42 if ($items = $dDB->select("SELECT $filelds FROM $tables WHERE $filter LIMIT 0, ?d", '%'.$name.'%', $limit))
43 foreach ($items as $item)
44 $result['i'][]=array('ico'=>getItemIcon($item['displayid'], 0), 'class'=>$Quality[$item['Quality']], 'link'=>'?item='.$item['entry'], 'txt'=>$item['name'], 'type'=>$ls_type_name['i']);
48 if ($type == 'set' OR $type == 'all')
50 if ($set = $wDB->select('SELECT `id`, `name` FROM `wowd_itemset` WHERE `name` LIKE ? LIMIT 0, ?d', '%'.$name.'%', $limit))
52 $result['set'][]=array('txt'=>$s['name'], 'link'=>'?itemset='.$s['id'], 'type'=>$ls_type_name['set']);
56 if ($type == 'q' OR $type == 'all')
58 $filter = '`Title` like ?';
59 $tables = '`quest_template`';
60 $filelds = '`quest_template`.`entry`, `Title`';
63 $tables = '`quest_template` LEFT JOIN `locales_quest` ON `quest_template`.`entry` = `locales_quest`.`entry`';
64 $filter = str_replace('`Title`', '`Title_loc'.$locale.'`', $filter);
65 $filelds= str_replace('`Title`', '`locales_quest`.`Title_loc'.$locale.'` AS `Title`', $filelds);
67 if ($quests = $dDB->select("SELECT $filelds FROM $tables WHERE $filter LIMIT 0, ?d", '%'.$name.'%', $limit))
68 foreach($quests as $quest)
69 $result['q'][]=array('txt'=>$quest['Title'], 'link'=>'?quest='.$quest['entry'], 'type'=>$ls_type_name['q']);
73 if ($type == 'n' OR $type == 'all')
75 $filter = '`name` like ?';
76 $tables = '`creature_template`';
77 $filelds = '`creature_template`.`entry`, `name`';
80 $tables = '`creature_template` LEFT JOIN `locales_creature` ON `creature_template`.`entry` = `locales_creature`.`entry`';
81 $filter = str_replace('`name`', '`name_loc'.$locale.'`', $filter);
82 $filelds= str_replace('`name`', '`locales_creature`.`name_loc'.$locale.'` AS `name`', $filelds);
84 if ($npcs= $dDB->select("SELECT $filelds FROM $tables WHERE $filter LIMIT 0, ?d", '%'.$name.'%', $limit))
85 foreach ($npcs as $npc)
86 $result['n'][]=array('txt'=>$npc['name'], 'link'=>'?npc='.$npc['entry'], 'type'=>$ls_type_name['n']);
90 if ($type == 'g' OR $type == 'all')
92 $filter = '`name` like ?';
93 $tables = '`gameobject_template`';
94 $filelds = '`gameobject_template`.`entry`, `name`';
97 $tables = '`gameobject_template` LEFT JOIN `locales_gameobject` ON `gameobject_template`.`entry` = `locales_gameobject`.`entry`';
98 $filter = str_replace('`name`', '`name_loc'.$locale.'`', $filter);
99 $filelds= str_replace('`name`', '`locales_gameobject`.`name_loc'.$locale.'` AS `name`', $filelds);
101 if ($go = $dDB->select("SELECT $filelds FROM $tables WHERE $filter LIMIT 0, ?d", '%'.$name.'%', $limit))
103 $result['g'][]=array('txt'=>$g['name'], 'link'=>'?object='.$g['entry'], 'type'=>$ls_type_name['g']);
107 if ($type == 's' OR $type == 'all')
109 if ($spells = $wDB->select('SELECT `id`, `SpellName`, `Rank`, `SpellIconID` FROM `wowd_spell` WHERE `SpellName` like ? LIMIT 0, ?d', '%'.$name.'%', $limit))
110 foreach ($spells as $spell)
112 $n = $spell['SpellName'];
114 $n.=' ('.$spell['Rank'].')';
115 $result['s'][]=array('ico'=>getSpellIcon($spell['SpellIconID'], 0), 'txt'=>$n, 'link'=>'?spell='.$spell['id'], 'type'=>$ls_type_name['s']);
120 if ($type == 'f' OR $type == 'all')
122 $factions = $wDB->select('SELECT `id`, `name` FROM `wowd_faction` WHERE `name` like ? LIMIT 0, ?d', '%'.$name.'%', $limit);
124 foreach ($factions as $f)
125 $result['f'][]=array('txt'=>$f['name'], 'link'=>'?faction='.$f['id'], 'type'=>$ls_type_name['f']);
129 if ($type == 'a' OR $type == 'all')
131 $area = $wDB->select('SELECT `id`, `name` FROM `wowd_zones` WHERE `name` like ? LIMIT 0, ?d', '%'.$name.'%', $limit);
133 foreach ($area as $a)
134 $result['a'][]=array('txt'=>$a['name'], 'link'=>'?zone='.$a['id'], 'type'=>$ls_type_name['a']);
139 foreach($result as $key=>$r)
140 $count+
=count($result[$key]);
142 // Limit results count to need amount by remove one result in max group step by step
143 while ($count > $limit)
147 foreach($result as $key=>$r)
149 $c = count($result[$key]);
156 unset($result[$max_key][$cmax-1]);
163 if (isset($_REQUEST['ls'])) // Live Search mode
165 echo '<table class=livesearch><tbody>';
166 foreach($result as $key=>$r)
168 foreach($result[$key] as $res)
171 echo '<td>'.(isset($res['ico'])?
'<img src='.$res['ico'].'>' : '').'</td>';
172 echo '<td class=lsname><a'.(isset($res['class'])?
' class='.$res['class']:'').' href="'.$res['link'].'">'.highliteText($res['txt'], $name).'</a></td>';
173 echo '<td class=lstype>'.$res['type'].'</td>';
177 echo '</tbody></table>';
179 else if (isset($_REQUEST['os'])) // Open Search mode
181 echo '["'.$name.'", [';
182 foreach($result as $key=>$r)
183 foreach($result[$key] as $res)
184 echo '"'.$res['txt'].' ('.$res['type'].')",';