Требование: PHP => 5.3, часть 2
[cswow.git] / module / search / search_npc.php
blobd53b0fd921dfc3a6b124190aa7af3b8eaee2544c
1 <?php
2 include_once("include/functions.php");
3 include_once("include/report_generator.php");
5 // Îïðåäåëÿåì ðåæèì ïîèñêà
6 $allmode = @$_REQUEST['s']=='all';
8 // Ñîçäà¸ì ññûëêó íà ñòðàíèöó, èãíîðèðóåì äåôîëòíûå çíà÷åíèÿ
9 $FindRefrence = "?s=n";
11 $show_fields = array('NPC_REPORT_LEVEL', 'NPC_REPORT_NAME', 'NPC_REPORT_REACTION', 'NPC_REPORT_MAP');
13 //==============================================================================
14 // Ñîçäà¸ì SQL çàïðîñ èñõîäÿ èç çàäàíûõ ïîëüçîâàòåëåì ïàðàìåòðîâ
15 //==============================================================================
16 $filter = "";
17 // Ôèëüòð èìåíè
18 if ($name = mysql_real_escape_string(@$_REQUEST['name']))
20 $filter.= " AND `Name` like '%$name%'";
21 $FindRefrence.="&name=$name";
23 // Ôèëüòð äîïîëíèòåëüíîãî èìåíè
24 if ($subname = mysql_real_escape_string(@$_REQUEST['subname']))
26 $filter.= " AND `SubName` like '%$subname%'";
27 $FindRefrence.="&subname=$subname";
29 // Level filter
30 if ($level_min = intval(@$_REQUEST['level_min']))
32 $filter.= " AND `MinLevel` >= '$level_min'";
33 $FindRefrence.="&level_min=$level_min";
35 if ($level_max = intval(@$_REQUEST['level_max']))
37 $filter.= " AND `MaxLevel` <= '$level_max'";
38 $FindRefrence.="&level_max=$level_max";
40 // Ôèëüòð ïî òèïó
41 if ($type = intval(@$_REQUEST['type']))
43 $filter.= " AND `CreatureType` = '$type'";
44 $FindRefrence.="&type=$type";
46 // Ôèëüòð ïî family
47 if ($family = intval(@$_REQUEST['family']))
49 $filter.= " AND `Family` = '$family'";
50 $FindRefrence.="&family=$family";
52 // Ôèëüòð ïî ðàíãó
53 if (isset($_REQUEST['rank']))
55 $rank = intval($_REQUEST['rank']);
56 $filter.= " AND `Rank` = '$rank'";
57 $FindRefrence.="&rank=$rank";
59 // Ôèëüòð ïî ôëàãó
60 if (isset($_REQUEST['flag']))
62 $npc_flag = intval($_REQUEST['flag']);
63 $filter.= " AND (`NpcFlags`&".(1<<$npc_flag).")";
64 $FindRefrence.="&flag=$npc_flag";
66 // Óáèðàåì íåíóæíûé AND â íà÷àëå ñòðîêè
67 $filter = substr($filter, 5);
69 // Âûâîä äèàëîãà ïîèñêà
70 if ($allmode==0 and $ajaxmode==0)
72 if ($level_min == 0) $level_min = "";
73 if ($level_max == 0) $level_max = "";
74 echo '<form>';
75 echo '<input name="s" type="hidden" value="n">';
76 echo '<table class=find>';
77 echo '<tr><td class=top colspan=4>';
78 echo '<table class=findtop><tr><td class=topleft>&nbsp;</td><td class=top>'.$lang['find_mob'].'</td><td class=topright>&nbsp;</td></tr></table>';
79 echo '</td></tr>';
80 echo '<tr><td>'.$lang['mob_name'].':</td><td colspan=3><input class=ls_search alt="n" name="name" value="'.@$_REQUEST['name'].'" size="30"></td></tr>';
81 echo '<tr><td>'.$lang['mob_subname'].':</td><td colspan=3><input name="subname" value="'.@$_REQUEST['subname'].'" size="30"></td></tr>';
82 echo '<tr><td>'.$lang['level'].':</td><td><input name="level_min" value="'.$level_min.'" size="11"></td><td>-</td><td><input name="level_max" value="'.$level_max.'" size="11"></td></tr>';
83 echo '<tr><td class=bottom colspan=4><input type=submit value="'.$lang['search'].'"></td></tr>';
84 echo '</table>';
85 echo '</form>';
88 if ($filter!="")
90 $npc_search = new CreatureReportGenerator();
91 if (!$allmode)
92 $npc_search->disableMark();
93 //==============================================================================
94 // Ëîêàëèçàöèÿ çàïðîñà
95 //==============================================================================
96 if ($config['locales_lang'] > 0)
98 if ($name)
100 if (preg_match($config['locales_charset'], $name) || ctype_digit($name))
101 $filter = str_replace('`Name`', '`name_loc'.$config['locales_lang'].'`', $filter);
102 else
103 $npc_search->disableNameLocalisation();
105 if ($subname)
107 if (preg_match($config['locales_charset'], $subname) || ctype_digit($subname))
108 $filter = str_replace('`SubName`', '`subname_loc'.$config['locales_lang'].'`' ,$filter);
109 else
110 $npc_search->disableSubnameLocalisation();
113 $npc_search->Init($show_fields, $FindRefrence, 'searchNpc', $config['fade_limit'], 'name');
114 $npc_search->doRequirest($filter);
115 $number = $npc_search->getTotalDataCount();
116 if ($number <= 0)
117 echo $lang['not_found'];
118 else if ($number == 1 && $allmode == 0) // Ïåðåíàïðàâëÿåì
119 echo '<meta http-equiv="refresh" content=1;URL=?npc='.$npc_search->data_array[0]['Entry'].'>';
120 else
121 $npc_search->createReport($lang['search_results'].' - '.$lang['found'].' '.$number);