function iesdc_prensa_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
$dbconn =& pnDBGetConn(true);
$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
$prensatable = &$pntable['iesdc_prensa'];
$prensacolumn = &$pntable['iesdc_prensa_column'];
// tabla creada?
$sql = "SELECT COUNT(1) FROM $prensatable";
$dbconn->Execute($sql);
if ($dbconn->ErrorNo() != 0) {
//No existe->la creamos
$sql = "CREATE TABLE `iw_nuke_iesdc_prensa` (
`codi` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`prensa` VARCHAR( 80 ) NOT NULL ,
`url_prensa` VARCHAR( 250 ) NOT NULL ,
`imagen` VARCHAR( 50 ) NOT NULL)";
$dbconn->Execute($sql);
if ($dbconn->ErrorNo() != 0) {
pnSessionSetVar('errormsg', _DBCREATETABLEERROR);
return false;
}
}
// Initialisation successful
return true;
}
/**
* upgrade the prensa module from an old version
*
* This function can be called multiple times
* This function MUST exist in the pninit file for a module
*
* @author Jim McDonald
* @return bool true on success, false otherwise
*/
function iesdc_prensa_upgrade($oldversion)
{
// Update successful
return true;
}
/**
* delete the prensa module
*
* This function is only ever called once during the lifetime of a particular
* module instance
* This function MUST exist in the pninit file for a module
*
* @author Jim McDonald
* @return bool true on success, false otherwise
*/
function iesdc_prensa_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
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
$Exampletable = &$pntable['iesdc_prensa'];
// New Object DataDictionary
$dict = &NewDataDictionary($dbconn);
$sqlarray = $dict->DropTableSQL($Exampletable);
// Check for an error with the database code, and if so set an
// appropriate error message and return
if ($dict->ExecuteSQLArray($sqlarray) != 2) {
pnSessionSetVar('errormsg', _EXAMPLEDROPTABLEFAILED);
// Report failed deletion attempt
return false;
}
// Delete any module variables
pnModDelVar('iesdc_prensa');
// Deletion successful
return true;
}