Jump to content

Schedule Search by Airline


Alex

Recommended Posts

I have three airlines in my VA, AVA,AVC and AVE, i'm trying to search for only schedules by each of them using this code, but i cant get it to work and i'm kinda tying myself up losing where i'm at. I know its fairly simple but i'm passed that stage.

i'm editing the schedule_search.tpl

<div id="airlinetab">

	<p>Select Required Airline:</p>

       <select id="allairlines" name="airline">

       <option value="">Select Airline</option>

       <?php

       if (!$allairlines) $allairlines = array();

       	foreach($allairlines as $allairlines)

           {

           	echo '<option value="'.$allairlines.'">'.$allairlines
               .' ('.$allairlines->name.')</option>';
               }
               ?>

               </select>

	<input type="submit" name="submit" value="Find Flights" />
</div>

I have seen daves add on, however i could not get it to display the aircraft selection properly. i just kept getting Airport Icao's when i tried to search by aircraft.

(i changed in frontscheduledata.class line 38

$query = "SELECT DISTINCT icao

to

$query = "SELECT DISTINCT name

but now i get an error poining to this line in the frontschedlue.php of daves addon

foreach($aircrafts as $aircraft)

)

any pointers to where i'm going wrong?

Thanks Alex

Link to comment
Share on other sites

thanks Nabeel.

i tried this.

<div id="airlinetab">

               <p>Select Required Airline:</p>

       <select id="allairlines" name="airline">

       <option value="">Select Airline</option>

       <?php

       if (!$airline) $airline = array();

               foreach($allairlines as $airline)

           {

               echo '<option value="'.$airline.'">'.$airline
               .' ('.$airline->name.')</option>';
               }
               ?>

               </select>

               <input type="submit" name="submit" value="Find Flights" />
       </div

>

but it doesnt grab any of my airlines at all. All i get in the drop down is "select Airline".

search.jpg

I tried to copy the same way that is used to select departure airport etc.

Link to comment
Share on other sites

  • Administrators

The $allairlines variable must be empty. How are you supplying the data to that in the module? Try a print_r($allairlines) at the start of your template to see if there is anything in the variable. If that is not printing anything out then start working your way back through the module and then the data class to see where the variable is being dropped.

Link to comment
Share on other sites

The $allairlines variable must be empty. How are you supplying the data to that in the module? Try a print_r($allairlines) at the start of your template to see if there is anything in the variable. If that is not printing anything out then start working your way back through the module and then the data class to see where the variable is being dropped.

Out of my depth i think.

i looked into the module/schedules/shedules.php which gives this.

PASTEBIN

AND IN THE SCHEDULESDATA.CLASS.PHP

PASTEBIN

apols for quoting all the codes, im assuming that the schedules search uses these templates etc.

Link to comment
Share on other sites

  • Administrators

If you look in Schedules.php and follow the function that gives you the results for the schedules index you will find that it ends up using the

showSchedules()

function. There is no data call for getting the information for your airlines within that function. You will have to add the data call and assign it to a variable in your template. ie - $allairlines

Something like this should work.

$this->set('allairlines', OperationsData::GetAllAirlines());

Then in your template the $allairlines will be populated with the airlines from your database.

Link to comment
Share on other sites

Thanks Dave,

I entered that into schdules.php but got a syntax error, i changed it slightly and now have the form popluated with all the airlines, so thats sorted,

alsearch.jpg

however when selecting an individual airline, it just returns ALL flights from ALL airlines, so the actual search funtion for each airline isn't working.

Heres what i changed the schedules.php to.

