view www/loc.php @ 817:eaba088b5424

Show alternative location names on location page.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Sep 2009 17:25:56 +0000
parents 6341de08bd52
children 8b0c0dba7350
line wrap: on
line source

<?
require "config.inc.php";
require "common.inc.php";


function makeURL($afilter, $filter, $coders, $desc, $qname, $qclass)
{
  $s = "";
  if ($afilter) $s = "f=".$filter;

  if (!$coders) {
    if ($s !== "") $s .= "&amp;";
    $s .= "s";
  }

  if ($qname !== "") {
    if ($s !== "") $s .= "&amp;";
    $s .= "n=".$qname;
  }
  
  echo "   <td><a ";
  if ($qclass !== "")
    echo "class=\"".$qclass."\" ";
  echo "href=\"".$_SERVER["PHP_SELF"];
  if (strlen($s) > 0) echo "?".$s;
  echo "\">".$desc."</a></td>\n";
}


/* Initialization
 */
printPageHeader($pageTitle." - Locations",
  "<script type=\"text/javascript\" src=\"tooltip.js\"></script>");
//echo "<div><b>DEVELOPMENT VERSION</b></div>";


if (isset($_GET["c"])) {
  $filter = "C";
  $applyFilter = TRUE;
} else {
  if (isset($_GET["f"]) && $_GET["f"] != "") {
    $filter = $_GET["f"];
    if (!preg_match("/^[A-Za-z]+\$/", $filter)) {
      echo "<h1>Invalid filter rule '".htmlentities($filter)."'</h1>\n";
      $filter = "C";
      $applyFilter = FALSE;
    } else {
      $applyFilter = TRUE;
    }
  } else {
    $filter = "CF";
    $applyFilter = FALSE;
  }
}

$showCoders = !isset($_GET["s"]);

if (isset($_GET["a"])) {
  $coderName = basename($_GET["a"]);
  $coderName = strtoupper(substr($coderName, 0, 1)).strtolower(substr($coderName, 1));
  $wizTable = readWizInfoFiles();
}

if (isset($_GET["n"])) {
  $locTable = array();
  $setName = strtolower(basename($_GET["n"]));
  if (file_exists($setName.".loc")) {
    parseLocFile($setName, $locTable, $applyFilter, $filter);
  } else {
    echo "<h1>No such continent ID!</h1>\n";
    unset($setName);
  }
} else {
  $locTable = readLocationFiles($applyFilter, $filter);
}


/* Start of the page
 */
echo "<h1>";
if ($applyFilter) {
  if (array_key_exists($filter, $locationTypes)) {
    echo $locationTypes[$filter][2];
  } else {
    echo "?";
  }
} else
  echo "Locations";

echo " of ";

if (isset($continentList[$setName]))
  echo $continentList[$setName][0]." continent in ";
else
if (isset($specialList[$setName]))
  echo $specialList[$setName][0]." in ";
echo "BatMUD";
if (isset($coderName))
  echo " by ".$coderName;
echo "</h1>\n";

?>
<div class="selbar">
 <form action="<? echo $_SERVER["PHP_SELF"]; ?>" method="get">
<?
if (isset($setName))
  echo "<input type=\"hidden\" name=\"n\" value=\"".htmlentities($setName)."\" />\n";
?>
 <table>
  <tr>
   <td>
    <select name="f">
<?
foreach ($locationTypes as $id => $type) {
  echo "    <option value=\"".$id."\"";
  if ($applyFilter && $filter == $id)
    echo " selected=\"selected\"";
  echo ">".$type[3]."</option>\n";
}
?>
    </select>
   </td>
   <td>
    <input type="submit" value=" Update " class="isubmit" />
   </td>
   <td></td>
<?
makeURL($applyFilter, $filter, $showCoders, "All continents", "", "");
foreach ($continentList as $continent => $data) {
  makeURL($applyFilter, $filter, $showCoders, $data[0], $continent, $continent);
}
?>
   <td><a href="<? echo $pageIndex ?>">Back to main page</a></td>
  </tr>
 </table>
 </form>
</div>

<?
/* Coder/creator information box
 */
if (isset($coderName) && isset($wizTable[$coderName]) && count($wizTable[$coderName]) > 1) {
  echo "<div class=\"wizinfo\">\n <table>\n  <tr>\n";
  
  $s = $wizTable[$coderName]["imageURL"];
  if (isset($s)) {
    if (substr($s, 0, 6) == "bat://")
    $s = "img/unknown.png";
//      $s = "http://www.bat.org/albums/".substr($s, 6);
  } else
    $s = "img/unknown.png";
  
  echo "   <td class=\"img\"><img src=\"".$s."\" alt=\"".$coderName."\" /></td>\n";


  echo "   <td class=\"info\">\n";
  echo "    <h2>".$coderName."</h2>\n";

  $s = $wizTable[$coderName]["desc"];
  if (isset($s) > 0) {
    echo "    <p>".$s."</p>\n";
  }

  echo "    [<a href=\"".fingerURL($coderName)."\">Finger</a>]\n";

  $s = $wizTable[$coderName]["homeURL"];
  if (isset($s)) {
    if ($s == "bat")
      $s = "http://wiz.bat.org/~".strtolower($coderName)."/";
      
    echo "    [<a href=\"".$s."\">Homepage</a>]<br />\n";
  }
  
  echo "   </td>\n  </tr>\n </table>\n</div>\n";
}


