Jump to content

Landing rates and condition


Jakes

Recommended Posts

Hi Jeffrey,

The code as it is now. I cannot understand why it doesn't write to the db, maybe a fresh eye will catch the fault?

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
  CodonEvent::addListener('Aircraft_Condition');
}
public function EventListener($eventinfo)
   {
  if($eventinfo[2] == 'pirep_filed')

   //Retrieve the aircraft info based on the aircraft id stored in the pirep row

   $aircraft = OperationsData::getAircraftByReg($pirepdata->registration);

   //Figure out the $cond that needs to be placed into the
   if($pirepdata->landingrate > 1 && $pirepdata->landingrate <-500)
  $cond = $aircraft->cond -20;
  else $cond = 50;

   $params = array (
  'id'    => $aircraft->id,
  'cond'    => $cond,
  'minrank'    => $aircraft->minrank,
  'enabled'    => $aircraft->enabled,
  );
$update = OperationsData::editAircraft($params);
   }
}

Link to comment
Share on other sites

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Guest lorathon

Try this..... Remember that this code should be located in core/modules/Aircraft_Condition/Aircraft_Condition.php

<?php
class Aircraft_Condition extends CodonModule
{

public function __construct() {
CodonEvent::addListener('Aircraft_Condition');				
}

public function EventListener($eventinfo) {

   if($eventinfo[0] == 'pirep_filed') {

  $pirepinfo = $eventinfo[2];		  
							 $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
  $pirepinfo->landingrate = intval($pirepinfo->landingrate);
  if($pirepinfo->landingrate < -100 && $pirepinfo->landingrate > -500)
							  $cond = $aircraft->cond -20;
							 else
							  $cond = 100;

							 $params = array (
'id'	=> $aircraft->id,
'cond'	=> $cond,
'minrank'	=> $aircraft->minrank,
'enabled'	=> $aircraft->enabled,
);
$update = OperationsData::editAircraft($params);
						}

}

In the core/modules/acars/acar.php

Find this under FileReport

CodonEvent::Dispatch('pirep_filed', 'PIREPS', $_POST);

Change it to this

CodonEvent::Dispatch('pirep_filed', 'PIREPS', $data);

See if that works.

Link to comment
Share on other sites

Hi Jeffrey,

Thanks, but i cannot find the CodonEvent::Dispatch('pirep_filed','PIREPS', $_POST); In the core/modules/acars/acars.php

Perhaps it in another file?

yeah same here only codonEvent::Dispatch I have in my acars.php

is CodonEvent::Dispatch('refresh_acars', 'ACARS');

Link to comment
Share on other sites

The only place other that this is in the PIREP.php and even so is withouth the $_post ending the line. Tested by adding the $_post as well as the $data and while one doesn't throw any errors, it still doesn't update either. How accurate is the calculation code?

Link to comment
Share on other sites

Guest lorathon

As for the calculation code.....

Not sure what you mean. The calc code will either set the $cond as -20 or 100. So there is always an output to update with. I have been trying to tell you guys that it is not the update that is wrong. The code is either not firing at all. Or the $pirepinfo is not being filled. Both the code I wrote with the custom update function and the editAircraft code will work.

When I walked through the filing process I found the event trigger and noticed that the output had $_POST as the output data. Well there is no $_POST for input into the function. The function of ACARSData::FilePIREP is fired using the variables of $pilotid and $data. To me it looks like the 'pirep_filed' is being triggered but without anything in the $eventinfo[2] array. Hopefully the change to $data will fire the $eventinfo[2] array.

Link to comment
Share on other sites

Hi lorathon,

Thank you :) so, the code you gave us along with the changes to be made in the acarsdata.class, the mod should work? Will try both sets of code and make the necessary changes and then report back,

One again, thank you for your time and support.

Much appreciated

Link to comment
Share on other sites

Guest lorathon

Stable version of phpVMS OperationsData

