pninit.php
Code
function Rules_init()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list [17]($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// It's good practice to name the table and column definitions you
// are getting - $table and $column don't cut it in more complex
// modules
$rulestable = $pntable['rules'];
$rulescolumn = &$pntable['rules_column'];
// Create the table - the formatting here is not mandatory, but it does
// make the SQL statement relatively easy to read. Also, separating out
// the SQL statement from the Execute() command allows for simpler
// debug operation if it is ever needed
$sql = "CREATE TABLE $rulestable (
$rulescolumn[rid] int(10) NOT NULL auto_increment,
$rulescolumn[rulenumber] int(3) NOT NULL default 0,
$rulescolumn[rulecategory] int(2) NOT NULL default 0,
$rulescolumn[ruletext] blob NOT NULL,
PRIMARY KEY($rulescolumn[rid]))";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _CREATETABLEFAILED);
return false;
}
// Set up for second table
$rulescategorytable = $pntable['rules_categories'];
$rulescategorycolumn = &$pntable['rules_categories_column'];
//Create the second table
$sql = "CREATE TABLE $rulescategorytable (
$rulescategorycolumn[cid] int(10) NOT NULL auto_increment,
$rulescategorycolumn[catnumber] int(3) NOT NULL default 0,
$rulescategorycolumn[catname] varchar(100) NOT NULL default '',
PRIMARY KEY($rulescategorycolumn[cid]))";
$dbconn->Execute($sql);
//Check for an error with the database code, and if so set an
appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
//pnSessionSetVar('errormsg', _CREATETABLEFAILED);
//return false;
}
// Initialisation successful
return true;
}
/**
* upgrade the template module from an old version
* This function can be called multiple times
*/
function Rules_upgrade($oldversion)
{
// Upgrade dependent on old version number
switch($oldversion) {
case 1.0:
// Code to upgrade from version 1.0 goes here
break;
case 2.0:
// Code to upgrade from version 2.0 goes here
break;
}
// Update successful
return true;
}
/**
* delete the template module
* This function is only ever called once during the lifetime of a particular
* module instance
*/
function Rules_delete()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list [18]($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// Drop the table - for such a simple command the advantages of separating
// out the SQL statement from the Execute() command are minimal, but as
// this has been done elsewhere it makes sense to stick to a single method
$sql = "DROP TABLE $pntable[rules]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Drop the second table
$sql = "DROP TABLE $pntable[rules_categories]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Deletion successful
return true;
}
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list [17]($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// It's good practice to name the table and column definitions you
// are getting - $table and $column don't cut it in more complex
// modules
$rulestable = $pntable['rules'];
$rulescolumn = &$pntable['rules_column'];
// Create the table - the formatting here is not mandatory, but it does
// make the SQL statement relatively easy to read. Also, separating out
// the SQL statement from the Execute() command allows for simpler
// debug operation if it is ever needed
$sql = "CREATE TABLE $rulestable (
$rulescolumn[rid] int(10) NOT NULL auto_increment,
$rulescolumn[rulenumber] int(3) NOT NULL default 0,
$rulescolumn[rulecategory] int(2) NOT NULL default 0,
$rulescolumn[ruletext] blob NOT NULL,
PRIMARY KEY($rulescolumn[rid]))";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _CREATETABLEFAILED);
return false;
}
// Set up for second table
$rulescategorytable = $pntable['rules_categories'];
$rulescategorycolumn = &$pntable['rules_categories_column'];
//Create the second table
$sql = "CREATE TABLE $rulescategorytable (
$rulescategorycolumn[cid] int(10) NOT NULL auto_increment,
$rulescategorycolumn[catnumber] int(3) NOT NULL default 0,
$rulescategorycolumn[catname] varchar(100) NOT NULL default '',
PRIMARY KEY($rulescategorycolumn[cid]))";
$dbconn->Execute($sql);
//Check for an error with the database code, and if so set an
appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
//pnSessionSetVar('errormsg', _CREATETABLEFAILED);
//return false;
}
// Initialisation successful
return true;
}
/**
* upgrade the template module from an old version
* This function can be called multiple times
*/
function Rules_upgrade($oldversion)
{
// Upgrade dependent on old version number
switch($oldversion) {
case 1.0:
// Code to upgrade from version 1.0 goes here
break;
case 2.0:
// Code to upgrade from version 2.0 goes here
break;
}
// Update successful
return true;
}
/**
* delete the template module
* This function is only ever called once during the lifetime of a particular
* module instance
*/
function Rules_delete()
{
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn()
// we currently just want the first item, which is the official
// database handle. For pnDBGetTables() we want to keep the entire
// tables array together for easy reference later on
list [18]($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
// Drop the table - for such a simple command the advantages of separating
// out the SQL statement from the Execute() command are minimal, but as
// this has been done elsewhere it makes sense to stick to a single method
$sql = "DROP TABLE $pntable[rules]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Drop the second table
$sql = "DROP TABLE $pntable[rules_categories]";
$dbconn->Execute($sql);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
// Report failed deletion attempt
return false;
}
// Deletion successful
return true;
}
pntables.php
Code
<?php
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WIthOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Carl Uussalu
// Purpose of file: Table functions for rules module
// -
/**
* This function is called internally by the core whenever the module is
* loaded. It adds in the information
*/
function Rules_pntables()
{
// Initialise table array
$pntable = array [19]();
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules';
// Set the table name
$pntable['rules'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_column'] = array [20]('rid' => $rules . '.pn_rid',
'rulenumber' => $rules . '.pn_rulenumber',
'rulecategory' => $rules . '.pn_rulecategory',
'ruletext' => $rules . '.pn_ruletext');
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules_categories';
// Set the table name
$pntable['rules_categories'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_categories_column'] = array [21]('cid' => $rules . '.pn_cid',
'catnumber' => $rules . '.pn_catnumber',
'catname' => $rules . '.pn_catname');
// Return the table information
return $pntable;
}
?>
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WIthOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Carl Uussalu
// Purpose of file: Table functions for rules module
// -
/**
* This function is called internally by the core whenever the module is
* loaded. It adds in the information
*/
function Rules_pntables()
{
// Initialise table array
$pntable = array [19]();
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules';
// Set the table name
$pntable['rules'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_column'] = array [20]('rid' => $rules . '.pn_rid',
'rulenumber' => $rules . '.pn_rulenumber',
'rulecategory' => $rules . '.pn_rulecategory',
'ruletext' => $rules . '.pn_ruletext');
// Get the name for the template item table. This is not necessary
// but helps in the following statements and keeps them readable
$rules= pnConfigGetVar('prefix') . '_rules_categories';
// Set the table name
$pntable['rules_categories'] = $rules;
// Set the column names. Note that the array has been formatted
// on-screen to be very easy to read by a user.
$pntable['rules_categories_column'] = array [21]('cid' => $rules . '.pn_cid',
'catnumber' => $rules . '.pn_catnumber',
'catname' => $rules . '.pn_catname');
// Return the table information
return $pntable;
}
?>
