Требование: PHP => 5.3, часть 2
[cswow.git] / module / search / quest_zone_sort.php
blobf27381ad16b673c9b1f8b5aaf10ebe53494530d0
1 <?php
2 function cmpZones($a, $b)
4 if (count($a['areas'])==1)
5 return count($b['areas'])==1 ? strcmp($a['name'], $b['name']) : 1;
6 return count($b['areas'])!=1 ? strcmp($a['name'], $b['name']) : -1;
8 function zoneSortSelect()
10 global $lang, $config, $dDB, $wDB;
11 $cacheFilename = 'quest_zone_sort_'.$config['lang'].'.html';
12 if (checkUseCacheHtml($cacheFilename, 24*60*60))
14 $zone_sort = $dDB->selectCol("SELECT `ZoneOrSort` FROM `quest_template` GROUP BY `ZoneOrSort`");
15 $areas = $wDB->select("SELECT `id` AS ARRAY_KEY, `map_id`, `zone_id`, `name` FROM `wowd_zones` WHERE `id` IN (?a)", $zone_sort);
16 $q_zones= array();
17 $q_sort = array();
18 foreach($zone_sort as $z)
20 if ($z > 0)
22 $area = @$areas[$z];
23 $map = $area['map_id'];
24 if (!isset($q_zones[$map]))
26 $q_zones[$map]['name'] = getMapName($map);
27 $q_zones[$map]['areas']= array();
29 $q_zones[$map]['areas'][$z]=$area['name'];
31 else if ($z < 0)
32 $q_sort[-$z]=getQuestSort(-$z);
34 // Sort it
35 uasort($q_zones, 'cmpZones');
36 uasort($q_sort, 'strcmp');
38 echo '<select name="ZoneID" style="width: 49%">';
39 echo '<option value=0>'.$lang['anything'].'</option>'."\n";
40 foreach($q_zones as $map=>$z)
42 if (count($z['areas']) > 1)
44 uasort($z['areas'], 'strcmp');
45 echo '<optgroup label="'.$z['name'].'">';
46 foreach($z['areas'] as $id=>$name)
47 echo '<option value='.$id.'>'.$name.'</option>'."\n";
48 echo '</optgroup>';
50 else
52 foreach($z['areas'] as $id=>$name)
53 echo '<option value='.$id.'>'.$name.'</option>'."\n";
56 echo "</select>\n";
57 echo '<select name="SortID" style="width: 49%">';
58 echo '<option value=0>'.$lang['anything'].'</option>'."\n";
59 foreach($q_sort as $id=>$name)
60 echo '<option value='.$id.'>'.$name.'</option>'."\n";
61 echo "</select>";
62 flushHtmlCache($cacheFilename);