source: branches/mvc/Base/Types/GPS.php

Last change on this file was 47, checked in by chronos, 10 years ago
  • Odstraněno: Zbytečná PHP ukončovací značka "?>" z konce všech souborů.
File size: 2.7 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Base.php');
4
5class TypeGPS extends TypeBase
6{
7 function OnView($Item)
8 {
9 global $Database;
10
11 $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
12 if($DbResult->num_rows > 0)
13 {
14 $DbRow = $DbResult->fetch_assoc();
15 $Longitude = $this->Explode($DbRow['Longitude']);
16 $Latitude = $this->Explode($DbRow['Latitude']);
17 $Output = '<a href="http://www.mapy.cz/?st=search&fr=loc:'.$DbRow['Latitude'].' '.$DbRow['Longitude'].'">'.$Latitude[0].'°'.$Latitude[1]."'".$Latitude[2].'" '.$Longitude[0].'°'.$Longitude[1]."'".$Longitude[2].'"</a>';
18 }
19 return($Output);
20 }
21
22 function OnEdit($Item)
23 {
24 global $Database;
25
26 if($Item['Value'] != '')
27 {
28 $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
29 if($DbResult->num_rows > 0)
30 {
31 $DbRow = $DbResult->fetch_assoc();
32 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
33 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
34 $Value = $this->Explode($DbRow['Latitude']);
35 $Output = '<input type="text" size="3" name="'.$Item['Name'].'-lat-deg" value="'.$Value[0].'"/>°';
36 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-min" value="'.$Value[1].'"/>\'';
37 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-sec" value="'.$Value[2].'"/>"<br />';
38 $Value = $this->Explode($DbRow['Longitude']);
39 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-deg" value="'.$Value[0].'"/>°';
40 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-min" value="'.$Value[1].'"/>\'';
41 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-sec" value="'.$Value[2].'"/>"';
42 return($Output);
43 }
44
45 function OnLoad($Item)
46 {
47 global $Database;
48
49 $Latitude = $this->Implode($_POST[$Item['Name'].'-lat-deg'], $_POST[$Item['Name'].'-lat-min'], $_POST[$Item['Name'].'-lat-sec']);
50 $Longitude = $this->Implode($_POST[$Item['Name'].'-lon-deg'], $_POST[$Item['Name'].'-lon-min'], $_POST[$Item['Name'].'-lon-sec']);
51 $Database->query('INSERT INTO SystemGPS (`Latitude`, `Longitude`) VALUES ("'.$Latitude.'", "'.$Longitude.'")');
52 return($Database->insert_id);
53 }
54
55 function Explode($Float)
56 {
57 $Degrees = intval($Float);
58 $Float = abs($Float);
59 $Float = ($Float - intval($Float)) * 60;
60 $Minutes = intval($Float);
61 $Float = ($Float - intval($Float)) * 60;
62 $Seconds = round($Float, 3);
63 return(array($Degrees, $Minutes, $Seconds));
64 }
65
66 function Implode($Degrees, $Minutes, $Seconds)
67 {
68 if($Degrees < 0) return(-(abs($Degrees) + ($Minutes + $Seconds / 60) / 60));
69 else return($Degrees + ($Minutes + $Seconds / 60) / 60);
70 }
71}
Note: See TracBrowser for help on using the repository browser.