/* Print list of locations
 */
if (count($locTable) > 0) {
  /* Make alphabetically sorted table of locations
   */
  $alphaTable = array();
  foreach ($locTable as $id => $data)
  if (isset($data["name"])) {
    $idx = $data["name"][0];
    if (isset($_GET["nocoders"])) {
      if (count($data["coders"]) == 0 && !preg_match("/[SPG]/", $data["flags"]))
        $alphaTable[$idx][] = $data;
    } else {
      if (isset($coderName)) {
        if (array_search($coderName, $data["coders"]) !== FALSE)
          $alphaTable[$idx][] = $data;
      } else
        $alphaTable[$idx][] = $data;
    }
  }

  ksort($alphaTable, SORT_STRING);

  /* Print locations per first character
   */
  $locationTips = array();
  $totalLoc = 0;
  $maxRow = 6;
  foreach ($alphaTable as $key => $value) {
    if (count($value) <= 0) continue;

    asort($value);
      
    echo "<h3><a name=\"".strtolower($key)."\"></a>".$key."</h3>\n".
    "<table class=\"loc\" width=\"95%\">\n";
 
    $n = 0;
    foreach ($value as $ik => $iv) {
      if ($n == 0)
        echo " <tr>\n";
        
        $totalLoc++;

        // Print location entry
        printf("  <td width=\"%d%%\" class=\"%s\">",
          (100 / $maxRow), $iv["continent"]);
        
        if (isset($specialList[$iv["continent"]]) && !$specialList[$iv["continent"]][1]) {
          echo "<b>".htmlentities($iv["name"])."</b>";
        } else {
          printURL($iv["continent"].".html#loc".$iv["x"]."_".$iv["y"]);
          echo htmlentities($iv["name"])."</a>";
        }
        
        if (isset($iv["url"]) || isset($iv["freeform"])) {
          if (isset($iv["freeform"]))
            $desc = htmlentities($iv["freeform"]);
          else
            $desc = "";
          
          if (isset($iv["url"])) {
            $urlEnt = $iv["url"];
            $urlBegin = "<a href=\"".htmlentities($urlEnt)."\" target=\"_blank\">";
            $urlEnd = "</a>";
            if (strlen($iv["url"]) > 40)
              $urlEnt = substr($urlEnt, 0, 40)."...";
            $desc .= "<br /><br /><b>".htmlentities($urlEnt)."</b>";
          } else {
            $urlBegin = $urlEnd = "";
          }
          
          echo " ".$urlBegin."<img class=\"noborder\" src=\"question.png\" onmouseover=\"stt(".$totalLoc.
            ");\" onmouseout=\"htt();\" alt=\"(?)\" />".$urlEnd."\n";
          
          $locationTips[$totalLoc] = array(
            "title" => $iv["name"],
            "desc" => $desc
          );
        }        
        
        // Alternative names
        if (count($iv["names"]) > 1) {
          unset($iv["names"][0]);
          echo "<br />".implode(" | ", $iv["names"]);
        }
        
        // Coder / society names
        if (count($iv["coders"]) > 0 && $showCoders) {
          $isSG = preg_match("/[SG]/", $iv["flags"]);
          if ((!isset($coderName) && !$isSG) || isset($coderName)) {
          $fs = "";
          while (list($fKey, $fVal) = each($iv["coders"])) {
            if ($fs != "") $fs .= ", ";
            if ($filter != "C" || !$applyFilter)
              $fs .= "<a href=\"".$_SERVER["PHP_SELF"]."?a=".$fVal."\">".$fVal."</a>";
            else
              $fs .= $fVal;
          }
          echo "<br />[".$fs."]";
          }
        }
        
        echo "</td>\n";

        $n++;
        if ($n >= $maxRow) {
          echo " </tr>\n";
          $n = 0;
        }      
      }
      if ($n > 0) {
        while ($n++ < $maxRow)
          echo "  <td></td>\n";
      
        echo " </tr>\n";
      }
      echo "</table>\n";
  }
  
  echo "<p><b>".$totalLoc."</b> locations.</p>\n";

  /* Print out location tooltip HTML code
   */
  foreach ($locationTips as $tipID => $tip) {
    echo "<div class=\"tooltip\" id=\"tt".$tipID.
    "\"><div class=\"holder\"><b>".htmlentities($tip["title"]).
    "</b><br />".$tip["desc"]."</div></div>\n";
  }
} else {
  echo "<p><b>No locations known!</b></p>\n";
}

// Google Analytics
require "urchin.inc.php";
?>
</body>
</html>