Jakes Posted March 28, 2012 Author Report Posted March 28, 2012 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); } }
Guest lorathon Posted March 28, 2012 Report Posted March 28, 2012 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.
Jakes Posted March 29, 2012 Author Report Posted March 29, 2012 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?
Txmmy83 Posted March 29, 2012 Report Posted March 29, 2012 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');
redcoals Posted March 29, 2012 Report Posted March 29, 2012 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?
Guest lorathon Posted March 29, 2012 Report Posted March 29, 2012 I am sorry. I put the wrong file name in core/common/acarsdata.class.php Woopsies
Guest lorathon Posted March 29, 2012 Report Posted March 29, 2012 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.
redcoals Posted March 29, 2012 Report Posted March 29, 2012 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
Administrators Nabeel Posted March 29, 2012 Administrators Report Posted March 29, 2012 You don't need to include 'minrank' => $aircraft->minrank, 'enabled' => $aircraft->enabled, Have you tried a print_r() on the $eventinfo call to see what's coming through?
Administrators Nabeel Posted March 29, 2012 Administrators Report Posted March 29, 2012 After $update = OperationsData::editAircraft($params); Throw a DB::debug() To see if there's an error being thrown
Guest lorathon Posted March 29, 2012 Report Posted March 29, 2012 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?
Jakes Posted March 29, 2012 Author Report Posted March 29, 2012 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
Administrators Nabeel Posted March 29, 2012 Administrators Report Posted March 29, 2012 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
Jakes Posted March 29, 2012 Author Report Posted March 29, 2012 Thanks Nabeel, do I need to add this to the module, or the OperationsData.class?
Txmmy83 Posted March 30, 2012 Report Posted March 30, 2012 the calculations are in ops_aircraftbuysell.tpl which you find in admin/templates starting at line 11 and they seemed to be only used in the admin backend
Jakes Posted April 3, 2012 Author Report Posted April 3, 2012 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.
Nighthawk Posted April 5, 2012 Report Posted April 5, 2012 Oh nice, i find this topic now... @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.
Txmmy83 Posted April 7, 2012 Report Posted April 7, 2012 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
Nighthawk Posted April 8, 2012 Report Posted April 8, 2012 grrrr. i havent enough time to test it grrrr
Nighthawk Posted April 9, 2012 Report Posted April 9, 2012 <?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
Nighthawk Posted April 9, 2012 Report Posted April 9, 2012 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!
Nighthawk Posted April 13, 2012 Report Posted April 13, 2012 i tried it now, but it doesn´t work. mhhh. Back to clipboard....
Jakes Posted April 16, 2012 Author Report Posted April 16, 2012 Hi Nighthawk, Thanks for the help so far, I will also play around with the new info you gave. Just a bit swamped in work right now. Cheers,
Jakes Posted May 21, 2012 Author Report Posted May 21, 2012 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; } }
Nighthawk Posted June 17, 2012 Report Posted June 17, 2012 i know, it´s very hardcore... i think we need to connect all the main programmers here to get it work
Nighthawk Posted June 17, 2012 Report Posted June 17, 2012 i made some workarounds but didnt find a way in the moment to get it to work
carlosuc99 Posted August 26, 2012 Report Posted August 26, 2012 How Can I use this module?? What files I need to modify or create?
Recommended Posts