Advertisement
dimipan80

Gosho Is Moving

May 2nd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. $luggage = preg_split('/\s*C\|_\|\s*/', $_GET['luggage'], -1, PREG_SPLIT_NO_EMPTY);
  3. $typeLuggage = array();
  4. if (isset($_GET['typeLuggage'])) {
  5.     foreach ($_GET['typeLuggage'] as $type) {
  6.         $typeLuggage[] = $type;
  7.     }
  8. }
  9.  
  10. $room = $_GET['room'];
  11. $minWeight = $_GET['minWeight'];
  12. $maxWeight = $_GET['maxWeight'];
  13.  
  14. if (empty($typeLuggage) || $room == '' || $minWeight == '' || $maxWeight == '') {
  15.     die('<ul></ul>');
  16. }
  17.  
  18. $minWeight = (int)$minWeight;
  19. $maxWeight = (int)$maxWeight;
  20. $filteredLuggage = array();
  21. $typeWeightArr = array();
  22. foreach ($luggage as $piece) {
  23.     $pieceInfo = preg_split('/\s*\;\s*/', $piece, -1, PREG_SPLIT_NO_EMPTY);
  24.     $type = $pieceInfo[0];
  25.  
  26.     if (!in_array($type, $typeLuggage) || $pieceInfo[1] != $room) {
  27.         continue;
  28.     }
  29.  
  30.     if (!array_key_exists($type, $filteredLuggage)) {
  31.         $filteredLuggage[$type] = array();
  32.         $typeWeightArr[$type] = 0;
  33.     }
  34.  
  35.     $luggageName = $pieceInfo[2];
  36.     $typeWeightArr[$type] += (int)$pieceInfo[3];
  37.     array_push($filteredLuggage[$type], $luggageName);
  38. }
  39.  
  40. foreach ($typeWeightArr as $type => $weight) {
  41.     if ($weight < $minWeight || $weight > $maxWeight) {
  42.         unset($typeWeightArr[$type]);
  43.         unset($filteredLuggage[$type]);
  44.     }
  45. }
  46.  
  47. ksort($filteredLuggage);
  48. $result = '<ul>';
  49. foreach ($filteredLuggage as $type => $list) {
  50.     sort($list);
  51.     $result .= '<li><p>' . $type . '</p><ul><li><p>' . $room . '</p><ul><li><p>';
  52.     $result .= implode(', ', $list) . ' - ' . $typeWeightArr[$type] . 'kg</p></li></ul></li></ul></li>';
  53. }
  54.  
  55. echo $result . '</ul>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement