Ciao a tutti,
ho bisogno di una aiuto da qualche esperto, ma sinceramente non so bene se questo forum è quello giusto, ma spero molto di si.
Sono membro dello staff di una compagnia aerea virtuale, e il nostro sito è stato realizzato da un programmatore di php, ma abbiamo un problema che nemmeno lui riesce a risolvere.
Il domanda è questa:
nella pagina delle rotte, il codice legge le latitudini degli aeroporti in gradi da 0 a 180 Est, e da 0 a -180 Ovest. Il problema è che leggendo i gradi riconosce solo 3 caratteri, quindi verso ovest riconosce solo le latitudini fino a -99°, a -100° il codice php da errore.
Come posso modificare il codice per far riconoscere le latitudini oltre al -99°?
Vi riporto tutto il codice della pagina, e ringrazio chiunque riesca a darmi un aiuto.
Ciao a tutti.
codice:
<?php
class Routes extends Controller {
function Routes()
{
parent::Controller();
if($this->session->userdata('pid') == "")
{
redirect('login');
}
}
function index()
{
$this->template->write('title', 'Available Routes - Company Operations');
$query = $this->db->query("SELECT * FROM `pilots` WHERE `pilot_id` = '".$this->session->userdata('pid')."'");
$row = $query->row();
// all routes
$query2 = $this->db->query("SELECT * FROM `routes` WHERE `origin` = '".$row->location."'");
$european = '';
$american = '';
$asian = '';
foreach($query2->result() as $row2)
{
$query3 = $this->db->query("SELECT * FROM `airports` WHERE `ident` = '".$row2->destination."'");
$row3 = $query3->row();
$query4 = $this->db->query("SELECT * FROM `airports` WHERE `ident` = '".$row2->origin."'");
$row4 = $query4->row();
$tmprow = ' <tr>
<td>'.$row3->name.' - '.$row3->ident.'</td>
<td>'.round($this->distance($row3->lat,$row3->lon,$row4->lat,$row4->lon)).' nm</td>
<td>'.ucwords($row2->flight_type).'</td>
<td>Book Flight</td>
</tr>';
if(substr($row2->route_number,0,1) == "1" || substr($row2->route_number,0,1) == "3" || substr($row2->route_number,0,1) == "4")
{
$european .= $tmprow;
}
if(substr($row2->route_number,0,1) == "6" || substr($row2->route_number,0,1) == "7")
{
$american .= $tmprow;
}
if(substr($row2->route_number,0,1) == "2")
{
$asian .= $tmprow;
}
}
$this->template->parse_view('content', 'lounge/routes', array('eu'=>$european,'us'=>$american,'as'=>$asian ));
$this->template->render();
}
function distance($Aa, $Ba, $Ca, $Da){
// this is just some basic error checking i'd normally put it into a seperate file but
// for the purposes of this file... well you know.
$input = array($Aa, $Ba, $Ca, $Da);
foreach($input as $name){
if (@ereg("[[:alpha:]]",$name)){
echo "You cannot enter letters into this function
\n";
die;
}
if(@ereg("\.",$name)){
$dot = ".";
$pos = strpos($name, $dot);
//echo $pos."
\n";
if($pos > 3){
echo "The input cannot exceed more than 3 digits left of the decimal
\n";
die;
}
}
if($name > 365){
echo "The input cannot exceed 365 degrees
\n";
die;
}
}
$A = $Aa/57.29577951;
$B = $Ba/57.29577951;
$C = $Ca/57.29577951;
$D = $Da/57.29577951;
//convert all to radians: degree/57.29577951
if ($A == $C && $B == $D ){
$dist = 0;
}
else if ( (sin($A)* sin($C)+ cos($A)* cos($C)* cos($B-$D)) > 1){
$dist = 3963.1* acos(1);// solved a prob I ran into. I haven't fully analyzed it yet
}else{
$dist = 3963.1* acos(sin($A)*sin($C)+ cos($A)* cos($C)* cos($B-$D));
}
return ($dist);
}
}
/* End of file routes.php */
/* Location: ./system/application/controllers/routes.php */