<body>
<?php
echo "<p>Buckyball Racing Club";
- foreach (array("competitor", "hull", "ship", "system", "race", "raikogram", "entry") as $what) {
+ foreach (array("competitor", "hull", "ship", "system", "station", "race", "raikogram", "entry") as $what) {
$title = preg_replace('/y$/', 'ie', $what);
echo " | <a href=\"?module=$what\">" . ucfirst($title) . "s</a>";
}
--- /dev/null
+<h2>Stations</h2>
+<?php
+
+ function add_station($system_id, $type, $name) {
+ if (! $name) {
+ echo "<p>Missing station name!</p>\n";
+ return false;
+ }
+ $orbital = 0 + (! ($type & Station::OrbitalFlag()));
+ $large_pad = 0 + (! ($type & Station::LargePadFlag()));
+
+ $station = new Station;
+ $station->setSystemId($system_id);
+ $station->setOrbital($orbital);
+ $station->setLargePad($large_pad);
+ $station->setName($name);
+ try {
+ $station->save();
+ return true;
+ }
+ catch (Exception $e) {
+ echo "<p>Error adding station: " . $e->getMessage() . "</p>\n";
+ }
+ return false;
+ }
+
+ function module_station($action) {
+ if ($_POST['add_station']) {
+ if (add_station($_POST["system_id"], $_POST["type"], $_POST["name"])) unset($_POST);
+ }
+
+ $q = new StationQuery;
+ $q->joinWith('Station.System');
+ $stations = $q->orderBy('System.Name')->orderByName()->find();
+ foreach ($stations as $station) {
+ $station_name = $station->getName();
+ $system_name = $station->getSystem()->getName();
+ $type = $station->getType();
+ echo "<p><strong>$station_name</strong> $type in <em>$system_name</em></p>\n";
+ }
+
+ echo "<hr>\n";
+ $sq = new SystemQuery;
+ $systems = $sq->orderByName()->find();
+ if (! count($systems)) {
+ echo "<p>Add systems before adding stations.</p>\n";
+ return;
+ }
+ form();
+ echo "<p>Add a new station: ";
+ echo "<a href=\"?module=system\">System:</a> <select name=\"system_id\">";
+ option("system_id", 0, "");
+ foreach ($systems as $system) {
+ $id = $system->getId();
+ $name = $system->getName();
+ option("system_id", $id, $name);
+ }
+ echo "</select>\n";
+ echo "type: <select name=\"type\">\n";
+ /* Flags are what the station DOESN'T have! */
+ option("type", 0, "Starport");
+ option("type", Station::LargePadFlag(), "Outpost");
+ option("type", Station::OrbitalFlag(), "Base");
+ option("type", Station::LargePadFlag() | Station::OrbitalFlag(), "Settlement");
+ echo "</select>\n";
+ input("name", $_POST["name"]);
+ echo "</select>\n";
+
+ submit("add_station", "Add");
+ echo "</p>\n";
+ end_form();
+ }
+?>
+
--- /dev/null
+<h2>Systems</h2>
+<?php
+
+ function add_system($system_name) {
+ if (! $system_name) {
+ echo "<p>Missing system name!</p>\n";
+ return false;
+ }
+ $system = new System;
+ $system->setName($system_name);
+ try {
+ $system->save();
+ return true;
+ }
+ catch (Exception $e) {
+ echo "<p>Error adding system: " . $e->getMessage() . "</p>\n";
+ }
+ return false;
+ }
+
+ function module_system($action) {
+ if ($_POST['add_system']) {
+ if (add_system($_POST["system_name"])) unset($_POST);
+ }
+
+ $q = new SystemQuery;
+ $systems = $q->orderByName()->find();
+ if (! count($systems)) echo "<p>No systems</p>\n";
+ foreach ($systems as $system) {
+ $system_name = $system->getName();
+ echo "<p><strong>$system_name</strong></p>\n";
+ }
+
+ echo "<hr>\n";
+ form();
+ echo "<p>Add a new system: ";
+ input("system_name", $_POST['system_name']);
+ submit("add_system", "Add");
+ echo "</p>\n";
+ end_form();
+ }
+
+?>
--- /dev/null
+<?php
+
+
+
+/**
+ * Skeleton subclass for representing a row from the 'station' table.
+ *
+ *
+ *
+ * You should add additional methods to this class to meet the
+ * application requirements. This class will only be generated as
+ * long as it does not already exist in the output directory.
+ *
+ * @package propel.generator.buckyball
+ */
+class Station extends BaseStation
+{
+ function LargePadFlag() { return 1; }
+ function OrbitalFlag() { return 2; }
+
+ function getType() {
+ if ($this->getOrbital()) {
+ if ($this->getLargePad()) return "Starport";
+ else return "Outpost";
+ }
+ else {
+ if ($this->getLargePad()) return "Base";
+ else return "Settlement";
+ }
+ }
+}
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="system_id" type="integer" required="true"/>
<column name="name" type="varchar" size="64" required="true"/>
+ <column name="orbital" type="boolean" default="true" required="true"/>
+ <column name="large_pad" type="boolean" default="true" required="true"/>
<unique name="system_station">
<unique-column name="system_id"/>
<unique-column name="name"/>