source: trunk/Common/Form/Types/GPS.php

Last change on this file was 922, checked in by chronos, 3 years ago
  • Modified: Do not determine form submit from URL but directly from submit variable and filled form variables.
  • Added: Use system config from /etc/isp-central directory if standard config is not available.
  • Modified: Form file code cleanup. FormManager class moved to separate file.
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
57 function Explode(float $Float): array
58 {
59 $Degrees = intval($Float);
60 $Float = abs($Float);
61 $Float = ($Float - intval($Float)) * 60;
62 $Minutes = intval($Float);
63 $Float = ($Float - intval($Float)) * 60;
64 $Seconds = round($Float, 3);
65 return array($Degrees, $Minutes, $Seconds);
66 }
67
68 function Implode($Degrees, $Minutes, $Seconds): float
69 {
70 if ($Degrees < 0) return -(abs($Degrees) + ($Minutes + $Seconds / 60) / 60);
71 else return $Degrees + ($Minutes + $Seconds / 60) / 60;
72 }
73}
Note: See TracBrowser for help on using the repository browser.