| 1 |
<?
|
| 2 |
// $Id: track.module,v 1.11 2009/03/07 19:48:29 gadzuk Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* GPX-handling and displaying.
|
| 7 |
*/
|
| 8 |
|
| 9 |
define('TRACK_PATH', drupal_get_path('module', 'track'));
|
| 10 |
|
| 11 |
include_once(TRACK_PATH ."/track.gpx.inc");
|
| 12 |
include_once(TRACK_PATH ."/track.tile.inc");
|
| 13 |
include_once(TRACK_PATH ."/track.google.map.inc");
|
| 14 |
|
| 15 |
|
| 16 |
$phptrackback = "";
|
| 17 |
|
| 18 |
function get_gpx_filepath($nid) {
|
| 19 |
$extras = new StdClass();
|
| 20 |
$extras->file = db_fetch_object(db_query('SELECT * FROM {track} WHERE nid = %d', $nid));
|
| 21 |
return $extras->file->filepath;
|
| 22 |
}
|
| 23 |
|
| 24 |
function track_add() {
|
| 25 |
return node_add("track");
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_menu().
|
| 30 |
*/
|
| 31 |
function track_menu() {
|
| 32 |
$items = array();
|
| 33 |
|
| 34 |
// Menu items appearing under Navigation
|
| 35 |
$items['track'] = array(
|
| 36 |
'title' => 'Track list',
|
| 37 |
'page callback' => 'list_trk',
|
| 38 |
'access callback' => 'user_access',
|
| 39 |
'access arguments' => array('access content'),
|
| 40 |
'type' => MENU_NORMAL_ITEM);
|
| 41 |
$items['track/add'] = array(
|
| 42 |
'title' => 'Track upload',
|
| 43 |
'page callback' => 'track_add',
|
| 44 |
'access callback' => 'user_access',
|
| 45 |
'access arguments' => array('Create tracks'),
|
| 46 |
'type' => MENU_NORMAL_ITEM);
|
| 47 |
|
| 48 |
// Callbacks for various track functions
|
| 49 |
$items['track/trk'] = array(
|
| 50 |
'page callback' => 'download_trk',
|
| 51 |
'access callback' => 'user_access',
|
| 52 |
'access arguments' => array('access content'),
|
| 53 |
'type' => MENU_CALLBACK);
|
| 54 |
$items['track/kml'] = array(
|
| 55 |
'page callback' => 'download_kml',
|
| 56 |
'access callback' => 'user_access',
|
| 57 |
'access arguments' => array('access content'),
|
| 58 |
'type' => MENU_CALLBACK);
|
| 59 |
$items['track/gpx'] = array(
|
| 60 |
'page callback' => 'download_gpx',
|
| 61 |
'access callback' => 'user_access',
|
| 62 |
'access arguments' => array('access content'),
|
| 63 |
'type' => MENU_CALLBACK);
|
| 64 |
$items['track/icon'] = array(
|
| 65 |
'page callback' => 'get_icon',
|
| 66 |
'access callback' => 'user_access',
|
| 67 |
'access arguments' => array('access content'),
|
| 68 |
'type' => MENU_CALLBACK);
|
| 69 |
$items['track/ajax/all'] = array(
|
| 70 |
'page callback' => 'trackback_all',
|
| 71 |
'access callback' => 'user_access',
|
| 72 |
'access arguments' => array('access content'),
|
| 73 |
'type' => MENU_CALLBACK);
|
| 74 |
$items['track/ajax/detail'] = array(
|
| 75 |
'page callback' => 'trackback_detail',
|
| 76 |
'access callback' => 'user_access',
|
| 77 |
'access arguments' => array('access content'),
|
| 78 |
'type' => MENU_CALLBACK);
|
| 79 |
$items['track/profile'] = array(
|
| 80 |
'page callback' => 'trackback_profile',
|
| 81 |
'access callback' => 'user_access',
|
| 82 |
'access arguments' => array('access content'),
|
| 83 |
'type' => MENU_CALLBACK);
|
| 84 |
$items['track/repartition'] = array(
|
| 85 |
'page callback' => 'trackback_repartition',
|
| 86 |
'access callback' => 'user_access',
|
| 87 |
'access arguments' => array('access content'),
|
| 88 |
'type' => MENU_CALLBACK);
|
| 89 |
$items['track/boundslist'] = array(
|
| 90 |
'page callback' => 'track_boundslist',
|
| 91 |
'access callback' => 'user_access',
|
| 92 |
'access arguments' => array('access content'),
|
| 93 |
'type' => MENU_CALLBACK);
|
| 94 |
|
| 95 |
return $items;
|
| 96 |
}
|
| 97 |
|
| 98 |
function track_boundslist() {
|
| 99 |
$result = db_query('SELECT latmin, lonmin, latmax, lonmax FROM {track}');
|
| 100 |
if ($result) {
|
| 101 |
while ($bounds = db_fetch_object($result)) {
|
| 102 |
echo $bounds->lonmin .";".$bounds->latmin .";".$bounds->lonmax .";".$bounds->latmax."<br>\n";
|
| 103 |
}
|
| 104 |
}
|
| 105 |
}
|
| 106 |
|
| 107 |
function trackback_profile($nid) {
|
| 108 |
$aGPXfile = new GPX_file();
|
| 109 |
$aGPXfile->LoadFromFile(get_gpx_filepath($nid));
|
| 110 |
$aGPXfile->XMLforProfile();
|
| 111 |
}
|
| 112 |
|
| 113 |
function trackback_repartition($nid) {
|
| 114 |
$aGPXfile = new GPX_file();
|
| 115 |
$aGPXfile->LoadFromFile(get_gpx_filepath($nid));
|
| 116 |
$aGPXfile->XMLforRepartition();
|
| 117 |
}
|
| 118 |
|
| 119 |
function get_icon($diff) {
|
| 120 |
header("Content-type: image/png");
|
| 121 |
|
| 122 |
if ($diff == "S") {
|
| 123 |
$image_name = TRACK_PATH ."/misc/pushpins/058.png";
|
| 124 |
} elseif ($diff == "M") {
|
| 125 |
$image_name = TRACK_PATH ."/misc/pushpins/150.png";
|
| 126 |
} elseif ($diff == "L") {
|
| 127 |
$image_name = TRACK_PATH ."/misc/pushpins/011.png";
|
| 128 |
} else {
|
| 129 |
$image_name = TRACK_PATH ."/misc/pushpins/007.png";
|
| 130 |
}
|
| 131 |
|
| 132 |
$im = imagecreatefrompng($image_name);
|
| 133 |
imageAlphaBlending($im, true);
|
| 134 |
imageSaveAlpha($im, true);
|
| 135 |
|
| 136 |
if ($diff == "XL") {
|
| 137 |
$black = imagecolorallocate($im, 0, 0, 0);
|
| 138 |
} else {
|
| 139 |
$black = imagecolorallocate($im, 0, 0, 0);
|
| 140 |
}
|
| 141 |
|
| 142 |
$string = $diff;
|
| 143 |
$len = strlen($string);
|
| 144 |
|
| 145 |
if($len <= 2) {
|
| 146 |
$px = (imagesx($im) - 7 * strlen($string)) / 2 + 1;
|
| 147 |
imagestring($im, 3, $px, 3, $string, $black);
|
| 148 |
} else {
|
| 149 |
$px = (imagesx($im) - 7 * strlen($string)) / 2 + 2;
|
| 150 |
imagestring($im, 2, $px, 3, $string, $black);
|
| 151 |
}
|
| 152 |
|
| 153 |
imagepng($im);
|
| 154 |
imagedestroy($im);
|
| 155 |
}
|
| 156 |
|
| 157 |
function trackback_detail($nid) {
|
| 158 |
// create interface object with map
|
| 159 |
$aMap = new GoogleMap();
|
| 160 |
// init all values
|
| 161 |
$aMap->Init();
|
| 162 |
|
| 163 |
// map is displaying sync, zoom
|
| 164 |
if ($aMap->mapaction == "initsync") {
|
| 165 |
$result = db_query('SELECT min(latmin) as latminr, min(lonmin) as lonminr,max(latmax) as latmaxr, max(lonmax) as lonmaxr, avg(latstart) as latavg, avg(lonstart) as lonavg FROM {track} WHERE nid='.$nid);
|
| 166 |
if ($result) {
|
| 167 |
while ($bounds = db_fetch_object($result)) {
|
| 168 |
$latmin = $bounds->latminr;
|
| 169 |
$lonmin = $bounds->lonminr;
|
| 170 |
$latmax = $bounds->latmaxr;
|
| 171 |
$lonmax = $bounds->lonmaxr;
|
| 172 |
$latavg = $bounds->latavg;
|
| 173 |
$lonavg = $bounds->lonavg;
|
| 174 |
}
|
| 175 |
}
|
| 176 |
|
| 177 |
$varlon = max(1e-5, $lonmax - $lonmin);
|
| 178 |
$angle = 360 * 0.7;
|
| 179 |
$zoomlevellon = 17;
|
| 180 |
while ($angle>$varlon)
|
| 181 |
{
|
| 182 |
$angle = $angle / 2;
|
| 183 |
$zoomlevellon--;
|
| 184 |
}
|
| 185 |
|
| 186 |
$varlat = max(1e-5, $latmax - $latmin);
|
| 187 |
$angle = 360 * 0.7;
|
| 188 |
$zoomlevellat = 17;
|
| 189 |
while ($angle>$varlat)
|
| 190 |
{
|
| 191 |
$angle = $angle / 2;
|
| 192 |
$zoomlevellat--;
|
| 193 |
}
|
| 194 |
|
| 195 |
$zoomlevel = max(0, max($zoomlevellat, $zoomlevellon));
|
| 196 |
|
| 197 |
// center and zoom the map
|
| 198 |
$lonavg = ($lonmin + $lonmax) / 2.0;
|
| 199 |
$latavg = ($latmin + $latmax) / 2.0;
|
| 200 |
$aMap->MoveAndZoom($lonavg, $latavg, $zoomlevel);
|
| 201 |
}
|
| 202 |
// map is displaying async, display
|
| 203 |
if ($aMap->mapaction == "initasync") {
|
| 204 |
$aGPXfile = new GPX_file();
|
| 205 |
$aGPXfile->LoadFromFile(get_gpx_filepath($nid));
|
| 206 |
$aMap->AddClearLastTrace();
|
| 207 |
$points = $aGPXfile->PointsForGoogleMaps(2000);
|
| 208 |
|
| 209 |
$track = node_load($nid);
|
| 210 |
$desc = theme('info_window_html', $track);
|
| 211 |
$aMap->AddTrace($points, "#ff0000", 3, 0.8);
|
| 212 |
|
| 213 |
$intensite = $track->file->dzplus / ($track->file->length / 4);
|
| 214 |
$intensite = ($intensite - 30) * (100 / 40);
|
| 215 |
|
| 216 |
if ($intensite < 30) {
|
| 217 |
$mapicon = base_path()."track/icon/S";
|
| 218 |
}
|
| 219 |
elseif ($intensite < 60) {
|
| 220 |
$mapicon = base_path()."track/icon/M";
|
| 221 |
}
|
| 222 |
elseif ($intensite < 100) {
|
| 223 |
$mapicon = base_path()."track/icon/L";
|
| 224 |
}
|
| 225 |
else {
|
| 226 |
$mapicon = base_path()."track/icon/XL";
|
| 227 |
}
|
| 228 |
|
| 229 |
$aMap->AddPoint($points[0][0], $points[0][1], $track->nid, $desc, $mapicon);
|
| 230 |
$aMap->DisplayInfo("info", "");
|
| 231 |
}
|
| 232 |
// send scenario to map
|
| 233 |
$aMap->ShowXMLforAJAX();
|
| 234 |
}
|
| 235 |
|
| 236 |
function trackback_all() {
|
| 237 |
// create interface object with map
|
| 238 |
$aMap = new GoogleMap();
|
| 239 |
// init all values
|
| 240 |
$aMap->Init();
|
| 241 |
|
| 242 |
if ($aMap->mapaction == "initsync") {
|
| 243 |
$result = db_query('SELECT min(latmin) as latminr, min(lonmin) as lonminr,max(latmax) as latmaxr, max(lonmax) as lonmaxr FROM {track}');
|
| 244 |
$nresult = 0;
|
| 245 |
if ($result) {
|
| 246 |
while ($bounds = db_fetch_object($result)) {
|
| 247 |
$latmin = $bounds->latminr;
|
| 248 |
$lonmin = $bounds->lonminr;
|
| 249 |
$latmax = $bounds->latmaxr;
|
| 250 |
$lonmax = $bounds->lonmaxr;
|
| 251 |
$lonavg = ($lonmin + $lonmax) / 2.0;
|
| 252 |
$latavg = ($latmin + $latmax) / 2.0;
|
| 253 |
$nresult++;
|
| 254 |
}
|
| 255 |
}
|
| 256 |
|
| 257 |
if ($nresult > 0) {
|
| 258 |
$varlon = max(1e-5, $lonmax - $lonmin);
|
| 259 |
$angle = 360;
|
| 260 |
$zoomlevellon = 17;
|
| 261 |
while ($angle>$varlon)
|
| 262 |
{
|
| 263 |
$angle = $angle / 2;
|
| 264 |
$zoomlevellon--;
|
| 265 |
}
|
| 266 |
|
| 267 |
$varlat = max(1e-5, $latmax - $latmin);
|
| 268 |
$angle = 360;
|
| 269 |
$zoomlevellat = 17;
|
| 270 |
while ($angle>$varlat)
|
| 271 |
{
|
| 272 |
$angle = $angle / 2;
|
| 273 |
$zoomlevellat--;
|
| 274 |
}
|
| 275 |
|
| 276 |
$zoomlevel = max(0, max($zoomlevellat, $zoomlevellon));
|
| 277 |
|
| 278 |
// center and zoom the map
|
| 279 |
$aMap->MoveAndZoom($lonavg, $latavg, $zoomlevel);
|
| 280 |
} else {
|
| 281 |
$aMap->MoveAndZoom("0", "0", 17);
|
| 282 |
}
|
| 283 |
|
| 284 |
}
|
| 285 |
if ($aMap->mapaction == "initasync") {
|
| 286 |
$result = db_query('SELECT n.nid, r.title, r.teaser, u.name, u.uid, t.latstart, t.lonstart, t.dzplus, t.length FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid INNER JOIN {track} t ON t.nid = n.nid');
|
| 287 |
|
| 288 |
if ($result) {
|
| 289 |
while ($track = db_fetch_object($result)) {
|
| 290 |
$desc = theme('info_window_html', $track);
|
| 291 |
|
| 292 |
$intensite = $track->dzplus / ($track->length / 4);
|
| 293 |
$intensite = ($intensite - 30) * (100 / 40);
|
| 294 |
|
| 295 |
if ($intensite < 30) {
|
| 296 |
$mapicon = base_path()."track/icon/S";
|
| 297 |
}
|
| 298 |
elseif ($intensite < 60) {
|
| 299 |
$mapicon = base_path()."track/icon/M";
|
| 300 |
}
|
| 301 |
elseif ($intensite < 100) {
|
| 302 |
$mapicon = base_path()."track/icon/L";
|
| 303 |
}
|
| 304 |
else {
|
| 305 |
$mapicon = base_path()."track/icon/XL";
|
| 306 |
}
|
| 307 |
$aMap->AddPoint($track->lonstart, $track->latstart, $track->nid, $desc, $mapicon);
|
| 308 |
}
|
| 309 |
}
|
| 310 |
$aMap->DisplayInfo("info", "");
|
| 311 |
} // end init
|
| 312 |
|
| 313 |
if ($aMap->mapaction == "clicked") {
|
| 314 |
$aGPXfile = new GPX_file();
|
| 315 |
$aGPXfile->LoadFromFile(get_gpx_filepath($aMap->idclicked));
|
| 316 |
$aMap->AddClearLastTrace();
|
| 317 |
$aMap->AddTrace($aGPXfile->PointsForGoogleMaps(2000), "#0000ff", 2, 0.8);
|
| 318 |
|
| 319 |
// $track = node_load($aMap->idclicked);
|
| 320 |
$desc = theme('info_details', $track);
|
| 321 |
$aMap->DisplayInfo("info", $desc);
|
| 322 |
}
|
| 323 |
|
| 324 |
// send scenario to map
|
| 325 |
$aMap->ShowXMLforAJAX();
|
| 326 |
}
|
| 327 |
|
| 328 |
function theme_info_window_html($track) {
|
| 329 |
prepare_google_maps();
|
| 330 |
$output = "";
|
| 331 |
$output .= "<b>".$track->title."</b>";
|
| 332 |
$output .= " ".t("by")." ";
|
| 333 |
$output .= l($track->name, 'user/'.$track->uid);
|
| 334 |
$output .= check_markup($track->teaser, $track->format, FALSE);
|
| 335 |
$output .= "<b>".l(t('More details'), 'node/'.$track->nid)."</b>";
|
| 336 |
return $output;
|
| 337 |
}
|
| 338 |
|
| 339 |
function theme_info_details($track) {
|
| 340 |
prepare_google_maps();
|
| 341 |
$output = theme('track_files', $track, true);
|
| 342 |
return $output;
|
| 343 |
}
|
| 344 |
|
| 345 |
function prepare_google_maps() {
|
| 346 |
_gmap_doheader();
|
| 347 |
drupal_add_js(TRACK_PATH .'/misc/map.inc.js');
|
| 348 |
}
|
| 349 |
|
| 350 |
function track_footer($main = 0) {
|
| 351 |
global $phptrackback;
|
| 352 |
|
| 353 |
if ($phptrackback != "") {
|
| 354 |
prepare_google_maps();
|
| 355 |
$content = '';
|
| 356 |
$content .= "<script type=\"text/javascript\">";
|
| 357 |
$content .= "\n";
|
| 358 |
$content .= "//<![CDATA[\n";
|
| 359 |
$content .= " var myMapClass = null;\n";
|
| 360 |
$content .= "$(document).ready(function() {\n";
|
| 361 |
$content .= " myMapClass = new MapClass();\n";
|
| 362 |
$content .= " myMapClass.initmap('".base_path().$phptrackback."', 'map');\n";
|
| 363 |
$content .= " });\n";
|
| 364 |
$content .= "//]]>";
|
| 365 |
$content .= "\n";
|
| 366 |
$content .= "</script >\n";
|
| 367 |
}
|
| 368 |
|
| 369 |
return $content;
|
| 370 |
}
|
| 371 |
|
| 372 |
function track_page_last() {
|
| 373 |
$output = '';
|
| 374 |
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'track' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
|
| 375 |
|
| 376 |
$header = array();
|
| 377 |
$header[] = t("Name");
|
| 378 |
$header[] = t("Teaser");
|
| 379 |
$header[] = t("Length");
|
| 380 |
$header[] = t("Z+");
|
| 381 |
$header[] = t("Z-");
|
| 382 |
$header[] = "<b>".t("Intensity")."</b>";
|
| 383 |
|
| 384 |
$rows = array();
|
| 385 |
|
| 386 |
while ($node = db_fetch_object($result)) {
|
| 387 |
$row = array();
|
| 388 |
$track = node_load($node->nid);
|
| 389 |
$row[] = l($track->title, 'node/'.$track->nid);
|
| 390 |
$row[] = check_markup($track->teaser, $track->format, FALSE);
|
| 391 |
$row[] = sprintf('%2.2f', $track->file->length)." km";
|
| 392 |
$row[] = sprintf('%2.2f', $track->file->dzplus)." m";
|
| 393 |
$row[] = sprintf('%2.2f', $track->file->dzminu)." m";
|
| 394 |
|
| 395 |
if ($track->file->length != 0) {
|
| 396 |
$intensite = $track->file->dzplus / ($track->file->length / 4);
|
| 397 |
$intensite = ($intensite - 30) * (100 / 40);
|
| 398 |
} else {
|
| 399 |
$intensite = 0.0;
|
| 400 |
}
|
| 401 |
|
| 402 |
if ($intensite < 30) {
|
| 403 |
$sint = "S";
|
| 404 |
}
|
| 405 |
elseif ($intensite < 60) {
|
| 406 |
$sint = "M";
|
| 407 |
}
|
| 408 |
elseif ($intensite < 100) {
|
| 409 |
$sint = "L";
|
| 410 |
}
|
| 411 |
else {
|
| 412 |
$sint = "XL";
|
| 413 |
}
|
| 414 |
|
| 415 |
$row[] = "<b>".$sint."</b>";
|
| 416 |
$rows[] = $row;
|
| 417 |
}
|
| 418 |
$output .= theme_table($header, $rows);
|
| 419 |
|
| 420 |
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
|
| 421 |
return $output;
|
| 422 |
}
|
| 423 |
|
| 424 |
function list_trk() {
|
| 425 |
global $phptrackback;
|
| 426 |
$phptrackback = 'track/ajax/all';
|
| 427 |
|
| 428 |
prepare_google_maps();
|
| 429 |
|
| 430 |
$content = '';
|
| 431 |
|
| 432 |
/* $output .= theme_item_list(
|
| 433 |
array(),
|
| 434 |
t('Map'),
|
| 435 |
'ul'
|
| 436 |
);
|
| 437 |
*/
|
| 438 |
|
| 439 |
$content .= ' <table width="95%"><tr><td>';
|
| 440 |
$content .= ' <div id="map" style="height: 600px; left:0px; right:0px;"></div>';
|
| 441 |
$content .= ' </td></tr><tr><td>';
|
| 442 |
$content .= ' <div id="info" style="height: 100px">'.t("Loading").'...'.'</div>';
|
| 443 |
$content .= ' </td></tr></table>';
|
| 444 |
|
| 445 |
$content .= track_page_last();
|
| 446 |
|
| 447 |
return $content;
|
| 448 |
}
|
| 449 |
|
| 450 |
function download_trk($nid = 0) {
|
| 451 |
$aGPXfile = new GPX_file();
|
| 452 |
$aGPXfile->LoadFromFile(get_gpx_filepath($nid));
|
| 453 |
$aGPXfile->ConvertToTRK();
|
| 454 |
}
|
| 455 |
|
| 456 |
function download_kml($nid = 0) {
|
| 457 |
$aGPXfile = new GPX_file();
|
| 458 |
$aGPXfile->LoadFromFile(get_gpx_filepath($nid));
|
| 459 |
$aGPXfile->ConvertToKML();
|
| 460 |
}
|
| 461 |
|
| 462 |
function download_gpx($nid = 0) {
|
| 463 |
$file = get_gpx_filepath($nid);
|
| 464 |
file_transfer($file, array('Content-Disposition: attachment; filename="'.basename($file).'"') );
|
| 465 |
}
|
| 466 |
|
| 467 |
/**
|
| 468 |
* Implementation of hook_perm.
|
| 469 |
*/
|
| 470 |
function track_perm() {
|
| 471 |
return array('create tracks');
|
| 472 |
}
|
| 473 |
|
| 474 |
/**
|
| 475 |
* Implementation of hook_help().
|
| 476 |
*/
|
| 477 |
function track_help($path, $arg) {
|
| 478 |
switch ($path) {
|
| 479 |
case 'node/add#track':
|
| 480 |
return t('Upload new track.');
|
| 481 |
}
|
| 482 |
}
|
| 483 |
|
| 484 |
/**
|
| 485 |
* Implementation of hook_node_info.
|
| 486 |
*/
|
| 487 |
function track_node_info() {
|
| 488 |
return array(
|
| 489 |
'track' => array(
|
| 490 |
'name' => t('Track'),
|
| 491 |
'module' => 'track',
|
| 492 |
'description' => t("A track is a GPS/GPX track file"),
|
| 493 |
)
|
| 494 |
);
|
| 495 |
}
|
| 496 |
|
| 497 |
/**
|
| 498 |
* Implementation of hook_access.
|
| 499 |
*/
|
| 500 |
function track_access($op, $node) {
|
| 501 |
global $user;
|
| 502 |
switch ($op) {
|
| 503 |
case 'create':
|
| 504 |
return user_access("create tracks");
|
| 505 |
case 'update':
|
| 506 |
case 'delete':
|
| 507 |
return user_access("create tracks") && ($user->uid == $node->uid);
|
| 508 |
}
|
| 509 |
}
|
| 510 |
|
| 511 |
function track_flash_chart($width, $height, $nid, $type) {
|
| 512 |
global $base_path;
|
| 513 |
|
| 514 |
$swf = "FC2Line.swf";
|
| 515 |
if ($type == "repartition")
|
| 516 |
$swf = "FC2Column.swf";
|
| 517 |
$output = '';
|
| 518 |
$output .= '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
|
| 519 |
$output .= 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
|
| 520 |
$output .= 'WIDTH="'.$width.'" HEIGHT="'.$height.'" id="FC2Area3D" ALIGN="">';
|
| 521 |
$output .= '<PARAM NAME=movie VALUE="'.$base_path.TRACK_PATH.'/misc/'.$swf.'?dataUrl='. $base_path . 'track/'.$type.'/'.$nid.'">';
|
| 522 |
$output .= '<PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF>';
|
| 523 |
$output .= '<EMBED src="'.$base_path.TRACK_PATH.'/misc/'.$swf.'?dataUrl='.$base_path.'track/'.$type.'/'.$nid.'" quality=high ';
|
| 524 |
$output .= 'bgcolor=#FFFFFF WIDTH="'.$width.'" HEIGHT="'.$height.'" NAME="FC2Area3D" ';
|
| 525 |
$output .= 'ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>';
|
| 526 |
$output .= '</OBJECT>';
|
| 527 |
return $output;
|
| 528 |
}
|
| 529 |
|
| 530 |
/**
|
| 531 |
* Implementation of hook_view.
|
| 532 |
*/
|
| 533 |
function track_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 534 |
global $phptrackback;
|
| 535 |
if ($phptrackback == "")
|
| 536 |
$phptrackback = 'track/ajax/detail/'.$node->nid."/";
|
| 537 |
|
| 538 |
$node = node_prepare($node, $teaser);
|
| 539 |
$node->content['track'] = array(
|
| 540 |
'#value' => theme('track_files', $node),
|
| 541 |
'#weight' => 1,
|
| 542 |
);
|
| 543 |
return $node;
|
| 544 |
}
|
| 545 |
|
| 546 |
/**
|
| 547 |
* Implementation of hook_theme().
|
| 548 |
*/
|
| 549 |
function track_theme() {
|
| 550 |
return array(
|
| 551 |
'track' => array('arguments' => array('element')),
|
| 552 |
'track_files' => array('arguments' => array('element')),
|
| 553 |
'item_list' => array('arguments' => array('element')),
|
| 554 |
'info_window_html' => array('arguments' => array('element')),
|
| 555 |
'info_details' => array('arguments' => array('element')),
|
| 556 |
);
|
| 557 |
}
|
| 558 |
|
| 559 |
function theme_track_files($node) {
|
| 560 |
prepare_google_maps();
|
| 561 |
|
| 562 |
//theme_node_example_order_info
|
| 563 |
$output = "";
|
| 564 |
|
| 565 |
if ($file = $node->file) {
|
| 566 |
$output .= "<p>";
|
| 567 |
|
| 568 |
$output .= theme_item_list(
|
| 569 |
array(
|
| 570 |
t('Length').' : '.sprintf('%2.2f', $node->file->length).'km',
|
| 571 |
t('Positive Z').' : '.sprintf('%2.2f', $node->file->dzplus).'m',
|
| 572 |
t('Negative Z').' : '.sprintf('%2.2f', $node->file->dzminu).'m',
|
| 573 |
t('Z min').' : '.sprintf('%2.2f', $node->file->zmin).'m',
|
| 574 |
t('Z max').' : '.sprintf('%2.2f', $node->file->zmax).'m'
|
| 575 |
),
|
| 576 |
t('Characteristics'),
|
| 577 |
'ul'
|
| 578 |
);
|
| 579 |
|
| 580 |
if (!$teaser) {
|
| 581 |
$output .= theme_item_list(
|
| 582 |
array(),
|
| 583 |
t('Map'),
|
| 584 |
'ul'
|
| 585 |
);
|
| 586 |
|
| 587 |
$output .= ' <table width="95%"><tr><td>';
|
| 588 |
$output .= ' <div id="map" style="height: 600px; left:0px; right:0px;"></div>';
|
| 589 |
$output .= ' </td></tr><tr><td>';
|
| 590 |
$output .= ' <div id="info" style="height: 30px">'.t("Loading").'...'.'</div>';
|
| 591 |
$output .= ' </td></tr></table>';
|
| 592 |
|
| 593 |
|
| 594 |
$output .= theme_item_list(
|
| 595 |
array(
|
| 596 |
track_flash_chart(565, 420, $node->nid, "profile"),
|
| 597 |
track_flash_chart(565, 420, $node->nid, "repartition")
|
| 598 |
),
|
| 599 |
t('Charts')." (".l("FusionCharts", "http://www.infosoftglobal.com/FusionCharts/").")",
|
| 600 |
'ul'
|
| 601 |
);
|
| 602 |
|
| 603 |
// Only create link to file when it is in the proper location.
|
| 604 |
if (file_check_location($file->filepath, file_directory_path())) {
|
| 605 |
$output .= theme_item_list(
|
| 606 |
array(
|
| 607 |
"<p>".l($node->title . ' - '.t('GPX file'), 'track/gpx/'.$node->nid),
|
| 608 |
// "<p>".l($node->title . ' - '.t('TRK file'), 'track/trk/'.$node->nid),
|
| 609 |
"<p>".l($node->title . ' - '.t('KML file'), 'track/kml/'.$node->nid)
|
| 610 |
),
|
| 611 |
t('Downloads'),
|
| 612 |
'ul'
|
| 613 |
);
|
| 614 |
}
|
| 615 |
|
| 616 |
}
|
| 617 |
|
| 618 |
$output .= "</p>";
|
| 619 |
}
|
| 620 |
|
| 621 |
return $output;
|
| 622 |
}
|
| 623 |
|
| 624 |
/**
|
| 625 |
* Implementation of hook_form().
|
| 626 |
*
|
| 627 |
* Return an array of the form elements needed to edit this node.
|
| 628 |
*/
|
| 629 |
function track_form(&$node) {
|
| 630 |
$op = isset($_POST['op']) ? $_POST['op'] : '';
|
| 631 |
|
| 632 |
if ($op == t('Preview')) {
|
| 633 |
track_validate($node);
|
| 634 |
}
|
| 635 |
if ($op == t('Submit')) {
|
| 636 |
track_validate($node);
|
| 637 |
}
|
| 638 |
|
| 639 |
// Set form parameters so we can accept file uploads.
|
| 640 |
$form['#attributes'] = array('enctype' => 'multipart/form-data');
|
| 641 |
|
| 642 |
// Title of the track
|
| 643 |
$form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
|
| 644 |
|
| 645 |
// Check if a file exists for the node
|
| 646 |
if ($node->file->filepath) {
|
| 647 |
$form['title']['#description'] .= t('A file already exists: '.$node->file->filepath);
|
| 648 |
$form['current_file'] = array(
|
| 649 |
'#type' => 'hidden',
|
| 650 |
'#value' => $node->file->filepath
|
| 651 |
);
|
| 652 |
}
|
| 653 |
// file upload field
|
| 654 |
$form['file'] = array(
|
| 655 |
'#type' => 'file',
|
| 656 |
'#title' => t('File').'<span class="form-required" title="This field is required.">*</span>',
|
| 657 |
'#size' => 40,
|
| 658 |
'#default_value' => '',
|
| 659 |
'#weight' => -3,
|
| 660 |
'#description' => t('GPX file'),
|
| 661 |
);
|
| 662 |
|
| 663 |
$form['body_filter']['body'] = array(
|
| 664 |
'#type' => 'textarea',
|
| 665 |
'#title' => t('Body'),
|
| 666 |
'#default_value' => $node->body,
|
| 667 |
'#rows' => 10,
|
| 668 |
'#weight' => -2,
|
| 669 |
'#required' => TRUE);
|
| 670 |
$form['body_filter']['filter'] = filter_form($node->format);
|
| 671 |
|
| 672 |
return $form;
|
| 673 |
}
|
| 674 |
|
| 675 |
|
| 676 |
function track_form_alter($form_id, &$form) {
|
| 677 |
}
|
| 678 |
|
| 679 |
function file_check_local($source) {
|
| 680 |
$file = new StdClass();
|
| 681 |
$file->filename = trim(basename($source), '.');
|
| 682 |
$file->filepath = $source;
|
| 683 |
return $file;
|
| 684 |
}
|
| 685 |
|
| 686 |
function track_validate_file(&$node) {
|
| 687 |
$validators = array(
|
| 688 |
'file_validate_extensions' => array('gpx'),
|
| 689 |
);
|
| 690 |
|
| 691 |
// Check for a new file upload.
|
| 692 |
if ($file = file_save_upload('file', $validators, file_directory_path())) {
|
| 693 |
file_set_status($file, FILE_STATUS_PERMANENT);
|
| 694 |
|
| 695 |
$node->file = $file;
|
| 696 |
$node->current_file = $node->file->filepath;
|
| 697 |
}
|
| 698 |
else
|
| 699 |
{
|
| 700 |
$current_file = isset($_POST['edit']['current_file']) ? $_POST['edit']['current_file'] : '';
|
| 701 |
if (file_exists($current_file)) {
|
| 702 |
$node->file = file_check_local($current_file);
|
| 703 |
$node->current_file = $node->file->filepath;
|
| 704 |
$file = $node->file;
|
| 705 |
}
|
| 706 |
}
|
| 707 |
return $file;
|
| 708 |
}
|
| 709 |
|
| 710 |
/**
|
| 711 |
* Implementation of hook_validate().
|
| 712 |
*
|
| 713 |
* Verify that there is a file attached to the node.
|
| 714 |
*/
|
| 715 |
function track_validate(&$node) {
|
| 716 |
$file = track_validate_file($node);
|
| 717 |
// Make sure there is an upload or an existing file.
|
| 718 |
if (!$file && !file_exists($node->current_file) && !file_exists($node->file->filepath)) {
|
| 719 |
form_set_error('file', t('A file must be provided.'));
|
| 720 |
}
|
| 721 |
}
|
| 722 |
|
| 723 |
/**
|
| 724 |
* Implementation of hook_execute().
|
| 725 |
*
|
| 726 |
* If a file was uploaded save it before updating the database.
|
| 727 |
*/
|
| 728 |
function track_execute(&$node) {
|
| 729 |
$file = track_validate_file($node);
|
| 730 |
// Make sure there is an upload or an existing file.
|
| 731 |
if (!$file && !file_exists($node->current_file)) {
|
| 732 |
form_set_error('file', t('A file must be provided.'));
|
| 733 |
}
|
| 734 |
}
|
| 735 |
|
| 736 |
/**
|
| 737 |
* Implementation of hook_load().
|
| 738 |
*
|
| 739 |
* The node is being loaded. Load the file's information from the database so
|
| 740 |
* it can be added to the node.
|
| 741 |
*/
|
| 742 |
function track_load($node) {
|
| 743 |
$extras = new StdClass();
|
| 744 |
$extras->file = db_fetch_object(db_query('SELECT filename, filepath, '.
|
| 745 |
'latstart,lonstart,latmin,latmax,lonmin,lonmax,length,dzminu,dzplus,zmin,zmax'.
|
| 746 |
' FROM {track} WHERE nid = %d', $node->nid));
|
| 747 |
return $extras;
|
| 748 |
}
|
| 749 |
|
| 750 |
/**
|
| 751 |
* Implementation of hook_insert().
|
| 752 |
*
|
| 753 |
* The node is being created, save the file's infomation to the database.
|
| 754 |
*/
|
| 755 |
function track_insert($node) {
|
| 756 |
track_validate($node);
|
| 757 |
$file = $node->file;
|
| 758 |
|
| 759 |
$aGPXfile = new GPX_file();
|
| 760 |
$aGPXfile->LoadFromFile($file->filepath);
|
| 761 |
$aGPXfile->getInfos($latstart,$lonstart,$latmin,$latmax,$lonmin,$lonmax,$length,$dzminu,$dzplus,$zmin,$zmax);
|
| 762 |
|
| 763 |
db_query("INSERT INTO {track} (nid, filename, filepath, ".
|
| 764 |
"latstart,lonstart,latmin,latmax,lonmin,lonmax,length,dzminu,dzplus,zmin,zmax".
|
| 765 |
") VALUES (%d, '%s', '%s', %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f)",
|
| 766 |
$node->nid, $file->filename, $file->filepath,
|
| 767 |
$latstart,$lonstart,$latmin,$latmax,$lonmin,$lonmax,$length,$dzminu,$dzplus,$zmin,$zmax
|
| 768 |
);
|
| 769 |
}
|
| 770 |
|
| 771 |
/**
|
| 772 |
* Implementation of hook_update().
|
| 773 |
*
|
| 774 |
* The node is being updated, save the updated file's infomation to the database.
|
| 775 |
*/
|
| 776 |
function track_update($node) {
|
| 777 |
track_validate($node);
|
| 778 |
$file = $node->file;
|
| 779 |
|
| 780 |
if ($file->filepath) {
|
| 781 |
$aGPXfile = new GPX_file();
|
| 782 |
$aGPXfile->LoadFromFile($file->filepath);
|
| 783 |
$aGPXfile->getInfos($latstart,$lonstart,$latmin,$latmax,$lonmin,$lonmax,$length,$dzminu,$dzplus,$zmin,$zmax);
|
| 784 |
|
| 785 |
db_query("UPDATE {track} SET filename='%s', filepath='%s',".
|
| 786 |
"latstart=%f,lonstart=%f,latmin=%f,latmax=%f,lonmin=%f,lonmax=%f,length=%f,dzminu=%f,dzplus=%f,zmin=%f,zmax=%f".
|
| 787 |
"WHERE NID=%d",
|
| 788 |
$file->filename, $file->filepath,
|
| 789 |
$latstart,$lonstart,$latmin,$latmax,$lonmin,$lonmax,$length,$dzminu,$dzplus,$zmin,$zmax,$node->nid
|
| 790 |
);
|
| 791 |
}
|
| 792 |
}
|
| 793 |
|
| 794 |
/**
|
| 795 |
* Implementation of hook_delete().
|
| 796 |
*
|
| 797 |
* The node is being delete, remove the file and any information.
|
| 798 |
*/
|
| 799 |
function track_delete($node) {
|
| 800 |
file_delete($node->filepath);
|
| 801 |
db_query("DELETE FROM {track} WHERE nid = %d", $node->nid);
|
| 802 |
}
|
| 803 |
|
| 804 |
//function track_settings() {
|
| 805 |
// $form['googlemapskey'] = array(
|
| 806 |
// '#type' => 'textfield',
|
| 807 |
// '#title' => t('Google Maps key'),
|
| 808 |
// '#default_value' => variable_get('googlemapskey', 'AAAAAAAAAAA'),
|
| 809 |
// '#size' => 120,
|
| 810 |
// '#maxlength' => 255,
|
| 811 |
// '#description' => t('Required by Google. ').l(t('You will be able to generate your key here'), 'http://www.google.com/apis/maps/signup.html')
|
| 812 |
// );
|
| 813 |
//
|
| 814 |
// return $form;
|
| 815 |
//}
|
| 816 |
|