Требование: PHP => 5.3, часть 2
[cswow.git] / include / functions.php
blob57f1a0036e41213e129b6b59cbfc9e47ba841d74
1 <?php
2 include_once ("item_table.php");
3 include_once ("spell_table.php");
4 include_once ("talent_table.php");
5 include_once ("gameobject_table.php");
6 include_once ("enchant_table.php");
7 include_once ("quest_data.php");
9 function getLPageOffset($page, $limit)
11 if ($page< 1)$page_seek = 0;
12 else $page_seek = ($page-1) * $limit;
13 return $page_seek;
16 function getPageOffset($page)
18 global $config;
19 return getLPageOffset($page, $config['fade_limit']);
22 function generateLPage($totalRecords, $currentPage, $link, $limit, $colSpan)
24 $totalPage = floor($totalRecords /$limit+0.9999);
25 if ($totalPage <=1) return;
26 if ($currentPage<1)
27 $currentPage = 1;
28 echo "<tr><td colspan=$colSpan class=page>";
29 for ($i=1;$i<=$totalPage;$i++)
31 if ($i!=$currentPage) printf($link, $i, $i);
32 else echo '<b><i>'.$i.' </i></b>';
34 echo "</td></tr>";
37 function generatePage($totalRecords, $currentPage, $link, $colSpan)
39 global $config;
40 generateLPage($totalRecords, $currentPage, $link, $config['fade_limit'], $colSpan);
43 function RenderError($text)
45 global $lang;
46 echo "$lang[error] - $text";
48 function money($many, $height=10)
50 if ($many>0)
52 $many = str_pad($many, 12, 0, STR_PAD_LEFT);
53 $str = "";
55 else if ($many == 0)
56 return "n/a";
57 else
59 $many = str_pad(-$many, 12, 0, STR_PAD_LEFT);
60 $str = "-";
62 $copper = intval(substr($many, -2));
63 $silver = intval(substr($many, -4, -2));
64 $gold = intval(substr($many, -11, -4));
65 $hstr = "";
66 if ($height!=14) $hstr = "height={$height}px";
67 if ($gold ) { $str.= "$gold<img $hstr src=images/gold.gif> "; }
68 if ($silver) { $str.= "$silver<img $hstr src=images/silver.gif> "; }
69 if ($copper) { $str.= "$copper<img $hstr src=images/copper.gif>"; }
70 return $str;
73 function getTimeText($seconds)
75 global $lang;
76 $text = "";
77 if ($seconds < 0) {$text.= "$lang[minustime]";}
78 if ($seconds >=24*3600) {$text.= intval($seconds/(24*3600))." $lang[days]"; if ($seconds%=24*3600) $text.=" ";}
79 if ($seconds >= 3600) {$text.= intval($seconds/3600)." $lang[hours]"; if ($seconds%=3600) $text.=" ";}
80 if ($seconds >= 60) {$text.= intval($seconds/60)." $lang[min]"; if ($seconds%=60) $text.=" ";}
81 if ($seconds > 0) {$text.= $seconds." $lang[sec]";}
82 return $text;
85 // Функция разделения строки по точке
86 function mergeStrByPoint($str, &$a, &$b)
88 $len = strlen($str);
89 if ($len == 0) {$a = -1; $b = -1; return;}
90 if ($x = strpos($str, '.'))
92 $a = intval(substr($str, 0, $x));
93 $b = intval(substr($str, $x + 1, $len - $x));
94 return;
96 $a = intval($str);
97 $b = -1;
101 * Convert a PHP scalar, array or hash to JS scalar/array/hash. This function is
102 * an analog of json_encode(), but it can work with a non-UTF8 input and does not
103 * analyze the passed data. Output format must be fully JSON compatible.
105 * @param mixed $a Any structure to convert to JS.
106 * @return string JavaScript equivalent structure.
108 function php2js($a=false)
110 if (is_null($a)) return 'null';
111 if ($a === false) return 'false';
112 if ($a === true) return 'true';
113 if (is_scalar($a)) {
114 if (is_float($a)) {
115 // Always use "." for floats.
116 $a = str_replace(",", ".", strval($a));
118 // All scalars are converted to strings to avoid indeterminism.
119 // PHP's "1" and 1 are equal for all PHP operators, but
120 // JS's "1" and 1 are not. So if we pass "1" or 1 from the PHP backend,
121 // we should get the same result in the JS frontend (string).
122 // Character replacements for JSON.
123 static $jsonReplaces = array(
124 array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'),
125 array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"')
127 return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
129 $isList = true;
130 for ($i = 0, reset($a); $i < count($a); $i++, next($a)) {
131 if (key($a) !== $i) {
132 $isList = false;
133 break;
136 $result = array();
137 if ($isList) {
138 foreach ($a as $v) {
139 $result[] = php2js($v);
141 return '[ ' . join(', ', $result) . ' ]'."\n";
142 } else {
143 foreach ($a as $k => $v) {
144 $result[] = php2js($k) . ': ' . php2js($v);
146 return '{ ' . join(', ', $result) . ' }';
150 // составляет список
151 function getListFromArray($array, $i, $mask, $href)
153 $text = "";
154 while ($mask)
156 if ($mask & 1)
158 $data = @$array[$i]; if ($data == "") $data = "$i";
159 if ($href)
160 $text.="<a href=\"".sprintf($href, $i)."\">".$data."</a>";
161 else
162 $text.=$data;
163 if ($mask!=1)
164 $text.=", ";
166 $mask>>=1;
167 $i++;
169 return $text;
171 // составляет список c 0
172 function getListFromArray_0($array, $mask, $href="")
174 return getListFromArray($array, 0, $mask, $href);
176 // составляет список c 1
177 function getListFromArray_1($array, $mask, $href="")
179 return getListFromArray($array, 1, $mask, $href);
182 function getExtendCost($excostid)
184 global $wDB;
185 return $wDB->selectRow('-- CACHE: 1h
186 SELECT * FROM `wowd_item_ex_cost` WHERE `id` = ?d', $excostid);
189 function healthmanaex($hp)
191 echo number_format($hp);
194 function getLootList($lootId, $table, &$totalRecords, $offset=0, $count=0)
196 global $dDB;
197 $totalRecords = 0;
198 $limit = "";
199 if ($count) $limit = "LIMIT $offset, $count";
200 $rows = $dDB->selectPage($totalRecords, "SELECT * FROM `$table`
201 WHERE `entry` = ?d
202 GROUP BY IF (`mincountOrRef` < 0, `mincountOrRef`, `item`)
203 ORDER BY `groupid`, `ChanceOrQuestChance`>0, ABS(`ChanceOrQuestChance`) DESC $limit", $lootId);
204 if (!$rows)
205 return 0;
206 foreach($rows as &$loot)
208 // Group chance
209 if ($loot['ChanceOrQuestChance'] == 0)
211 $group = $loot['groupid'];
212 $chance = 0; $n = 0;
213 foreach($rows as &$g)
214 if ($g['groupid'] == $group)
216 if ($g['ChanceOrQuestChance']>0) $chance+=$g['ChanceOrQuestChance'];
217 else $n++;
219 $chance = round((100 - $chance) / $n, 3);
220 foreach($rows as &$g)
221 if ($g['groupid'] == $group && $g['ChanceOrQuestChance']==0)
222 $g['ChanceOrQuestChance'] =$chance;
224 if ($loot['mincountOrRef'] < 0)
226 // Получаем список
227 $subcount = 0;
228 $loot['item'] = getLootList(-$loot['mincountOrRef'], "reference_loot_template", $subcount);
229 $loot['maxcount'] = $dDB->selectCell("SELECT `maxcount` FROM `$table` WHERE `entry` = ?d AND `mincountOrRef` = ?d", $lootId, $loot['mincountOrRef']);
232 return $rows;
235 //******************************************************************************
236 // Локализация данных
237 //******************************************************************************
238 function localiseCreature(&$creature)
240 global $dDB, $config;
241 $locale = $config['locales_lang'];
242 if ($locale == 0 OR @$creature['Entry'] == 0)
243 return;
244 $lang = $dDB->selectRow('-- CACHE: 1h
245 SELECT
246 `name_loc'.$locale.'` AS `Name`,
247 `subname_loc'.$locale.'` AS `SubName`
248 FROM `locales_creature`
249 WHERE `entry` = ?d', $creature['Entry']);
250 if ($lang)
252 if ($lang['Name']) $creature['Name'] = $lang['Name'];
253 if ($lang['SubName']) $creature['SubName'] = $lang['SubName'];
257 function localiseGameobject(&$go)
259 global $dDB, $config;
260 $locale = $config['locales_lang'];
261 if ($locale == 0 OR $go['entry']==0)
262 return;
263 $lang = $dDB->selectRow('-- CACHE: 1h
264 SELECT
265 `name_loc'.$locale.'` AS `name`,
266 `castbarcaption_loc'.$locale.'` AS `cast_name`
267 FROM `locales_gameobject`
268 WHERE `entry` = ?d', $go['entry']);
269 if ($lang)
271 if ($lang['name']) $go['name'] = $lang['name'];
272 if ($lang['cast_name']) $go['castBarCaption'] = $lang['cast_name'];
276 function localiseQuest(&$quest)
278 global $dDB, $config;
279 $locale = $config['locales_lang'];
280 if ($locale == 0 OR @$quest['entry']==0)
281 return;
282 $lang = $dDB->selectRow('-- CACHE: 1h
283 SELECT
284 `Title_loc'.$locale.'` as `Title`,
285 `Details_loc'.$locale.'` as `Details`,
286 `Objectives_loc'.$locale.'` as `Objectives`,
287 `OfferRewardText_loc'.$locale.'` as `OfferRewardText`,
288 `RequestItemsText_loc'.$locale.'` as `RequestItemsText`,
289 `EndText_loc'.$locale.'` as `EndText`,
290 `CompletedText_loc'.$locale.'` as `CompletedText`,
291 `ObjectiveText1_loc'.$locale.'` as `ObjectiveText1`,
292 `ObjectiveText2_loc'.$locale.'` as `ObjectiveText2`,
293 `ObjectiveText3_loc'.$locale.'` as `ObjectiveText3`,
294 `ObjectiveText4_loc'.$locale.'` as `ObjectiveText4`
295 FROM `locales_quest` WHERE `entry` = ?d', $quest['entry']);
296 if ($lang)
298 if ($lang['Title']) $quest['Title'] = $lang['Title'];
299 if ($lang['Details']) $quest['Details'] = $lang['Details'];
300 if ($lang['Objectives']) $quest['Objectives'] = $lang['Objectives'];
301 if ($lang['OfferRewardText']) $quest['OfferRewardText'] = $lang['OfferRewardText'];
302 if ($lang['RequestItemsText'])$quest['RequestItemsText']= $lang['RequestItemsText'];
303 if ($lang['EndText']) $quest['EndText'] = $lang['EndText'];
304 if ($lang['CompletedText']) $quest['CompletedText'] = $lang['CompletedText'];
305 if ($lang['ObjectiveText1']) $quest['ObjectiveText1'] = $lang['ObjectiveText1'];
306 if ($lang['ObjectiveText2']) $quest['ObjectiveText2'] = $lang['ObjectiveText2'];
307 if ($lang['ObjectiveText3']) $quest['ObjectiveText3'] = $lang['ObjectiveText3'];
308 if ($lang['ObjectiveText4']) $quest['ObjectiveText4'] = $lang['ObjectiveText4'];
312 function localiseItem(&$item)
314 global $dDB, $config;
315 $locale = $config['locales_lang'];
316 if ($locale == 0 OR $item['entry']==0)
317 return;
318 $lang = $dDB->selectRow('-- CACHE: 1h
319 SELECT
320 `name_loc'.$locale.'` AS `name`,
321 `description_loc'.$locale.'` AS `desc`
322 FROM `locales_item`
323 WHERE `entry` = ?d', $item['entry']);
324 if ($lang)
326 if ($lang['name']) $item['name'] = $lang['name'];
327 if ($lang['desc']) $item['description'] = $lang['desc'];
331 function getScalingStatDistribution($id)
333 global $wDB;
334 return $wDB->selectRow('-- CACHE: 1h
335 SELECT * FROM `wowd_scaling_stat_distribution` WHERE `id` = ?d', $id);
337 function getScalingStatValues($level)
339 global $wDB;
340 return $wDB->selectRow('-- CACHE: 1h
341 SELECT * FROM `wowd_scaling_stat_values` WHERE `level` = ?d', $level);
344 function getRandomSuffix($id)
346 global $wDB;
347 return $wDB->selectRow('-- CACHE: 1h
348 SELECT * FROM `wowd_item_random_suffix` WHERE `id` = ?d', $id);
351 function getRandomProperty($id)
353 global $wDB;
354 return $wDB->selectRow('-- CACHE: 1h
355 SELECT * FROM `wowd_item_random_propety` WHERE `id` = ?d', $id);
358 function getRandomPropertyPoint($level, $type, $quality)
360 if ($level < 0 OR $level > 300)
361 return 0;
362 switch ($quality)
364 case 2: $field = "uncommon"; break; // ITEM_QUALITY_UNCOMMON
365 case 3: $field = "rare"; break; // ITEM_QUALITY_RARE
366 case 4: $field = "epic"; break; // ITEM_QUALITY_EPIC
367 default:
368 return 0;
370 switch ($type)
372 case 0: // INVTYPE_NON_EQUIP:
373 case 18: // INVTYPE_BAG:
374 case 19: // INVTYPE_TABARD:
375 case 24: // INVTYPE_AMMO:
376 case 27: // INVTYPE_QUIVER:
377 case 28: // INVTYPE_RELIC:
378 return 0;
379 case 1: // INVTYPE_HEAD:
380 case 4: // INVTYPE_BODY:
381 case 5: // INVTYPE_CHEST:
382 case 7: // INVTYPE_LEGS:
383 case 17: // INVTYPE_2HWEAPON:
384 case 20: // INVTYPE_ROBE:
385 $field.= "_0";
386 break;
387 case 3: // INVTYPE_SHOULDERS:
388 case 6: // INVTYPE_WAIST:
389 case 8: // INVTYPE_FEET:
390 case 10: // INVTYPE_HANDS:
391 case 12: // INVTYPE_TRINKET:
392 $field.= "_1";
393 break;
394 case 2: // INVTYPE_NECK:
395 case 9: // INVTYPE_WRISTS:
396 case 11: // INVTYPE_FINGER:
397 case 14: // INVTYPE_SHIELD:
398 case 16: // INVTYPE_CLOAK:
399 case 23: // INVTYPE_HOLDABLE:
400 $field.= "_2";
401 break;
402 case 13: // INVTYPE_WEAPON:
403 case 21: // INVTYPE_WEAPONMAINHAND:
404 case 22: // INVTYPE_WEAPONOFFHAND:
405 $field.= "_3";
406 break;
407 case 15: // INVTYPE_RANGED:
408 case 25: // INVTYPE_THROWN:
409 case 26: // INVTYPE_RANGEDRIGHT:
410 $field.= "_4";
411 break;
412 default:
413 return 0;
415 global $wDB;
416 return $wDB->selectCell("-- CACHE: 1h
417 SELECT `$field` FROM `wowd_random_property_points` WHERE `itemlevel` = ?d", $level);
420 function getGlyph($entry)
422 global $wDB;
423 return $wDB->selectRow('-- CACHE: 1h
424 SELECT * FROM `wowd_glyphproperties` WHERE `id` = ?d', $entry);
427 function getGlyphName($entry)
429 if ($g=getGlyph($entry))
430 return getSpellName(getSpell($g['SpellId']));
431 return 'Glyph_'.$entry;
434 function getLockTypeNames()
436 global $wDB;
437 return $wDB->selectCol('-- CACHE: 1h
438 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_lock_type`');
440 // Lock
441 function getLockType($id, $asref=1)
443 $l = getLockTypeNames();
444 $name = isset($l[$id]) ? $l[$id] : 'Lock_type_'.$id;
445 if ($asref==1)
446 return '<a href="?s=s&lock='.$id.'">'.$name.'</a>';
447 if ($asref==2)
448 return '<a href="?s=o&lockSkill='.$id.'">'.$name.'</a>';
449 if ($asref==3)
450 return '<a href="?s=o&lockItem='.$id.'">'.$name.'</a>';
451 return $name;
454 // Работа с lock
455 function getLock($id)
457 global $wDB;
458 return $wDB->selectRow('-- CACHE: 1h
459 SELECT * FROM `wowd_lock` WHERE `id` = ?d', $id);
462 // Spellfocus
463 function getSpellFocus($id)
465 global $wDB;
466 return $wDB->selectRow('-- CACHE: 1h
467 SELECT * FROM `wowd_spellfocus` WHERE `id` = ?d', $id);
470 // Spellfocus
471 function getSpellFocusName($id, $reftype=0)
473 $focus = getSpellFocus($id);
474 if ($focus)
476 if ($reftype == 1) return "<a href=?s=s&focus=$id>".$focus['name']."</a>";
477 if ($reftype == 2) return "<a href=?s=o&focus=$id>".$focus['name']."</a>";
478 return $focus['name'];
480 return "Spellfocus_$id";
483 // Работа со скилами
484 function getSkillLineAbility($spellId)
486 global $wDB;
487 return $wDB->selectRow('-- CACHE: 1h
488 SELECT * FROM `wowd_skill_line_ability` WHERE `spellId` = ?d', $spellId);
491 function getSkillLine($id)
493 global $wDB;
494 return $wDB->selectRow('-- CACHE: 1h
495 SELECT * FROM `wowd_skill_line` WHERE `id` = ?d', $id);
498 function getSkillName($skillId, $as_ref=1)
500 $skillLine = getSkillLine($skillId);
501 if ($skillLine)
503 if ($as_ref)
504 return "<a href=\"?skill=$skillId\">".$skillLine['Name']."</a>";
505 else
506 return $skillLine['Name'];
508 return "";
511 function getSkillNameForSpell($spellId, $as_ref=1)
513 if ($SkillLineAbility = getSkillLineAbility($spellId))
514 return getSkillName($SkillLineAbility['skillId'], $as_ref);
515 return "";
518 function show_spell($entry, $iconId=0, $style=0)
520 global $wDB;
521 if (!$iconId)
522 $iconId = $wDB->selectCell('-- CACHE: 1h
523 SELECT `SpellIconID` FROM `wowd_spell` WHERE `id` = ?d', $entry);
524 $icon = getSpellIcon($iconId);
525 echo '<a href="?spell='.$entry.'"><img'.($style?' class='.$style:'').' src="'.$icon.'"></a>';
526 return;
529 function validateText($text)
531 $letter = array("'",'"' ,"<" ,">" ,">" ,"\r","\n" );
532 $values = array("`",'&quot;',"&lt;","&gt;","&gt;","" ,"<br>");
533 return str_replace($letter, $values, $text);
535 function addTooltip($text, $extra='')
537 if ($text=='') return '';
538 return 'onmouseover="Tip(\''.validateText($text).'\''.($extra?','.$extra:'').');"';
541 function getSpellTargetPosition($id)
543 global $dDB;
544 return $dDB->selectRow("SELECT * FROM `spell_target_position` WHERE `id` = ?d", $id);
547 function getSpellScriptTarget($id)
549 global $dDB;
550 return $dDB->select("SELECT * FROM `spell_script_target` WHERE `entry` = ?d", $id);
553 function getEnchantment($enchantmentId)
555 global $wDB;
556 return $wDB->selectRow('-- CACHE: 1h
557 SELECT * FROM `wowd_item_enchantment` WHERE `id` = ?d', $enchantmentId);
560 function getEnchantmentDesc($enchantment)
562 if ($enc = getEnchantment($enchantment))
563 return "<a href=?enchant=$enchantment>".validateText($enc['description'])."</a>";
564 return "Enchant $enchantment";
567 function getGemInfo($GemId)
569 global $wDB;
570 return $wDB->selectRow('-- CACHE: 1h
571 SELECT * FROM `wowd_gemproperties` WHERE `id` = ?d', $GemId);
574 function getGemProperties($GemProperties)
576 if ($gem = getGemInfo($GemProperties))
577 return getEnchantmentDesc($gem['spellitemenchantement']);
578 return "Gem Properties id - $GemProperties";
581 //********************************************************************************
582 function getCreature($creature_id, $fields = "*")
584 global $dDB;
585 if ($creature = $dDB->selectRow("-- CACHE: 1h
586 SELECT $fields FROM `creature_template` WHERE `Entry` = ?d", $creature_id))
587 localiseCreature($creature);
588 return $creature;
591 function getCreatureName($creature_id, $as_ref=1)
593 if ($Creature=getCreature($creature_id, "`Entry`, `Name`"))
595 if ($Creature['Name']=="") $Creature['Name'] = "npc_$creature_id";
596 if ($as_ref)
597 return "<a href=?npc=".$Creature['Entry'].">".$Creature['Name']."</a>";
598 return $Creature['Name'];
600 return "Unknown creature - $creature_id";
603 function getCreatureRank($rank, $as_ref=1)
605 global $gCreatureRank;
606 $name = @$gCreatureRank[$rank];
607 if (empty($name)) $name = "Rank_".$rank;
608 if ($as_ref)
609 return "<a href=\"?s=n&rank=$rank\">".$name."</a>";
610 return $name;
613 function getCreatureFamilyNames()
615 global $wDB;
616 return $wDB->selectCol('-- CACHE: 1h
617 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_creature_family`');
620 function getCreatureFamily($family, $as_ref=1)
622 $l = getCreatureFamilyNames();
623 $name = isset($l[$family]) ? $l[$family] : 'family_'.$family;
624 if ($as_ref)
625 return '<a href="?s=n&family='.$family.'">'.$name.'</a>';
626 return $name;
629 // Creature type
630 function getCreatureTypeNames()
632 global $wDB;
633 return $wDB->selectCol('-- CACHE: 1h
634 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_creature_type`');
637 function getCreatureType($i, $as_ref=1)
639 $t = getCreatureTypeNames();
640 $name = isset($t[$i]) ? $t[$i] : 'Type_'.$i;
641 if ($as_ref)
642 return '<a href="?s=n&type='.$i.'">'.$name.'</a>';
643 return $name;
646 function getCreatureTypeList($mask, $as_ref=1)
648 $t = getCreatureTypeNames();
649 if ($as_ref)
650 return getListFromArray_1($t, $mask, "?s=n&type=%d");
651 return getListFromArray_1($t, $mask);
654 function getCreatureCount($creature_id)
656 global $dDB;
657 return $dDB->selectCell("SELECT count(*) FROM `creature` WHERE `id` = ?d", $creature_id);
660 function getCreatureFlagName($flag, $as_ref=1)
662 global $gCreatureFlags;
663 if ($as_ref)
664 return '<a href="?s=n&flag='.$flag.'">'.@$gCreatureFlags[$flag].'</a>';
665 return @$gCreatureFlags[$flag];
668 function getCreatureFlagsList($mask, $as_ref=1)
670 global $gCreatureFlags;
671 if ($as_ref)
672 return getListFromArray_0($gCreatureFlags, $mask, "?s=n&flag=%d");
673 return getListFromArray_0($gCreatureFlags, $mask);
676 function getCreatureRewRate($faction_id)
678 global $dDB;
679 $creature = $dDB->selectCell("-- CACHE: 1h
680 SELECT `creature_rate` FROM `reputation_reward_rate` WHERE `faction` = ?d", $faction_id);
681 if (!$creature)
682 $creature=1;
683 return $creature;
686 function getCreatureEvent($creature_guid)
688 global $dDB;
689 return $dDB->selectCell("-- CACHE: 1h
690 SELECT `event` FROM `game_event_creature` WHERE `guid` = ?d", $creature_guid);
693 function getCreaturePool($creature_guid)
695 global $dDB;
696 return $dDB->selectCell("-- CACHE: 1h
697 SELECT `pool_entry` FROM `pool_creature` WHERE `guid` = ?d", $creature_guid);
700 function getCreaturePoolTemplate($creature_id)
702 global $dDB;
703 return $dDB->selectCell("-- CACHE: 1h
704 SELECT `pool_entry` FROM `pool_creature_template` WHERE `id` = ?d", $creature_id);
706 //********************************************************************************
707 function getGameobject($gameobject_id, $fields="*")
709 global $dDB;
710 if ($go = $dDB->selectRow("-- CACHE: 1h
711 SELECT $fields FROM `gameobject_template` WHERE `entry` = ?d", $gameobject_id))
712 localiseGameobject($go);
713 return $go;
715 function getGameobjectName($gameobject_id, $as_ref=1)
717 if ($gameobject=getGameobject($gameobject_id, "`entry`, `name`"))
719 if (empty($gameobject['name'])) $gameobject['name'] = "go_$gameobject_id";
720 if ($as_ref)
721 return "<a href=?object=".$gameobject['entry'].">".$gameobject['name']."</a>";
722 return $gameobject['name'];
724 return "Unknown go - $gameobject_id";
727 function getGameobjectType($i, $as_ref=1)
729 global $gameobjectType;
730 $type = @$gameobjectType[$i];
731 if ($type!="")
733 if ($as_ref)
734 return "<a href=?s=o&type=".$i.">".$type."</a>";
735 return $type;
737 return "Type_$i";
740 function getGameobjectCount($gameobject_id)
742 global $dDB;
743 return $dDB->selectCell("SELECT count(*) FROM `gameobject` WHERE `id` = ?d", $gameobject_id);
746 function getGameobjectEvent($gameobject_guid)
748 global $dDB;
749 return $dDB->selectCell("-- CACHE: 1h
750 SELECT `event` FROM `game_event_gameobject` WHERE `guid` = ?d", $gameobject_guid);
753 function getGameobjectPool($gameobject_guid)
755 global $dDB;
756 return $dDB->selectCell("-- CACHE: 1h
757 SELECT `pool_entry` FROM `pool_gameobject` WHERE `guid` = ?d", $gameobject_guid);
760 function getGameobjectPoolTemplate($gameobject_id)
762 global $dDB;
763 return $dDB->selectCell("-- CACHE: 1h
764 SELECT `pool_entry` FROM `pool_gameobject_template` WHERE `id` = ?d", $gameobject_id);
766 //********************************************************************************
767 function getFaction($faction_id, $fields="*")
769 global $wDB;
770 return $wDB->selectRow("-- CACHE: 1h
771 SELECT $fields FROM `wowd_faction` WHERE `id` = ?d", $faction_id);
773 function getFactionName($faction_id, $as_ref=1)
775 if ($faction = getFaction($faction_id, "`name`"))
776 $name = $faction['name'];
777 else
778 $name = "Faction ($faction_id)";
779 if ($as_ref)
780 $name = '<a href="?faction='.$faction_id.'">'.$name.'</a>';
781 return $name;
784 function getFactionTemplate($faction_id)
786 global $wDB;
787 return $wDB->selectRow('-- CACHE: 1h
788 SELECT * FROM `wowd_faction_template` WHERE `id` = ?d', $faction_id);
791 function getFactionTemplateName($faction_id)
793 if ($faction_id==0)
794 return 0;
795 if ($faction_template = getFactionTemplate($faction_id))
796 return getFactionName($faction_template['faction']);
797 return "Faction template - $faction_id";
800 function getBaseReputationForFaction($faction, $race, $class)
802 if (empty($faction)) return 0;
803 $racemask = 1<<($race -1);
804 $classmask = 1<<($class-1);
805 for ($i=0;$i<4;$i++)
806 if ($faction['BaseRepRaceMask_'.$i] & $racemask AND
807 ($faction['BaseRepClassMask_'.$i] == 0 OR $faction['BaseRepClassMask_'.$i] & $classmask))
808 return $faction['BaseRepValue_'.$i];
809 return 0;
811 function getBaseReputationFlagForFaction($faction, $race, $class)
813 if (empty($faction)) return 0;
814 $racemask = 1<<($race -1);
815 $classmask = 1<<($class-1);
816 for ($i=0;$i<4;$i++)
817 if ($faction['BaseRepRaceMask_'.$i] & $racemask AND
818 ($faction['BaseRepClassMask_'.$i] == 0 OR $faction['BaseRepClassMask_'.$i] & $classmask))
819 return $faction['ReputationFlags_'.$i];
820 return 0;
822 function getReputationRankName($rep)
824 global $gReputationRank;
825 $text = @$gReputationRank[$rep];
826 if ($text == "")
827 $text = "Err Rep Rank $rep";
828 return $text;
830 function getReputationDataFromReputation($rep)
832 global $gReputationRank;
833 $gBaseRep = -42000;
834 $gRepStep = array(36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000);
835 $current = $gBaseRep;
836 for ($i=0;$i<8;$current+=$gRepStep[$i],$i++)
837 if ($current + $gRepStep[$i] > $rep)
838 return array('rank'=>$i, 'rank_name'=>$gReputationRank[$i], 'rep'=>$rep - $current, 'max'=>$gRepStep[$i]);
839 return array('rank'=>7, 'rank_name'=>$gReputationRank[7], 'rep'=>$gRepStep[7], 'max'=>$gRepStep[7]);
841 function getFactionType($id)
843 global $gFactionType;
844 return $gFactionType[$id];
847 function getArea($Zone_id, $fields="*")
849 global $wDB;
850 return $wDB->selectRow("-- CACHE: 1h
851 SELECT $fields FROM `wowd_zones` WHERE `id` = ?d", $Zone_id);
854 function getAreaName($Zone_id, $as_ref=1)
856 $zone = getArea($Zone_id, '`name`');
857 if ($zone)
859 $name = $zone['name'];
860 if ($as_ref)
861 $name = '<a href="?zone='.$Zone_id.'">'.$name.'</a>';
863 else
864 $name = "Unknown area - $Zone_id";
865 return $name;
868 function getFullAreaName($Zone_id, $as_ref=1)
870 $zone = getArea($Zone_id, '`name`, `zone_id`');
871 if ($zone)
873 $name = $zone['name'];
874 if ($as_ref)
875 $name = '<a href="?zone='.$Zone_id.'">'.$name.'</a>';
876 if ($zone['zone_id'])
877 $name = getAreaName($zone['zone_id'], $as_ref).' - '.$name;
879 else
880 $name = "Unknown area - $Zone_id";
881 return $name;
884 function getMapName($id)
886 global $wDB;
887 $l = $wDB->selectCol('-- CACHE: 1h
888 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_map`');
889 return isset($l[$id]) ? $l[$id] : 'map_'.$id;
892 FACTION_MASK_PLAYER = 1, // any player
893 FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team
894 FACTION_MASK_HORDE = 4, // player or creature from horde team
895 FACTION_MASK_MONSTER = 8 // aggressive creature from monster team
897 function getLoyality($faction_id)
899 $faction_template=getFactionTemplate($faction_id);
900 if (!$faction_template)
901 return "??";
902 $loyality = '';
903 if ($faction_template['friendlyMask'])
905 $loyality.= '<span class=friendly>';
906 if ($faction_template['friendlyMask']&1) $loyality.='AH';
907 else
909 if ($faction_template['friendlyMask']&2) $loyality.='A';
910 if ($faction_template['friendlyMask']&4) $loyality.='H';
911 // if ($faction_template[friendlyMask]&8) $loyality.='M';
913 $loyality.= '</span>';
915 if ($faction_template['hostileMask'])
917 $loyality.= '<span class=hostile>';
918 if ($faction_template['hostileMask']&1) $loyality.='AH';
919 else
921 if ($faction_template['hostileMask']&2) $loyality.='A';
922 if ($faction_template['hostileMask']&4) $loyality.='H';
923 // if ($faction_template['hostileMask']&8) $loyality.='M';
925 $loyality.= '</span>';
927 if (($faction_template['friendlyMask']&7)==0 && ($faction_template['hostileMask']&7) == 0)
929 $loyality.='<span class=neitral>AH</span>';
931 return $loyality;
934 //********************************************************************************
935 function getQuest($quest_id, $fields = "*")
937 global $dDB, $config;
938 $quest = $dDB->selectRow("-- CACHE: 1h
939 SELECT $fields FROM `quest_template` WHERE `entry` = ?d", $quest_id);
940 if ($quest)
941 localiseQuest($quest);
942 return $quest;
945 function getQuestName($quest_id, $ashref=1)
947 if ($quest = getQuest($quest_id, "`entry`, `Title`"))
949 if (empty($quest['Title'])) $quest['Title'] = "quest_$quest_id";
950 if ($ashref)
951 return "<a href=?quest=".$quest['entry'].">".$quest['Title']."</a>";
952 return $quest['Title'];
954 return "Unknown quest - $quest_id";
957 function getQuestOld($quest_id)
959 global $dDB;
960 return $dDB->selectCell("-- CACHE: 1h
961 SELECT `entry` FROM `quest_template` WHERE (`Title` LIKE '%<CHANGE TO GOSSIP>%' OR `Title` LIKE '%EPRECATE%' OR `Title` LIKE '%DEPRICATED%' OR `Title` LIKE '%REUSE%' OR `Title` LIKE '%<NYI>%' OR `Title` LIKE '%COPY' OR `Title` LIKE '%UNUSED%' OR `Title` LIKE '%<TXT>%' OR `Title` LIKE '%ZZOLD%' OR `Title` LIKE '%[PH]%' OR `Title` LIKE '%[%') AND `entry` = ?d", $quest_id);
964 function getQuestSort($sort)
966 global $wDB;
967 $q = $wDB->selectCol('-- CACHE: 1h
968 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_quest_sort`');
969 return isset($q[$sort]) ? $q[$sort] : 'Sort_'.$sort;
972 function getQuestType($type)
974 global $wDB;
975 $q = $wDB->selectCol('-- CACHE: 1h
976 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_quest_info`');
977 return isset($q[$type]) ? $q[$type] : 'Info_'.$type;
980 function getNumPalayersCompletedQuest($entry)
982 global $cDB;
983 return $cDB->selectCell("SELECT count(*) FROM `character_queststatus` WHERE `quest` = '$entry' AND `status` = '1' AND `rewarded`='1'");
986 function getNumPalayersWithThisQuest($entry)
988 global $cDB;
989 return $cDB->selectCell("SELECT count(*) FROM `character_queststatus` WHERE quest = '$entry' AND (`status` = '0' OR `status` = '3')");
992 function getQuestXPValue($quest)
994 if ($quest['QuestLevel'] > 0)
995 $rawXPcount=getRewQuestXP($quest['QuestLevel']);
996 else
997 $rawXPcount=getRewQuestXP(79);
999 foreach ($rawXPcount as $field)
1001 $realXP = $field['Field'.($quest['RewXPId']+1)];
1003 return $realXP;
1006 function getRewQuestXP($questlevel_id)
1008 global $wDB;
1009 return $wDB->select("-- CACHE: 1h
1010 SELECT * FROM `wowd_questxp` WHERE `id` = ?d", $questlevel_id);
1013 function getRepRewRate($faction_id)
1015 global $dDB;
1016 $faction = $dDB->selectCell("-- CACHE: 1h
1017 SELECT `quest_rate` FROM `reputation_reward_rate` WHERE `faction` = ?d", $faction_id);
1018 if (!$faction)
1019 $faction=1;
1020 return $faction;
1023 function getRepSpillover($faction_id)
1025 global $dDB;
1026 return $dDB->select("-- CACHE: 1h
1027 SELECT * FROM `reputation_spillover_template` WHERE `faction` = ?d", $faction_id);
1030 function getGameEventQuest($quest_id)
1032 global $dDB;
1033 return $dDB->selectCell("-- CACHE: 1h
1034 SELECT `event` FROM `game_event_quest` WHERE `quest` = ?d", $quest_id);
1037 function getGameEventName($event_id)
1039 global $dDB;
1040 return $dDB->selectCell("-- CACHE: 1h
1041 SELECT `description` FROM `game_event` WHERE `entry` = ?d", $event_id);
1044 function getGameEventActive()
1046 global $cDB;
1047 return $cDB->select("SELECT `event` FROM `game_event_status`");
1050 function getGameEventActiveName($event_id)
1052 global $dDB;
1053 return $dDB->selectCell("-- CACHE: 1h
1054 SELECT `holiday` FROM `game_event` WHERE `entry` = ?d", $event_id);
1057 function getGameHolidayName($holiday_id)
1059 global $dDB;
1060 return $dDB->selectCell("-- CACHE: 1h
1061 SELECT `description` FROM `game_event` WHERE `holiday` = ?d", $holiday_id);
1064 function getTeamContributionPoints($level_id)
1066 global $wDB;
1067 return $wDB->selectCell("-- CACHE: 1h
1068 SELECT `Field1` FROM `wowd_teamcontributionpoints` WHERE `id` = ?d", $level_id);
1071 function getNpcQuestrelation($npc_id)
1073 global $dDB;
1074 return $dDB->selectCell("SELECT count(*) FROM `creature_questrelation` WHERE `id` = ?d", $npc_id);
1077 function getNpcInvolvedrelation($npc_id)
1079 global $dDB;
1080 return $dDB->selectCell("SELECT count(*) FROM `creature_involvedrelation` WHERE `id` = ?d", $npc_id);
1082 //********************************************************************************
1083 $Quality = array(
1084 '0'=>'quality0',
1085 '1'=>'quality1',
1086 '2'=>'quality2',
1087 '3'=>'quality3',
1088 '4'=>'quality4',
1089 '5'=>'quality5',
1090 '6'=>'quality6',
1091 '7'=>'quality7'
1094 function getItem($item_id, $fields = "*")
1096 global $dDB, $config;
1097 $item = $dDB->selectRow("-- CACHE: 1h
1098 SELECT $fields FROM `item_template` WHERE `entry` = ?d", $item_id);
1099 if ($item)
1100 localiseItem($item);
1101 return $item;
1104 function getItemName($item_id)
1106 $item = getItem($item_id, "`entry`, `name`");
1107 if ($item)
1108 return $item['name'];
1109 return "Unknown item - $item_id";
1112 function getItemFlags2($item_id)
1114 global $dDB, $config;
1115 $item = $dDB->selectCell("-- CACHE: 1h
1116 SELECT `Flags2` FROM `item_template` WHERE `entry` = ?d", $item_id);
1117 return $item;
1120 function getMail($quest_id)
1122 global $dDB, $config;
1123 $getMailId = $dDB->selectCell("-- CACHE: 1h
1124 SELECT `datalong` FROM `dbscripts_on_quest_end` WHERE `command` = 38 AND `id` = ?d", $quest_id);
1125 return $getMailId;
1128 function getMailTime($quest_id)
1130 global $dDB, $config;
1131 $getMailTime = $dDB->selectCell("-- CACHE: 1h
1132 SELECT `dataint` FROM `dbscripts_on_quest_end` WHERE `command` = 38 AND `id` = ?d", $quest_id);
1133 return $getMailTime;
1136 function getItemMail($item_id)
1138 global $dDB, $config;
1139 $item = $dDB->selectCell("-- CACHE: 1h
1140 SELECT `item` FROM `mail_loot_template` WHERE `entry` = ?d", $item_id);
1141 return $item;
1144 function getItemBonusText($i, $amount)
1146 global $iBonus;
1147 $text = @$iBonus[$i];
1148 if ($text == "") $text = "Err stat $i - %d";
1149 if ($i >=0 && $i < 8 && $amount > 0)
1150 return sprintf("+".$text, $amount);
1151 return sprintf($text, $amount);
1154 function getInventoryType($i, $as_ref=1)
1156 global $gInventoryType;
1157 $name = @$gInventoryType[$i];
1158 if ($name=="") $name = "InvType_$i";
1159 if ($as_ref)
1160 return "<a href=\"?s=i&type=$i\">".$name."</a>";
1161 return $name;
1164 function getInventoryTypeList($mask, $as_ref=1)
1166 global $gInventoryType;
1167 if ($as_ref)
1168 return getListFromArray_0($gInventoryType, $mask, "?s=i&type=%d");
1169 return getListFromArray_0($gInventoryType, $mask);
1172 function getClassName($class, $as_ref=1)
1174 global $itemClassSubclass;
1175 if ($as_ref)
1176 return "<a href=\"?s=i&class=$class\">".$itemClassSubclass["$class"]."</a>";
1177 else
1178 return $itemClassSubclass["$class"];
1181 function getSubclassName($class,$subclass, $as_ref=1)
1183 global $itemClassSubclass;
1184 if ($subclass>=0)
1186 $names = explode(":",$itemClassSubclass["$class"."."."$subclass"]);
1187 if (@$names[1]) $name = $names[1];
1188 else $name = $names[0];
1189 if ($as_ref)
1190 return "<a href=\"?s=i&class=$class.$subclass\">".$name."</a>";
1191 else
1192 return $name;
1194 return getClassName($class, $as_ref);
1197 function getShortSubclassName($class,$subclass, $as_ref=1)
1199 global $itemClassSubclass;
1200 if ($subclass>=0)
1202 $names = explode(":",$itemClassSubclass["$class"."."."$subclass"]);
1203 $name = $names[0];
1204 if ($as_ref)
1205 return "<a href=\"?s=i&class=$class.$subclass\">".$name."</a>";
1206 else
1207 return $name;
1209 return getClassName($class, $as_ref);
1212 function getSubclassList($class, $mask, $as_ref=1)
1214 if ($mask == 0)
1215 return 0;
1216 $text = "";
1217 $i=0;
1218 while ($mask)
1220 if ($mask & 1) {$text.=getSubclassName($class,$i,$as_ref);if ($mask!=1) $text.=", ";}
1221 $mask>>=1;
1222 $i++;
1224 return $text;
1227 function getSpellIconName($icon_id)
1229 global $wDB;
1230 $name = $wDB->selectCell('-- CACHE: 1h
1231 SELECT `name` FROM `wowd_spellicon` WHERE `id` = ?d', $icon_id);
1232 if ($name) return strtolower($name.'.jpg');
1233 else return 'wowunknownitem01.jpg';
1236 $bwicon_mode = false;
1237 function setBwIconMode() {global $bwicon_mode; $bwicon_mode = true;}
1238 function unsetBwIconMode() {global $bwicon_mode; $bwicon_mode = false;}
1240 function getSpellIcon($icon_id)
1242 global $wDB, $bwicon_mode;
1243 if ($bwicon_mode){$dir = 'bwicons';$g_bwicon_mode = 0;}
1244 else $dir = 'icons';
1245 return 'images/'.$dir.'/'.getSpellIconName($icon_id);
1249 function getItemIconName($icon_id)
1251 global $wDB;
1252 $name = $wDB->selectCell('-- CACHE: 1h
1253 SELECT `name` FROM `wowd_itemicon` WHERE `id` = ?d', $icon_id);
1254 if ($name) return strtolower($name.'.jpg');
1255 else return 'wowunknownitem01.jpg';
1258 function getItemIcon($icon_id)
1260 global $wDB, $bwicon_mode;
1261 if ($bwicon_mode){$dir = 'bwicons';$g_bwicon_mode = 0;}
1262 else $dir = 'icons';
1263 return 'images/'.$dir.'/'.getItemIconName($icon_id);
1266 function getItemIconFromItemId($item_id)
1268 global $dDB, $bwicon_mode;
1269 if ($icon = $dDB->selectCell("SELECT `displayid` FROM `item_template` WHERE `entry` = ?d", $item_id))
1270 return getItemIcon($icon, $bwicon_mode);
1271 return 'images/icons/wowunknownitem01.jpg';
1274 function getItemIconFromItemData($item_data)
1276 if ($item = getItem($item_data[ITEM_FIELD_ENTRY]))
1277 return getItemIcon($item['displayid']);
1278 return 'images/icons/wowunknownitem01.jpg';
1281 function getItemSet($item_set_id)
1283 global $wDB;
1284 return $wDB->selectRow('-- CACHE: 1h
1285 SELECT * FROM `wowd_itemset` WHERE `id` = ?d', $item_set_id);
1288 function getItemData($guid)
1290 global $cDB;
1291 return explode(' ', $cDB->selectCell("SELECT `data` FROM `item_instance` WHERE `guid` = ?d", $guid));
1294 function getRecipeItem($recipe)
1296 global $wDB;
1297 if ($recipe['spellid_1'] == 483)
1299 // Получаем спелл которому обучает
1300 $spell = getSpell($recipe['spellid_2']);
1301 if ($spell = getSpell($recipe['spellid_2']))
1302 return getItem($spell['EffectItemType_1']);
1304 return 0;
1307 function getCount($count)
1309 if ($count>1) return "($count)";
1310 return "";
1313 function getRecipeReqString($spell)
1315 $text = "";
1316 if ($spell['Reagent_1']) $text.=getItemName($spell['Reagent_1']).getCount($spell['ReagentCount_1']);
1317 if ($spell['Reagent_2']) $text.=", ".getItemName($spell['Reagent_2']).getCount($spell['ReagentCount_2']);
1318 if ($spell['Reagent_3']) $text.=", ".getItemName($spell['Reagent_3']).getCount($spell['ReagentCount_3']);
1319 if ($spell['Reagent_4']) $text.=", ".getItemName($spell['Reagent_4']).getCount($spell['ReagentCount_4']);
1320 if ($spell['Reagent_5']) $text.=", ".getItemName($spell['Reagent_5']).getCount($spell['ReagentCount_5']);
1321 if ($spell['Reagent_6']) $text.=", ".getItemName($spell['Reagent_6']).getCount($spell['ReagentCount_6']);
1322 if ($spell['Reagent_7']) $text.=", ".getItemName($spell['Reagent_7']).getCount($spell['ReagentCount_7']);
1323 if ($spell['Reagent_8']) $text.=", ".getItemName($spell['Reagent_8']).getCount($spell['ReagentCount_8']);
1324 return $text;
1327 function text_show_item($entry, $iconId = 0, $style = 0)
1329 global $dDB, $config;
1330 if (!$iconId)
1331 $iconId = $dDB->selectCell('-- CACHE: 1h
1332 SELECT `displayid` FROM `item_template` WHERE `entry` = ?d', $entry);
1333 $icon = getItemIcon($iconId);
1334 $text = '<a href="?item='.$entry.'"><img'.($style?' class='.$style:'').' src="'.$icon.'"></a>';
1335 return $text;
1338 function show_item($entry, $iconId = 0, $style = 'item')
1340 echo text_show_item($entry, $iconId, $style);
1343 function getborderText($text, $posx = 'left', $dx=0, $posy = 'top', $dy=0)
1345 return
1346 "<div style=\"position: absolute; $posx: ".($dx-1)."px; $posy: ".($dy-1)."px; color: black;\">$text</div>
1347 <div style=\"position: absolute; $posx: ".($dx-1)."px; $posy: ".($dy+1)."px; color: black;\">$text</div>
1348 <div style=\"position: absolute; $posx: ".($dx+1)."px; $posy: ".($dy-1)."px; color: black;\">$text</div>
1349 <div style=\"position: absolute; $posx: ".($dx+1)."px; $posy: ".($dy+1)."px; color: black;\">$text</div>
1350 <div style=\"position: absolute; $posx: ".($dx )."px; $posy: ".($dy-1)."px; color: black;\">$text</div>
1351 <div style=\"position: absolute; $posx: ".($dx )."px; $posy: ".($dy+1)."px; color: black;\">$text</div>
1352 <div style=\"position: absolute; $posx: ".($dx-1)."px; $posy: ".($dy )."px; color: black;\">$text</div>
1353 <div style=\"position: absolute; $posx: ".($dx+1)."px; $posy: ".($dy )."px; color: black;\">$text</div>
1354 <div style=\"position: absolute; $posx: ".($dx )."px; $posy: ".($dy )."px; color: white;\">$text</div>";
1356 function show_item_by_data($item_data, $style='item', $posx=0, $posy=0)
1358 $guid = $item_data[ITEM_FIELD_GUID];
1360 if (@$item_data[ITEM_FIELD_TYPE] == TYPE_ITEM)
1361 $count = $item_data[ITEM_FIELD_STACK_COUNT];
1362 else if (@$item_data[ITEM_FIELD_TYPE] == TYPE_CONTAINER)
1363 $count = $item_data[CONTAINER_FIELD_NUM_SLOTS];
1364 else
1365 return;
1366 $position="";
1367 if ($posx OR $posy)
1368 $position.= 'style="position: absolute; left: '.$posx.'px; top: '.$posy.'px; border: 0px;"';
1369 $icon = getItemIconFromItemData($item_data);
1370 if ($count == 1)
1372 echo '<a style="float: left;" href="?item=g'.$guid.'">';
1373 echo "<img class=$style src='$icon' $position></a>";
1375 else
1377 if (empty($position))
1378 $position = "style=\"position: relative; left: 0px;top: 0px; border: 0px;float: left;\"";
1379 echo "\n<div class=$style $position>";
1380 echo '<a href="?item=g'.$guid.'"><img class="'.$style.'" src="'.$icon.'"></a>';
1381 echo getborderText($count, 'right', 3, 'bottom', 1);
1382 echo "</div>";
1386 function show_item_by_guid($guid, $style='item', $posx=0, $posy=0)
1388 if ($guid==0)
1389 return;
1390 if ($item_data = getItemData($guid))
1391 show_item_by_data($item_data, $style, $posx, $posy);
1394 function show_item_from_char($id, $guid, $style='item', $posx=0, $posy=0, $empty_item)
1396 global $cDB;
1397 if ($id != 0)
1399 $item_data = $cDB->selectCell("SELECT `guid` FROM `item_instance` WHERE `owner_guid`=?d AND (SUBSTRING_INDEX( SUBSTRING_INDEX(`data` , ' ' , 9) , ' ' , -1 )+0)=?d AND (SUBSTRING_INDEX( SUBSTRING_INDEX(`data` , ' ' , 4) , ' ' , -1 )+0)=$id", $guid, $guid, $id);
1400 if ($item_data = getItemData($item_data))
1401 show_item_by_data($item_data, $style, $posx, $posy);
1403 else { empty_show_item_from_char($style, $posx, $posy, $empty_item); }
1406 function empty_show_item_from_char($style='item', $posx=0, $posy=0, $empty_item="")
1408 switch ($empty_item):
1409 case ("head"): $icon = "images/player_info/empty_icon/head.png"; break;
1410 case ("neck"): $icon = "images/player_info/empty_icon/neck.png"; break;
1411 case ("shoulder"): $icon = "images/player_info/empty_icon/shoulder.png"; break;
1412 case ("back"): $icon = "images/player_info/empty_icon/back.png"; break;
1413 case ("chest"): $icon = "images/player_info/empty_icon/chest.png"; break;
1414 case ("shirt"): $icon = "images/player_info/empty_icon/shirt.png"; break;
1415 case ("tabard"): $icon = "images/player_info/empty_icon/tabard.png"; break;
1416 case ("wrist"): $icon = "images/player_info/empty_icon/wrist.png"; break;
1417 case ("gloves"): $icon = "images/player_info/empty_icon/gloves.png"; break;
1418 case ("belt"): $icon = "images/player_info/empty_icon/belt.png"; break;
1419 case ("legs"): $icon = "images/player_info/empty_icon/legs.png"; break;
1420 case ("feet"): $icon = "images/player_info/empty_icon/feet.png"; break;
1421 case ("finger"): $icon = "images/player_info/empty_icon/finger.png"; break;
1422 case ("trinket"): $icon = "images/player_info/empty_icon/trinket.png"; break;
1423 case ("main"): $icon = "images/player_info/empty_icon/main.png"; break;
1424 case ("off"): $icon = "images/player_info/empty_icon/off.png"; break;
1425 case ("ranged"): $icon = "images/player_info/empty_icon/ranged.png"; break;
1426 endswitch;
1428 if ($posx OR $posy) { $position = 'style="position: absolute; left: '.$posx.'px; top: '.$posy.'px; border: 0px;"'; }
1429 if (empty($position)) { $position = "style=\"position: relative; left: 0px;top: 0px; border: 0px;float: left;\""; }
1430 echo"\n<div class=$style $position><img class='".$style."' src='".$icon."'></div>";
1433 function getConditionItem($condition_id)
1435 global $dDB;
1436 return $dDB->select("-- CACHE: 1h
1437 SELECT * FROM `conditions` WHERE `condition_entry` = ?d", $condition_id);
1440 //********************************************************************************
1441 function getGuild($id)
1443 global $cDB;
1444 return $cDB->selectRow('-- CACHE: 1h
1445 SELECT * FROM `guild` WHERE `guildid` = ?d', $id);
1448 function getGuildName($id)
1450 global $cDB;
1451 $name = $cDB->selectCell('-- CACHE: 1h
1452 SELECT `name` FROM `guild` WHERE `guildid` = ?d', $id);
1453 return $name ? $name : 'Unknown';
1456 function getGuildRankList($id)
1458 global $cDB;
1459 $rows = $cDB->select('-- CACHE: 1h
1460 SELECT * FROM `guild_rank` WHERE `guildid` = ?d ORDER BY `rid`', $id);
1461 $rankList=array();
1462 if ($rows)
1463 foreach ($rows as $rank)
1464 $rankList[$rank['rid']] = $rank;
1465 return $rankList;
1467 //********************************************************************************
1468 function getCharacter($character_id, $fields = "*")
1470 global $cDB;
1471 return $cDB->selectRow("-- CACHE: 1h
1472 SELECT $fields FROM `characters` WHERE `guid` = ?d", $character_id);
1475 function getCharacterStats($character_id, $fields = "*")
1477 global $cDB;
1478 return $cDB->selectRow("-- CACHE: 1h
1479 SELECT $fields FROM `character_stats` WHERE `guid` = ?d", $character_id);
1482 function getCharacterName($character_id)
1484 global $cDB;
1485 $c = getCharacter($character_id, $fields = '`name`');
1486 return $c ? $c['name'] : 'Unknown';
1489 function getGender($gender)
1491 global $gGenderType;
1492 return $gGenderType[$gender];
1495 function getClassNames()
1497 global $wDB;
1498 return $wDB->selectCol('-- CACHE: 1h
1499 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_chr_classes`');
1502 function getClass($class)
1504 $l = getClassNames();
1505 return isset($l[$class]) ? $l[$class] : 'class_'.$class;
1508 function getAllowableClass($mask)
1510 $mask&=0x5FF;
1511 // Return zero if for all class (or for none
1512 if ($mask == 0x5FF OR $mask == 0)
1513 return 0;
1514 return getListFromArray_1(getClassNames(), $mask);
1517 function getQAllowableClass($mask)
1519 $mask&=0x5FF;
1520 // Return zero if for all class (or for none
1521 if ($mask == 0x5FF OR $mask == 0)
1522 return 0;
1523 return getListFromArray_1(getClassNames(), $mask, "?s=q&RedClass=%d");
1527 function getRaceNames()
1529 global $wDB;
1530 return $wDB->selectCol('-- CACHE: 1h
1531 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_chr_races`');
1534 function getRace($race)
1536 $l = getRaceNames();
1537 return isset($l[$race]) ? $l[$race] : 'race_'.$race;
1540 function getAllowableRace($mask)
1542 $mask&=0x7FF;
1543 // Return zero if for all class (or for none
1544 if ($mask == 0x7FF OR $mask == 0)
1545 return 0;
1546 return getListFromArray_1(getRaceNames(), $mask);
1549 function getRating($level)
1551 global $wDB;
1552 return $wDB->selectRow('-- CACHE: 1h
1553 SELECT * FROM `wowd_rating` WHERE `level` = ?d', $level);
1556 //********************************************************************************
1557 function getPlayerFaction($race)
1559 global $wDB;
1560 $l = $wDB->selectCol('-- CACHE: 1h
1561 SELECT `id` AS ARRAY_KEY, `team` FROM `wowd_chr_races`');
1562 return isset($l[$race]) ? $l[$race] : 2;
1564 function getFactionImage($race)
1566 $faction = getPlayerFaction($race);
1567 if ($faction == 0)
1568 return "images/player_info/factions_img/alliance.gif";
1569 if ($faction == 1)
1570 return "images/player_info/factions_img/horde.gif";
1571 return 0;
1574 function getRaceImage($race, $genderid)
1576 return "images/player_info/race_img/".$race."_".$genderid.".gif";
1579 function getClassImage($class)
1581 return "images/player_info/class_img/".$class.".gif";
1584 function getFamilyImage($family)
1586 global $wDB;
1587 $l = $wDB->selectCol('-- CACHE: 1h
1588 SELECT `id` AS ARRAY_KEY, `icon` FROM `wowd_creature_family`');
1589 if (isset($l[$family]))
1590 return "images/icons/".strtolower($l[$family]).".jpg";
1591 return "images/icons/wowunknownitem01.jpg";
1593 function getStatTypeName($i)
1595 global $gStatType;
1596 return isset($gStatType[$i]) ? $gStatType[$i] : "Stat ($i)";
1599 function getResistance($i)
1601 global $gResistance;
1602 return isset($gResistance[$i]) ? $gResistance[$i] : "Resistance ($i)";
1605 function getResistanceText($i, $amount)
1607 global $gResistanceType;
1608 $text = @$gResistanceType[$i];
1609 if ($text == "") $text = "Err resist $i - %d";
1610 if ($i >=0 && $i < 7 && $amount > 0)
1611 return sprintf("+".$text, $amount);
1612 return sprintf($text, $amount);
1615 function getSkillRank($i)
1617 global $gSkillRank;
1618 return @$gSkillRank[$i];
1620 function getTalentName($id)
1622 global $wDB;
1623 $l = $wDB->selectCol('-- CACHE: 1h
1624 SELECT `id` AS ARRAY_KEY, `name` FROM `wowd_talent_tab`');
1625 return isset($l[$id]) ? $l[$id] : 'talent_'.$id;