Adding on to or extending phpBugTracker should be easy for those with a knowledge of PHP and SQL. New developers are always welcome to join the project at http://www.sourceforge.net/projects/phpbt, or to simply submit patches, bug reports, or feature requests.
PHPlib can be found at http://phplib.sourceforge.net. It provides the database abstraction layer, html templates, and session and authentication management.
Instead of using PHP's database functions directly, interactions are done via database objects, which extend PHPlib's DB_Sql class.
The global variable $q is available as an instance of the class dbclass. This class adds two functions to the DB_Sql class, grab() and grab_field(). If they are called with an argument, the argument is passed as a query to the database and the results are returned from that query. If no argument is passed, they return results from the previous call to query(). Here are some examples:
Example 3-1. Using the database class
// Grab one field from one record in the database $user_email = $q->grab_field("select email from ".TBL_AUTH_USER." where user_id = 1"); echo $user_email; // Stuff all the fields from a user record into an array $user_info = $q->grab("select * from ".TBL_AUTH_USER." where user_id = 1"); echo $user_info['email']; // Work with a set of records $q->query("select * from ".TBL_AUTH_USER); while ($row = $q->grab()) { echo $row['email'].'<br>'; } |
Instead of outputting HTML from the scripts, templates are used to separate the code from the HTML. The templates contain tokens that are replaced by the scripts with values. The general process for using templates is as follows:
Example 3-2. Using the template class
// Set up the file to be used $t->set_file('content', 'bugdisplay.html'); // Substitute the tokens with data $t->set_var(array( 'title' => $buginfo['title'], 'description' => $buginfo['description'], .... )); // Parse the template and print it out (inside a wrap template) $t->pparse('main', array('content', 'wrap', 'main')); |
The session start and authentication code is included in include.php. The session is started by a call to page_open(), with the arguments specifying which session elements should be created. phpBugTracker uses the Auth and Perm classes from PHPlib in addition to the base Session class.
Session. Session variables, or variables that should be retained from page to page, are set via the $sess variable, which is an instantiation of the usess class. You can register a session variable with $sess->register('varname'). When registering, make sure you don't include the $ with varname. This variable will now be available in the global scope until the session is destroyed by the user closing the browser.
Auth. The login handler is located near the end of include.php. Via the uath class, the global variable $u is set to the user id of the user if logged in, or to 'nobody' if not logged in. This variable should be used as the CreatedBy or LastModifiedBy value for database inserts and updates.
Perm. There are two types of checks that are made in phpBugTracker: permission and group membership. These checks can be made two different ways -- one that exits and displays an access denied message (useful for protecting an entire page) or one that returns whether the user passed the check (useful for determining whether to display a piece of information).
Example 3-3. Permission and Group Checking
// Non-failing checks if ($perm->have_perm('EditBug')) { echo 'You can edit a bug!'; } if ($perm->in_group('User')) { echo 'You are logged in and belong to the User group'; } // Failing checks -- the script exits at this point if the check fails $perm->check('Admin'); $perm->check_group('Developer'); |
This section will not cover the usage of JpGraph in any detail, since it is not an integral part of phpBugTracker. Developers who are interested in using this class for generating bug reports or charting activity can see images.php for an example and are encouraged to visit JpGraph's web site at http://www.aditus.nu/jpgraph.