public static function editAircraft($data)
{
 $data['icao'] = DB::escape(strtoupper($data['icao']));
 $data['name'] = DB::escape(strtoupper($data['name']));
 $data['registration'] = DB::escape(strtoupper($data['registration']));

 $data['range'] = ($data['range'] == '') ? 0 : $data['range'];
 $data['weight'] = ($data['weight'] == '') ? 0 : $data['weight'];
 $data['cruise'] = ($data['cruise'] == '') ? 0 : $data['cruise'];

 $data['range'] = str_replace(',', '', $data['range']);
 $data['weight'] = str_replace(',', '', $data['weight']);
 $data['cruise'] = str_replace(',', '', $data['cruise']);
 $data['maxpax'] = str_replace(',', '', $data['maxpax']);
 $data['maxcargo'] = str_replace(',', '', $data['maxcargo']);

 if(empty($data['minrank']))
 {
  $data['minrank'] = 0;
 }

 if($data['enabled'] === true)
  $data['enabled'] = 1;
 else
  $data['enabled'] = 0;

 if($data['minrank'] > 0)
 {
  $rank_level = RanksData::getRankLevel($data['minrank']);
 }
 else
 {
  $rank_level = 0;
 }
 $sql = "UPDATE " . TABLE_PREFIX."aircraft
SET `icao`='{$data['icao']}', `name`='{$data['name']}', `fullname`='{$data['fullname']}',
 `registration`='{$data['registration']}', `downloadlink`='{$data['downloadlink']}',
 `imagelink`='{$data['imagelink']}', `range`='{$data['range']}', `weight`='{$data['weight']}',
 `cruise`='{$data['cruise']}', `maxpax`='{$data['maxpax']}', `maxcargo`='{$data['maxcargo']}',
 `minrank`={$data['minrank']}, `ranklevel`={$rank_level}, `enabled`={$data['enabled']}
WHERE `id`={$data['id']}";

 $res = DB::query($sql);

 if(DB::errno() != 0)
  return false;

 CodonCache::delete('all_aircraft');
 CodonCache::delete('all_aircraft_enabled');
 CodonCache::delete('all_aircraft_search');
 CodonCache::delete('all_aircraft_search_enabled');

 return true;
}

The stable version will not update the 'cond' column. Or am I incorrect?

Link to comment
Share on other sites

Ok, worked on a few angles. First, Jeffery, I've tried your code above, and no luck. @Nabeel, thhrowing a DB::debug() as suggested, give an error.

Parse error: syntax error, unexpected '}' in C:\wamp\www\core\modules\Aircraft_Condition\Aircraft_Condition.php on line 27

Also, Jefferey, I have already modified my OperationsData,class to this:

/**
 * Edit an aircraft
 */
   public static function editAircraft($data) {

    $data['icao'] = DB::escape(strtoupper($data['icao']));
    $data['name'] = DB::escape(strtoupper($data['name']));
    $data['registration'] = DB::escape(strtoupper($data['registration']));
    $data['range'] = ($data['range'] == '') ? 0 : $data['range'];
    $data['weight'] = ($data['weight'] == '') ? 0 : $data['weight'];
    $data['cruise'] = ($data['cruise'] == '') ? 0 : $data['cruise'];
    $data['range'] = str_replace(',', '', $data['range']);
    $data['weight'] = str_replace(',', '', $data['weight']);
    $data['cruise'] = str_replace(',', '', $data['cruise']);
    $data['maxpax'] = str_replace(',', '', $data['maxpax']);
    $data['maxcargo'] = str_replace(',', '', $data['maxcargo']);
    $data['price'] = ($data['price'] == '') ? 0 : $data['price'];
 $data['cond'] = ($data['cond'] == '') ? 0 : $data['cond'];
 $data['bought'] = ($data['bought'] == '') ? 0 : $data['bought'];

 $data['rep'] = ($data['rep'] == '') ? 0 : $data['rep'];

    if (empty($data['minrank'])) {
	    $data['minrank'] = 0;
    }
    if ($data['enabled'] === true || $data['enabled'] == '1') $data['enabled'] = 1;
    else  $data['enabled'] = 0;
    if ($data['minrank'] > 0) {
	    $data['ranklevel'] = RanksData::getRankLevel($data['minrank']);
    } else {
	    $data['ranklevel'] = 0;
    }
    $sql = "UPDATE " . TABLE_PREFIX . "aircraft SET ";
    $sql .= DB::build_update($data);
    $sql .= " WHERE `id`={$data['id']}";
    /*$sql = "UPDATE " . TABLE_PREFIX."aircraft
    SET `icao`='{$data['icao']}', `name`='{$data['name']}', `fullname`='{$data['fullname']}',
    `registration`='{$data['registration']}', `downloadlink`='{$data['downloadlink']}',
    `imagelink`='{$data['imagelink']}', `range`='{$data['range']}', `weight`='{$data['weight']}',
    `cruise`='{$data['cruise']}', `maxpax`='{$data['maxpax']}', `maxcargo`='{$data['maxcargo']}',`price`={$data['price']},`cond`={$data['cond']},
    `bought`={$data['bought']},`rep`={$data['rep']},`minrank`={$data['minrank']}, `ranklevel`={$rank_level}, `enabled`={$data['enabled']}, `bought`={$data['bought']}, `rep`={$data['rep']}
    WHERE `id`={$data['id']}";*/
    $res = DB::query($sql);
    if (DB::errno() != 0) return false;
    CodonCache::delete('all_aircraft');
    CodonCache::delete('all_aircraft_enabled');
    CodonCache::delete('all_aircraft_search');
    CodonCache::delete('all_aircraft_search_enabled');
    return true;
   }

