Changeset 19 for types/GPS.php
- Timestamp:
- Oct 22, 2008, 9:12:20 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
types/GPS.php
r18 r19 1 1 <?php 2 2 3 function TypeGPSOnView($Item) 3 class TypeGPS 4 4 { 5 global $Database; 5 function OnView($Item) 6 { 7 global $Database; 6 8 7 $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']);8 if($DbResult->num_rows > 0)9 {10 $DbRow = $DbResult->fetch_assoc();11 $Longitude = TypeGPSExplode($DbRow['Longitude']);12 $Latitude = TypeGPSExplode($DbRow['Latitude']);13 $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>';14 }15 return($Output);16 }17 18 function TypeGPSOnEdit($Item)19 {20 global $Database;21 22 if($Item['Value'] != '')23 {24 9 $DbResult = $Database->query('SELECT * FROM `SystemGPS` WHERE `Id`='.$Item['Value']); 25 10 if($DbResult->num_rows > 0) 26 11 { 27 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); 28 31 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0); 29 } else $DbRow = array('Longitude' => 0, 'Latitude' => 0); 30 $Value = TypeGPSExplode($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 = TypeGPSExplode($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); 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 } 39 69 } 40 70 41 function TypeGPSOnLoad($Item) 42 { 43 global $Database; 44 45 $Latitude = TypeGPSImplode($_POST[$Item['Name'].'-lat-deg'], $_POST[$Item['Name'].'-lat-min'], $_POST[$Item['Name'].'-lat-sec']); 46 $Longitude = TypeGPSImplode($_POST[$Item['Name'].'-lon-deg'], $_POST[$Item['Name'].'-lon-min'], $_POST[$Item['Name'].'-lon-sec']); 47 $Database->query('INSERT INTO SystemGPS (`Latitude`, `Longitude`) VALUES ("'.$Latitude.'", "'.$Longitude.'")'); 48 return($Database->insert_id); 49 } 50 51 function TypeGPSExplode($Float) 52 { 53 $Degrees = intval($Float); 54 $Float = abs($Float); 55 $Float = ($Float - intval($Float)) * 60; 56 $Minutes = intval($Float); 57 $Float = ($Float - intval($Float)) * 60; 58 $Seconds = round($Float, 3); 59 return(array($Degrees, $Minutes, $Seconds)); 60 } 61 62 function TypeGPSImplode($Degrees, $Minutes, $Seconds) 63 { 64 if($Degrees < 0) return(-(abs($Degrees) + ($Minutes + $Seconds / 60) / 60)); 65 else return($Degrees + ($Minutes + $Seconds / 60) / 60); 66 } 71 $TypeDefinitionList['GPS'] = new TypeGPS; 67 72 68 73 ?>
Note:
See TracChangeset
for help on using the changeset viewer.