1 | <?php
|
---|
2 |
|
---|
3 | class TypeGPS extends TypeBase
|
---|
4 | {
|
---|
5 | function OnView($Item)
|
---|
6 | {
|
---|
7 | global $Database;
|
---|
8 |
|
---|
9 | $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
|
---|
10 | if($DbResult->num_rows > 0)
|
---|
11 | {
|
---|
12 | $DbRow = $DbResult->fetch_assoc();
|
---|
13 | $Longitude = $this->Explode($DbRow['Longitude']);
|
---|
14 | $Latitude = $this->Explode($DbRow['Latitude']);
|
---|
15 | $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>';
|
---|
16 | }
|
---|
17 | return($Output);
|
---|
18 | }
|
---|
19 |
|
---|
20 | function OnEdit($Item)
|
---|
21 | {
|
---|
22 | global $Database;
|
---|
23 |
|
---|
24 | if($Item['Value'] != '')
|
---|
25 | {
|
---|
26 | $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
|
---|
27 | if($DbResult->num_rows > 0)
|
---|
28 | {
|
---|
29 | $DbRow = $DbResult->fetch_assoc();
|
---|
30 | } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
|
---|
31 | } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
|
---|
32 | $Value = $this->Explode($DbRow['Latitude']);
|
---|
33 | $Output = '<input type="text" size="3" name="'.$Item['Name'].'-lat-deg" value="'.$Value[0].'">°';
|
---|
34 | $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-min" value="'.$Value[1].'">\'';
|
---|
35 | $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-sec" value="'.$Value[2].'">"<br />';
|
---|
36 | $Value = $this->Explode($DbRow['Longitude']);
|
---|
37 | $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-deg" value="'.$Value[0].'">°';
|
---|
38 | $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-min" value="'.$Value[1].'">\'';
|
---|
39 | $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-sec" value="'.$Value[2].'">"';
|
---|
40 | return($Output);
|
---|
41 | }
|
---|
42 |
|
---|
43 | function OnLoad($Item)
|
---|
44 | {
|
---|
45 | global $Database;
|
---|
46 |
|
---|
47 | $Latitude = $this->Implode($_POST[$Item['Name'].'-lat-deg'], $_POST[$Item['Name'].'-lat-min'], $_POST[$Item['Name'].'-lat-sec']);
|
---|
48 | $Longitude = $this->Implode($_POST[$Item['Name'].'-lon-deg'], $_POST[$Item['Name'].'-lon-min'], $_POST[$Item['Name'].'-lon-sec']);
|
---|
49 | $Database->query('INSERT INTO SystemGPS (`Latitude`, `Longitude`) VALUES ("'.$Latitude.'", "'.$Longitude.'")');
|
---|
50 | return($Database->insert_id);
|
---|
51 | }
|
---|
52 |
|
---|
53 | function Explode($Float)
|
---|
54 | {
|
---|
55 | $Degrees = intval($Float);
|
---|
56 | $Float = abs($Float);
|
---|
57 | $Float = ($Float - intval($Float)) * 60;
|
---|
58 | $Minutes = intval($Float);
|
---|
59 | $Float = ($Float - intval($Float)) * 60;
|
---|
60 | $Seconds = round($Float, 3);
|
---|
61 | return(array($Degrees, $Minutes, $Seconds));
|
---|
62 | }
|
---|
63 |
|
---|
64 | function Implode($Degrees, $Minutes, $Seconds)
|
---|
65 | {
|
---|
66 | if($Degrees < 0) return(-(abs($Degrees) + ($Minutes + $Seconds / 60) / 60));
|
---|
67 | else return($Degrees + ($Minutes + $Seconds / 60) / 60);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | ?>
|
---|