Now, I need to explain my initial question;

The default phpVMS software does not have a "cond" table. Only after I installed the Step 1 Aircraft buying mod, the "cond" table was added.

Now when in the admin panel, the aircraft condition ( cond) is 0 until the aircraft is bought or leased. Only then, the aircraft show a condition. And not all of them shows 100% when bought. Some of my aircraft is at 95% even. So somewhere (Without this Aircraft_Condition module) there is already a code that calculate that condition. And I am looking for that code. Am I missing something?

Then, lastly, I went back to the basics:

I slightly modified the code on the developer's guides to test. First I tested the landingrate. It pics up the landing rate from a manual pirep which is 0

Here is what I have:

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct()
  {
  CodonEvent::addListener('Aircraft_Condition');						 
  }
public function EventListener($eventinfo)
{
 if($eventinfo[0] == 'pirep_prefile')
 {
  $pirepinfo = $eventinfo[2];
  if($pirepinfo->landingrate == 0)
  {
  Template::Set('message', 'This aircraft distance is out of range for this flight!');
  Template::Show('core_error.tpl');
  CodonEvent::Stop();
  }
 }
}
}

I have also tested it with an aircraft with a registration ZS-AA1 and it also worked well

if($pirepinfo->aircraft == 'ZS-AA1')

So the basics are working 100% Just need to write the condition to the DB

Link to comment
Share on other sites

  • Administrators

The stable version will not update the 'cond' column. Or am I incorrect?

Ahh, you're right.

So he needs another query to update it:

DB::query('UPDATE '.TABLE_PREFIX.'aircraft SET `cond`='.$cond.' WHERE `id`='.$aircraft->id);

Ok, worked on a few angles. First, Jeffery, I've tried your code above, and no luck. @Nabeel, thhrowing a DB::debug() as suggested, give an error.

Parse error: syntax error, unexpected '}' in C:\wamp\www\core\modules\Aircraft_Condition\Aircraft_Condition.php on line 27

That means you've got some other syntax error going on. Find and fix that first

Link to comment
Share on other sites

Thanks Thomas, but it is a bit confusing;

// Condition for new Plane
$newrd= rand(95, 100);

// Condition for used Plane
$userd= rand(60, 85);

// Condition for retired Plane
$retrd= rand(25, 55);

Then, there is also this line:

<input name="cond" type="hidden" value="<?php echo $newrd; ?>" />

My guess is that this have something to do with the state of the aircraft, whether it is new, used or retired.

I cannot understand why it is so difficult to just get a simple php script to write to a table. :(

Link to comment
Share on other sites

Oh nice, i find this topic now... :rolleyes:

@Jakes: This generates Random conditions for the different Aircrafts new/ used/ retired. Used and retired are only Placeholder to Buy used AC ( cheaper). Thats all-

And for my Aircraft Buying mod i Bypass the operationsdata.class. The changes are in Buyselldata.class. And u are right , i have added the colomn cond in the database and some other that i need.

At #14 u must use Buyselldata.class instead of operationsdata.class. In Operationsdata.class is no cond.

operationsdata.class= buyselldata.class (extended)

operations.php = Buysell.php (extended)

i want to buypass the original files, to simple delete the mod...

An example post #50

OperationsData::editAircraft(array(

'id' => THE ID

'cond' => $cond

));

The right use is :

BuysellData::editAircraft(array(

'id' => THE ID

'cond' => $cond

));

it´s only an example, i dont know if this will work on this point...

My Aircraft Buying mod is now on Github: https://Nighthawk666@github.com/Nighthawk666/Aircraft-Buying-mod.git

We all can work on this, to advance this mod.

Link to comment
Share on other sites

interesting ;) that could be a reason why it not update the cond value

please could someone with coding expirience test if it updates the cond value when using Nighthawks tips

since I think we are not that far away from solution :)

Link to comment
Share on other sites

