source: trunk/Packages/FormManager/Types/GPS.php

Last change on this file was 8, checked in by chronos, 18 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 3.1 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/Base.php');
4
5class TypeGPS extends TypeBase
6{
7 function OnView(array $Item): ?string
8 {
9 $DbResult = $this->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="https://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(array $Item): string
21 {
22 if ($Item['Value'] != '')
23 {
24 $DbResult = $this->Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
25 if ($DbResult->num_rows > 0)
26 {
27 $DbRow = $DbResult->fetch_assoc();
28 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
29 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
30 $Value = $this->Explode($DbRow['Latitude']);
31 $Output = '<input type="text" size="3" name="'.$Item['Name'].'-lat-deg" value="'.$Value[0].'"/>°';
32 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-min" value="'.$Value[1].'"/>\'';
33 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lat-sec" value="'.$Value[2].'"/>"<br />';
34 $Value = $this->Explode($DbRow['Longitude']);
35 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-deg" value="'.$Value[0].'"/>°';
36 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-min" value="'.$Value[1].'"/>\'';
37 $Output .= '<input type="text" size="3" name="'.$Item['Name'].'-lon-sec" value="'.$Value[2].'"/>"';
38 return $Output;
39 }
40
41 function OnLoad(array $Item): ?string
42 {
43 $Latitude = $this->Implode($_POST[$Item['Name'].'-lat-deg'], $_POST[$Item['Name'].'-lat-min'], $_POST[$Item['Name'].'-lat-sec']);
44 $Longitude = $this->Implode($_POST[$Item['Name'].'-lon-deg'], $_POST[$Item['Name'].'-lon-min'], $_POST[$Item['Name'].'-lon-sec']);
45 $this->Database->query('INSERT INTO SystemGPS (`Latitude`, `Longitude`) VALUES ("'.$Latitude.'", "'.$Longitude.'")');
46 return $this->Database->insert_id;
47 }
48
49 function OnCanLoad(array $Item): bool
50 {
51 return array_key_exists($Item['Name'].'-lat-deg', $_POST) and array_key_exists($Item['Name'].'-lat-sec', $_POST) and
52 array_key_exists($Item['Name'].'-lat-min', $_POST) and array_key_exists($Item['Name'].'-lon-deg', $_POST) and
53 array_key_exists($Item['Name'].'-lon-min', $_POST) and array_key_exists($Item['Name'].'-lon-sec', $_POST);
54 }
55
56 function Explode(float $Float): array
57 {
58 $Degrees = intval($Float);
59 $Float = abs($Float);
60 $Float = ($Float - intval($Float)) * 60;
61 $Minutes = intval($Float);
62 $Float = ($Float - intval($Float)) * 60;
63 $Seconds = round($Float, 3);
64 return array($Degrees, $Minutes, $Seconds);
65 }
66
67 function Implode($Degrees, $Minutes, $Seconds): float
68 {
69 if ($Degrees < 0) return -(abs($Degrees) + ($Minutes + $Seconds / 60) / 60);
70 else return $Degrees + ($Minutes + $Seconds / 60) / 60;
71 }
72}
Note: See TracBrowser for help on using the repository browser.