PN provides an interface to initialise, activate/deactivate or remove a module (it's SQL tables) and the files that contribute to this are: "pntables.php" et "pninit.php".
In this file, there is a function that fills in a PN core array called "pntable" with the name of all the tables used in a module and their fields
(example below: table "pn_joinproject_members" with 4 fields)
function joinproject_pntables() {
// Initialise table array
$pntable = array();
// Get the name for the template item table.
$members = pnConfigGetVar('prefix') . '_joinproject_members';
// Set the table name
$pntable['joinproject_members'] = $members;
// Set the column names.
$pntable['joinproject_members_column'] =
array('memberid' => $members . '.memberid',
'projid' => $members . '.projid',
'membername' => $members . '.membername',
'accepted' => $members . '.accepted');
// Return the table information
return $pntable; }
There are 2 functions : init() and delete()
Inside init() we create the tables needed by the module inside the PN database, by calling simple SQL queries
function joinproject_init() {
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
$memberstable = $pntable['joinproject_members'];
$memberscolumn = &$pntable['joinproject_members_column'];
$sql1 = "CREATE TABLE $memberstable (
$memberscolumn[memberid] tinyint unsigned NOT NULL auto_increment,
$memberscolumn[projid] tinyint unsigned NOT NULL default '',
$memberscolumn[membername] varchar(255) NOT NULL default '',
$memberscolumn[accepted] tinyint(1) NOT NULL default '0',
PRIMARY KEY(memberid))";
$dbconn->Execute($sql1);
// 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;
}
}
Inside delete() we delete the SQL tables, that are connected to the module, from the PN database, applying the SQL query: "DROP TABLE"
function joinproject_delete()
{
list($dbconn) = pnDBGetConn();
$pntable = pnDBGetTables();
$sql1 = "DROP TABLE $pntable[joinproject_members]";
$dbconn->Execute($sql1);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _DROPTABLEFAILED);
return false;
}
// Deletion successful
return true;
}