Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 158 lines (130 sloc) 4.522 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
<?php
/* Hitchwiki - maps
* Public transportation functions
* - pt_types()
* - pt_type()
* - pt_list()
*/

 
/*
* List public transportation types
*/
function pt_types() {
return array(
0 => _("Other"),
1 => _("Local bus"),
2 => _("Trolleybus"),
3 => _("Tram"),
4 => _("Metro"),
5 => _("Commuter train"),
6 => _("Taxi"),
7 => _("Long distance bus"),
8 => _("Long distance train"),
9 => _("Airline"),
10 => _("Shipping"),
11 => _("Carsharing"),
12 => _("Car rental")
);
}

 
/*
* Print out type
* type: INT
* output: text | image | icon_text
*/
function pt_type($type, $output="text") {
global $settings;

$types = pt_types();

// Image
if($output == "image") return '<img src="'.$settings["base_url"].'/static/gfx/transportation_'.htmlspecialchars($type).'.png" class="pt_type png" alt="'.$types[$type].'" />';

// Plain text + image icon
if($output == "icon_text") return '<span class="icon transportation_'.$type.'">'.$types[$type].'</span>';

// Plain text
else return $types[$type];

}


/*
* Print out the list of publics in certain country
*/
function pt_list($country_iso) {

$user = current_user();

// Built up a query
$query = "SELECT * FROM `t_ptransport` WHERE `country` = '".mysql_real_escape_string($country_iso)."' ORDER BY `city`,`type` ASC";

// Gather data
start_sql();
$result = mysql_query($query);
if (!$result) {
die("Error: SQL query failed.");
}

// If some results, print out
if(mysql_num_rows($result) >= 1) {
?>
<table class="infotable" id="public_transport_catalog" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th><?php echo _("City"); ?></th>
<th><?php echo _("Site"); ?></th>
<th><?php echo _("Type"); ?></th>
<?php if($user["admin"]===true): ?>
<th><?php echo _("Manage"); ?></th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php

// Print out page rows
while ($row = mysql_fetch_array($result)) {

echo '<tr valign="top">';

// City
if(!empty($row["city"])) echo '<td>'.htmlspecialchars($row["city"]).'</td>';
else echo '<td> </td>';

// URL
if(!empty($row["title"])) echo '<td><a href="'.htmlspecialchars($row["URL"]).'" rel="nofollow" target="_blank">'.htmlspecialchars($row["title"]).'</a></td>';
else echo '<td><a href="'.htmlspecialchars($row["URL"]).'" rel="nofollow" target="_blank">'._("Go to site").'</a></td>';

// Type
echo '<td class="pt_types">';
if(strstr($row["type"], ";")) {
foreach(explode(";", $row["type"]) as $type) {
echo '<small>'.pt_type($type, 'icon_text').'</small><br />';
}
}
elseif($row["type"] != "") {
echo '<small>'.pt_type($row["type"], 'icon_text').'</small>';
}
echo ' </td>';

// Manage -col for admins
if($user["admin"]===true) {
?>
<td>
<a href="<?= $settings["base_url"]; ?>/admin/?page=public_transport&amp;remove=<?php echo $row["id"]; ?>" class="remove_page ui-icon ui-icon-trash align_right" title="<?php echo _("Remove page permanently"); ?>"></a>
<a href="<?= $settings["base_url"]; ?>/admin/?page=public_transport&amp;edit=<?php echo $row["id"]; ?>" class="ui-icon ui-icon-pencil align_right" title="<?php echo _("Edit page"); ?>"></a>
</td>
<?php
}

echo '</tr>';
}
?>
</tbody>
</table>
<?php if($user["admin"]===true): ?>
<script type="text/javascript">
$(function() {
// Confirm delete
$("#public_transport_catalog .remove_page").click(function(e){
e.preventDefault();
if(confirm('<?php echo _("Are you sure?"); ?>')) {
$(location).attr('href', $(this).attr("href"));
}
});
});
</script>
<?php endif; ?>
<br />
<small class="icon transportation_in-city"><?php echo _("In-city transportation"); ?></small><br />
<small class="icon transportation_inter-city"><?php echo _("Inter-city / international transportation"); ?></small><br />
<?php
}
else {
?>
<p><?php echo _("No public transport found for this country."); ?> <a href="<?= $settings["base_url"]; ?>/add_public_transport/" onclick="open_page('add_public_transport'); return false;"><?php echo _("Add some?"); ?></a></p>
<?php
}
}

?>
Something went wrong with that request. Please try again.