Требование: PHP => 5.3, часть 2
[cswowd.git] / module / search / search_item.php
blob201be59bfaf267e37aa2c3441a7b6beb54de5029
1 <?php
2 include_once("conf.php");
3 include_once("item_class.php");
4 include_once("include/functions.php");
5 include_once("include/report_generator.php");
7 // Определяем режим поиска
8 $allmode = @$_REQUEST['s']=='all';
10 // Создаём ссылку на страницу, игнорируем дефолтные значения
11 $FindRefrence = "?s=i";
13 // Выбор какие поля будем выводить - основываемся на данных о типе и классе
14 $show_fields = 0; // По дефолту
16 //==============================================================================
17 // По каким полям ищем
18 //==============================================================================
19 $filter = "";
20 // Name filter
21 if ($name = mysql_real_escape_string(@$_REQUEST['name']))
23 $filter = " AND `name` like '%$name%'";
24 $FindRefrence.="&name=$name";
26 // Item Type filter
27 if ($type = intval(@$_REQUEST['type']))
29 $show_fields = @$itemType_list[$type];
30 $filter.= " AND InventoryType=$type";
31 $FindRefrence.="&type=$type";
33 // Class and subclass filter(stored in class.subclass format)
34 mergeStrByPoint(@$_REQUEST['class'], $class, $subclass);
35 if ($class>=0 OR $subclass>=0)
37 $show_fields = @$ItemClass_list[@$_REQUEST['class']];
38 $filter.=" AND `class` = $class";
39 $FindRefrence.="&class=$class";
40 if ($subclass >=0)
42 $filter.=" AND `subclass` = $subclass";
43 $FindRefrence.=".$subclass";
47 // Level Filter
48 if ($level_min = intval(@$_REQUEST['level_min']))
50 $filter.= " AND RequiredLevel >= $level_min";
51 $FindRefrence.="&level_min=$level_min";
53 if ($level_max = intval(@$_REQUEST['level_max']))
55 $filter.= " AND RequiredLevel <= $level_max";
56 $FindRefrence.="&level_max=$level_max";
58 // Тотем категория
59 if ($totemCat = intval(@$_REQUEST['totem']))
61 $filter.= " AND TotemCategory=$totemCat";
62 $FindRefrence.='&totem='.$totemCat;
64 // Тип камня
65 if ($gemProp = intval(@$_REQUEST['gem']))
67 $show_fields = &$item_jevelry;
68 if ($gem = $wDB->selectCol("SELECT `id` FROM `wowd_gemproperties` WHERE `color` & ?d", $gemProp))
70 $filter.= ' AND GemProperties IN ('.join(',', $gem).')';
71 $FindRefrence.='&gem='.$gemProp;
73 else
74 $filter.=' AND `item_template`.`entry`=-1';
76 // Flags
77 if ($flags = intval(@$_REQUEST['flags']))
79 $filter.= ' AND (`Flags`&'.(1<<$flags).')';
80 $FindRefrence.='&flags='.$flags;
83 // Убираем ненужный AND в начале строки
84 $filter = substr($filter, 5);
86 // Назначаем выводимые столбцы если не назначены
87 if ($show_fields==0)
88 $show_fields = &$item_all;
89 // Disable some columns output if need
90 if ($type)
91 if ($id = array_search('ITEM_REPORT_SLOTTYPE', $show_fields))
92 unset($show_fields[$id]);
93 if ($subclass >=0)
94 if ($id = array_search('ITEM_REPORT_SUBCLASS', $show_fields))
95 unset($show_fields[$id]);
97 //==============================================================================
98 // Search dialog
99 //==============================================================================
100 if ($allmode==0 and $ajaxmode==0)
102 if ($level_min == 0) $level_min = "";
103 if ($level_max == 0) $level_max = "";
104 // Вывод диалога
105 echo '<form>';
106 echo '<input name="s" type="hidden" value="i">';
107 echo '<table class=find>';
108 echo '<tr><td colspan=6 class=top>';
109 echo '<table class=findtop><tr><td class=topleft>&nbsp;</td><td class=top>'.$lang['find_item'].'</td><td class=topright>&nbsp;</td></tr></table>';
110 echo '</td></tr>';
112 echo '<tr><td>'.$lang['item_name'].':</td>';
113 echo '<td colSpan=5><input class=ls_search alt=i name="name" style="width: 100%;" value="'.$name.'"></td></tr>';
114 echo '<tr><td>'.$lang['item_class'].':</td><td colspan=5>';
115 echo '<select name="class" style="width: 100%;">\n';
116 echo "\n<option value=''>".getClassName(-1)."</option>\n";
117 $key = array_keys($ItemClass_list);
118 for($i=0; $i<count($ItemClass_list); $i++)
120 $text = "";
121 $value = $key[$i];
122 mergeStrByPoint($value, $s_class, $s_subclass);
123 $style = "";
124 if ($s_subclass < 0)
126 $text = getClassName($s_class);
127 $style = 'style = "FONT-WEIGHT: 800;"';
129 else
130 $text = "&nbsp;&nbsp;* ".getSubclassName($s_class, $s_subclass);
131 if ($s_class == $class AND $s_subclass == $subclass)
132 echo $style.=' selected = "selected"';
133 echo "<option $style value='$value'>$text</option>\n";
135 echo '</select></td></tr>';
136 echo '<tr><td>'.$lang['item_min_level'].':</td>';
137 echo '<td><input name="level_min" value="'.$level_min.'" style="WIDTH: 30px"></td>';
138 echo '<td width=90>'.$lang['item_max_level'].':</td>';
139 echo '<td><input name="level_max" value="'.$level_max.'" style="WIDTH: 30px"></td>';
140 echo '<td>'.$lang['item_type'].':</td><td><select name="type">\n';
141 echo "\n<option value=''>".getInventoryType(0)."</option>\n";
142 $key = array_keys($itemType_list);
143 for($i=0; $i<count($itemType_list); $i++)
145 $value = $key[$i];
146 $text = getInventoryType($value);
147 if ($type==$value) echo "<option \"selected\" value=$value>$text</option>\n";
148 else echo "<option value=$value>$text</option>\n";
150 echo '</select></td></tr><tr>';
151 echo '<tr><td colspan=6 class=bottom><input type=submit value="'.$lang['search'].'">&nbsp;<input type=RESET value="'.$lang['reset'].'"></td></tr>';
152 echo '</table>';
153 echo '</form>';
156 if ($filter!='')
158 $isearch = new ItemReportGenerator;
159 if (!$allmode)
160 $isearch->disableMark();
162 //==============================================================================
163 // Локализация запроса
164 //==============================================================================
165 if ($config['locales_lang'] > 0 && $name)
167 if (preg_match($config['locales_charset'], $name) || ctype_digit($name))
168 $filter = str_replace('`name`', '`name_loc'.$config['locales_lang'].'`', $filter);
169 else
170 $isearch->disableNameLocalisation();
173 $isearch->Init($show_fields, $FindRefrence, 'searchItem', $config['fade_limit'], 'name');
174 $isearch->doRequirest($filter);
175 $number = $isearch->getTotalDataCount();
176 if ($number <= 0)
177 echo $lang['not_found'];
178 else if ($number == 1 && $allmode == 0)
180 // Перенаправляем
181 echo '<meta http-equiv="refresh" content=1;URL=?item='.$isearch->data_array[0]['entry'].'>';
183 else
185 $isearch->removeIfAllZero('RequiredLevel', 'ITEM_REPORT_REQLEVEL');
186 $isearch->removeIfAllZero('armor', 'ITEM_REPORT_ARMOR');
187 $isearch->removeIfAllZero('dps', 'ITEM_REPORT_DPS');
188 $isearch->removeIfAllZero('delay', 'ITEM_REPORT_SPEED');
189 $isearch->createReport($lang['search_results'].' - '.$lang['found'].' '.$number);