David-Clark.net
Welcome to my random musings about web development, php, html, the codeigniter framework, and anything else that comes to mind.

If your phpVMS site is slow to respond during phpvms.net outage

If your site phpVMS based virtual airline is experiencing issues with timeouts and kACARS disconnects during the unfortunate outage of the phpVMS and VaCentral servers you can disable the functions in the framework that is calling back to the api server(s).

 

In the /core/local.config.php file change the following code;

 

Config::Set('VACENTRAL_ENABLED', true);

so it looks like this;

 

Config::Set('VACENTRAL_ENABLED', false);

and also

Config::Set('CHECK_RELEASE_VERSION', true);
Config::Set('CHECK_BETA_VERSION', true);

to

 

Config::Set('CHECK_RELEASE_VERSION', false);
Config::Set('CHECK_BETA_VERSION', false);

This should bring your site back to normal except for there will be no data sent to VaCentral. Once the phpVMS sites are back online just change those lines back to the original settings and you should be back up and running.

 

Also, if you have your VaCentral rank shown on your pages anywhere disable the function until phpVMS is restored.

Posted in phpVMS | Leave a comment

phpVMS Pilot Roster Module – Codon Framework

Many new users of the popular phpVMS system for Virtual Airlines developed as an opensource project by Nabeel Shazad question how to build a custom module to use within their own website.

The phpVMS/Codon structure follows the MVC structure for building an application. (Model, View, Controller) A short example on how to generate a full pilots roster, not by hubs, follows.

First we need to build the database query to collect all the pilots from the database, which would belong in a model. In your /core/common folder create a new php file, RosterData.class.php , notice the case sensitive naming structure.

Start the file with an opening php tag, be sure there is no white space prior to the tag in the file, if there is a “headers Already Sent” error will become your latest nemesis, then extend the existing CodonData object. Remeber the case sensitive nature of the naming conventions.

<?php

class RosterData extends CodonData  {

}

Notice there is no closing php tag, this will help keep the “Headers Already Sent” error away as well. Next we need to write our SQL query to get the data we would like from the database, namely the pilot roster. Create a function “get_pilot_roster” in your new model.

function get_pilot_roster()    {

}

Write the SQL query to get the data and place it inside your new function, using the TABLE_PREFIX constant to add the database table prefix to the table name. Just as a note, Codon automatically loads the database connection so you do not have to do it again within your model.

$query = "SELECT * FROM ".TABLE_PREFIX."pilots";

This query will get ALL the pilots from the table. If you want to get only active pilots we can add a WHERE command to the query to look for pilots that are marked active using the retired column.

$query = "SELECT * FROM ".TABLE_PREFIX."pilots WHERE retired = '0'";

Using the Codon DB class run the query and return the result in an array.

return DB::get_results($query);

Your complete RosterData.class.php file should look like this.

<?php
//file RosterData.class.php
class RosterData extends CodonData  {

    function get_pilot_roster()    {
        $query = "SELECT * FROM ".TABLE_PREFIX."pilots WHERE retired = '0'";
        return DB::get_results($query);
    }

}

Next, we will create our controller file, which will be the core of our new module and will direct all the action. Create a new folder in your /core/modules folder named Roster, again notice the capital R. In that folder create a new php file Roster.php and use it to extend the CodonModule object.

<?php

class Roster extends CodonModule    {

}

Now lets create our index function that will display the full roster page.

function index()    {

}

First we need to fill a variable with all the pilot data we want from the database to use in our final view using the data call we just built. We can use the Codon function SET.

$this->set('pilots', RosterData::get_pilot_roster());

Now we need to send all the data to a view file and display it to the user. We can simply use the Codon SHOW function to accomplish this, it will send the data you set to the ‘pilots’ variable along with it so it the data is available in our view when we get there.

$this->show('roster.tpl');

At this point your Roster.php file should look like this.

<?php
//file Roster.php
class Roster extends CodonModule    {

    function index()    {
       $this->set('pilots', RosterData::get_pilot_roster());
       $this->show('roster.tpl');
    }

}

Now we need to build a view file to display our final output in the browser, it can be a combination of php and html. We will build a very basic display here, you can add html structure to it as you would like, we will just make a simple list. Create our template file in your skin folder, we will use the default crystal skin at /lib/skins/crystal/. Name the file roster.tpl. We will take the $pilots variable that is loaded with our data and create a loop to just display the pilot’s names in a list.

//file roster.tpl
<ul>
<?php
    foreach($pilots as $pilot)    {
        echo '<li>'.$pilot->firstname.' '.$pilot->lastname.'</li>';
    }
?>
</ul>

A good tool to see what is available to you within the variable is to place a print_r or var_dump in the view files and run it this will show all the data that is in the variable and what you can use to build your display.

var_dump($pilots);
//or
print_r($pilots);

You can creative as you would like with the view file and the new pilot roster you have just built.

Posted in phpVMS | 1 Comment