Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
$Longitude = $this->Explode($DbRow['Longitude']);
$Latitude = $this->Explode($DbRow['Latitude']);
$Output = ''.$Latitude[0].'°'.$Latitude[1]."'".$Latitude[2].'" '.$Longitude[0].'°'.$Longitude[1]."'".$Longitude[2].'"';
}
return $Output;
}
function OnEdit(array $Item): string
{
if ($Item['Value'] != '')
{
$DbResult = $this->Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);
if ($DbResult->num_rows > 0)
{
$DbRow = $DbResult->fetch_assoc();
} else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
} else $DbRow = array('Longitude' => 0, 'Latitude' => 0);
$Value = $this->Explode($DbRow['Latitude']);
$Output = '°';
$Output .= '\'';
$Output .= '"
';
$Value = $this->Explode($DbRow['Longitude']);
$Output .= '°';
$Output .= '\'';
$Output .= '"';
return $Output;
}
function OnLoad(array $Item): ?string
{
$Latitude = $this->Implode($_POST[$Item['Name'].'-lat-deg'], $_POST[$Item['Name'].'-lat-min'], $_POST[$Item['Name'].'-lat-sec']);
$Longitude = $this->Implode($_POST[$Item['Name'].'-lon-deg'], $_POST[$Item['Name'].'-lon-min'], $_POST[$Item['Name'].'-lon-sec']);
$this->Database->query('INSERT INTO SystemGPS (`Latitude`, `Longitude`) VALUES ("'.$Latitude.'", "'.$Longitude.'")');
return $this->Database->insert_id;
}
function OnCanLoad(array $Item): bool
{
return array_key_exists($Item['Name'].'-lat-deg', $_POST) and array_key_exists($Item['Name'].'-lat-sec', $_POST) and
array_key_exists($Item['Name'].'-lat-min', $_POST) and array_key_exists($Item['Name'].'-lon-deg', $_POST) and
array_key_exists($Item['Name'].'-lon-min', $_POST) and array_key_exists($Item['Name'].'-lon-sec', $_POST);
}
function Explode(float $Float): array
{
$Degrees = intval($Float);
$Float = abs($Float);
$Float = ($Float - intval($Float)) * 60;
$Minutes = intval($Float);
$Float = ($Float - intval($Float)) * 60;
$Seconds = round($Float, 3);
return array($Degrees, $Minutes, $Seconds);
}
function Implode($Degrees, $Minutes, $Seconds): float
{
if ($Degrees < 0) return -(abs($Degrees) + ($Minutes + $Seconds / 60) / 60);
else return $Degrees + ($Minutes + $Seconds / 60) / 60;
}
}