Full Example

Full Example

The PHP module

<?php
/*
* Yap full example.
* This example shows:
*  - how to use the external file configuration
*  - how to set your extension class and how to write it
*  - how to enable/disable the delete link upon your condition
*/

// include the yap module and my extensions
include_once('CYap.inc');
include_once(
'pci_CYap_extension.php');

// setup the database connection. I do it here because
// I get that parameter from the application configuration.
$db_info=array('servername'     => $GLOBALS['DBSystem'],
               
'dbname'         => $GLOBALS['DBName'],
               
'user'           => $GLOBALS['DBUser'],
               
'password'       => $GLOBALS['DBPasswd'],               
               );
// Here I set to use the configuration file 'index_yap.cfg' and the
// language
$Show_info=array('cfgfile' => 'index_yap.cfg',
                 
'languagefile' => 'language.en',  
                 );

// Note: the parameters that you set here override the same parameter
// set from the configuration file.
$p=new CYap(array(), array(), $db_info, $Show_info, array());
// Show the page
$p->showpage();


/**
* This function enable the delete link, only if the user is the
* administrator (see the parameter 'deleteallow'. In this example
* I comment it becuase it requires some module from the application
* where I get this example.
* The $id parameter is the row's id.
*
*/
function MayIRemove($id)
{
// the real statement
// return($GLOBALS['auth']->IsAdmin());
// To keep the example working
return(true);
}
?>