public function showSchedules()
{
	$depapts = OperationsData::GetAllAirports();
	$equip = OperationsData::GetAllAircraftSearchList(true);
	$airline = OperationsData::GetAllAirlines();

	$this->set('allairlines', $airline);
	$this->set('depairports', $depapts);
	$this->set('equipment', $equip);

	$this->render('schedule_searchform.tpl');

and heres what i have in search_schedules.tpl

<div id="airlinetab">

               <p>Select Required Airline:</p>

       <select id="allairlines" name="allairlines">

       <option value="">Select Airline</option>

       <?php

       if (!$allairlines) $allairlines = array();

               foreach($allairlines as $airline)

           {

               echo '<option value="'.$airline->code.'" '.$sel.'>'.$airline->code.' - '.$airline->name.'</option>';
               }
               ?>

               </select>

               <input type="submit" name="submit" value="Find Flights" />
       </div>

do i need to add something like this into the

public function findflight()

if($this->post->s.code != '')
	{
		$params = array('s.code' => $this->post->airline);
	}

or

Do i need to add anything to scheduledata.class.php ?

Link to comment
Share on other sites

  • Administrators

You are going to have to intergrate a new search function into the js for that panel. You may be able to use parts of the module I wrote for schedule searches for airline sand airframes here -> http://forum.phpvms.net/topic/2197-schedule-search-airline-aircraft-arrival-departure/

Link to comment
Share on other sites

i think that will be way passed my skill level, i hoped that i could just copy the initial format as i posted in the first post to make this work, but it's clearly not that easy.

i tried to incorporate some of your code from frontschedules.php but failed miserably.

Link to comment
Share on other sites

failed almost fatally, ended up none of my pilots could file a pirep and all schedules dissapeared, don't know what i did but luckily a backup provided an escape.

i'm looking now at the common/schedules/schedulesdata.class.php and from reading nabeels comments in there i need to add something to the findflights part.

i cobbled together this, but still no luck in the actual search function working.

public function showSchedules()
{
	$depapts = OperationsData::GetAllAirports();
	$equip = OperationsData::GetAllAircraftSearchList(true);
	$airline = OperationsData::GetAllAirlines();
	$this->set('depairports', $depapts);
	$this->set('equipment', $equip);
	$this->set('airline', $airline);

	$this->render('schedule_searchform.tpl');

	# Show the routes. Remote this to not show them.
	$this->set('allroutes', SchedulesData::GetSchedules());

	$this->render('schedule_list.tpl');
}

public function findFlight()
{
	if($this->post->airline != '')
	{
		$params = array('s.code' => $this->post->airline);
	}

	if($this->post->depicao != '')
	{
		$params = array('s.depicao' => $this->post->depicao);
	}

	if($this->post->arricao != '')
	{
		$params = array('s.arricao' => $this->post->arricao);
	}

	if($this->post->equipment != '')
	{
		$params = array('a.name' => $this->post->equipment);
	}

	if($this->post->distance != '')
	{
		if($this->post->type == 'greater')
			$value = '> ';
		else
			$value = '< ';

		$value .= $this->post->distance;

		$params = array('s.distance' => $value);
	}

	$params['s.enabled'] = 1;
	$this->set('allroutes', SchedulesData::findSchedules($params));
	$this->render('schedule_results.tpl');

in your frontschedules.php it is written differently and i'm not confident enough to know the subtle differences.

Heres how that reads.

public function index() {
           if(isset($this->post->action))
           {
               if($this->post->action == 'findflight') {
               $this->findflight();
               }
           }
           else
           {
           $this->set('airports', OperationsData::GetAllAirports());
           $this->set('airlines', OperationsData::getAllAirlines());
           $this->set('aircrafts', FrontSchedulesData::findaircrafttypes());
           $this->set('countries', FrontSchedulesData::findcountries());
           $this->show('airport_search.tpl');
           }
       }

       public function findflight()
{
	$arricao = DB::escape($this->post->arricao);
               $depicao = DB::escape($this->post->depicao);
               $airline = DB::escape($this->post->airline);
               $aircraft = DB::escape($this->post->aircraft);

               if(!$airline)
                   {
                       $airline = '%';
                   }
               if(!$arricao)
                   {
                       $arricao = '%';
                   }
               if(!$depicao)
                   {
                       $depicao = '%';
                   }
               if($aircraft == !'')
               {
                   $aircrafts = FrontSchedulesData::findaircraft($aircraft);//print_r($aircrafts);
                   foreach($aircrafts as $aircraft)
                   {
                       $route = FrontSchedulesData::findschedules($arricao, $depicao, $airline, $aircraft->id);
                       if(!$route){$route=array();}
                       if(!$routes){$routes=array();}
                       $routes = array_merge($routes, $route);
                   }
               }
               else
               {
               $routes = FrontSchedulesData::findschedule($arricao, $depicao, $airline);
               }

	$this->set('allroutes', $routes);
	$this->show('schedule_results.tpl');

Dave, your frontschedules module works for me (as you directed in the posts above) however the search by aircraft type just displays the ICAO of airports in my list.

I'd be happy just to get either one working correctly without me messing it up again.

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

You are going to have to intergrate a new search function into the js for that panel. You may be able to use parts of the module I wrote for schedule searches for airline sand airframes here -> http://forum.phpvms.net/topic/2197-schedule-search-airline-aircraft-arrival-departure/

Dave, by this do you mean the Java Script? I'm still struggling with this airline search function.

Link to comment
Share on other sites

Ok in SchedulesDataClass i noticed that there was no search for the airline in the public function.

It appears that the airline is searched for using "s.code" is this correct?

i added the s.code as airline in the mysql queury added what i think should go but i'm probably way out. as it still doesnt search for the airline.

public static function findSchedules($params, $count = '', $start = '')
{
	$sql = 'SELECT s.*, 
				a.id as aircraftid, s.code as airline, a.name as aircraft, a.registration,
				a.minrank as aircraft_minrank, a.ranklevel as aircraftlevel,
				dep.name as depname, dep.lat AS deplat, dep.lng AS deplng,
				arr.name as arrname, arr.lat AS arrlat, arr.lng AS arrlng
			FROM '.TABLE_PREFIX.'schedules AS s
			LEFT JOIN '.TABLE_PREFIX.'airports AS dep ON dep.icao = s.depicao
			LEFT JOIN '.TABLE_PREFIX.'airports AS arr ON arr.icao = s.arricao
			LEFT JOIN '.TABLE_PREFIX.'airline AS air ON s.code = s.code
			LEFT JOIN '.TABLE_PREFIX.'aircraft AS a ON a.id = s.aircraft ';

This is really getting me down now, i have tried lots of trial and error and reading up of the API DOCS, to no avail.

i should clarify that whilst i state it doesnt search each individual airline, it does bring all the airlines up.

Link to comment
Share on other sites

My default template doesn't have the airline search function. i think it is an issue in the schedulesdataclass.

I have tried copy pasting the relevent parts from daves front schedules into my templates but just a errors galore.

I think the easiest thing will be to try an work out why daves frontschedules search module doesnt show my aircraft but the icao of airfields.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...