<?php
/**
* phpVMS - Virtual Airline Administration Software
* Copyright (c) 2008 Nabeel Shahzad
* For more information, visit www.phpvms.net
* Forums: http://www.phpvms.net/forum
* Documentation: http://www.phpvms.net/docs
*
* phpVMS is licenced under the following license:
*   Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
*   View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*/
class Aircraft_Condition extends CodonModule
{
public function __index()
{
  CodonEvent::addListener('Aircraft_Condition');
}
public function EventListener($eventinfo)
{
  if($eventinfo[2] == 'pirep_filed')

//Retrieve the aircraft info based on the aircraft id stored in the pirep row

$aircraft = BuysellData::getAircraftByReg($pirepdata->registration);

//Figure out the $cond that needs to be placed into the
if($pirepdata->landingrate > 1 && $pirepdata->landingrate <-500)
  $cond = $aircraft->cond -20;
  else $cond = 50;

$params = array (
  'id'	=> $aircraft->id,
  'cond'	=> $cond,
  'minrank'	=> $aircraft->minrank,
  'enabled'	=> $aircraft->enabled,
  );
$update = BuysellData::editAircraft($params);
}
}

I wil try this

Link to comment
Share on other sites

Ok, i added in core/modules/Aircraft_Condition a file called Aircraft_Condition.php. Now i have to fly.

Oh, i found a failure in the above script

Wrong:

if($pirepdata->landingrate > 1 && $pirepdata->landingrate <-500)

Right:

if($pirepdata->landingrate < 1 && $pirepdata->landingrate >-500)

Because the Landing Rate is negative!

Link to comment
Share on other sites

  • 4 weeks later...

Hey Oaks,

It's been a long time since i've worked on this mod, and I have some success. First of all, I had success writing to the database. The code below is adjusting the condition. ( PLEASE BEWARE IF YOU USE IT LIKE THIS, IT WILL CHANGE THE ENTIRE FLEET'S CONDITION)

The code I have now, is a bare code, with the basics. It picks up the landing rate, and in this case, when zero, it writethe condition to the DB. Also, just to help , I have added a message to show me if it picks up the landing rate, and show a message when filed a pirep.

Also, teh event I test on is pirep_prefile. The reason is then I dont need to approve the pirep every time I do a test. It is simply to speed up the testing. Once all are sorted, I will change it back.

That is the main functions we need here.

Now, I am trying to update just the specific aircraft's condition. but haven't got much luck yet. Maybe I miss something and my brain is just tired?

AGAIN, I WARN YOU TO NOT USE THIS CODE ON AN ACTIVE WEBSITE, IT WILL CHANGE THE ENTIRE FLEET'S CONDITION.

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct()
  {
  CodonEvent::addListener('Aircraft_Condition');											  
  }
public function EventListener($eventinfo)
 {
if($eventinfo[0] == 'pirep_prefile')
{
  $pirepinfo = $eventinfo[2];
  if($pirepinfo->landingrate == 0)
  {
  $cond = 50;
  Template::Set('message', 'Landing rate Picked up!');
  Template::Show('core_error.tpl');
  //DB::query('UPDATE '.TABLE_PREFIX.'aircraft SET `cond`='.$cond.' WHERE `aircraft`='.$pirepinfo->aircraft);
  DB::query('UPDATE '.TABLE_PREFIX.'aircraft SET `cond`='.$cond );
  }
}

 if(DB::errno() != 0)
 return false;
CodonCache::delete('all_aircraft');
CodonCache::delete('all_aircraft_enabled');
CodonCache::delete('all_aircraft_search');
CodonCache::delete('all_aircraft_search_enabled');

return true;
 }
}

Here is the code I am working on to update a specific aircraft:

<?php
class Aircraft_Condition extends CodonModule
{
public function __construct()
  {
  CodonEvent::addListener('Aircraft_Condition');											   
  }
public function EventListener($eventinfo)
 {


   if($eventinfo[0] == 'pirep_prefile')
   {
  $pirepinfo = $eventinfo[2];
  $aircraft = OperationsData::getAircraftByReg($pirepinfo->registration);
  if($pirepinfo->landingrate == 0)
  {
  $cond = 50;
  Template::Set('message', 'This aircraft distance is out of range for this flight!');
  Template::Show('core_error.tpl');
  DB::query('UPDATE '.TABLE_PREFIX.'aircraft SET `cond`='.$cond.' WHERE `id`='.$aircraft );

  }
   }

 if(DB::errno() != 0)
 return false;
   CodonCache::delete('all_aircraft');
   CodonCache::delete('all_aircraft_enabled');
   CodonCache::delete('all_aircraft_search');
   CodonCache::delete('all_aircraft_search_enabled');

   return true;
 }
}

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...