#### cut and paste the following into a file for the class File ####
#### To auto-match the locations specified in the public file template, ####
#### save it to classes/data/.class.php ####
--------------------------------------------------------------------
array('template_test','another_table));
*
* the 'block_name_1' is used to identify the block of data on the template page.
* the array of table names is to get formatting data for any fields that need it. If your
* SQL gets data (via a join) from more than one table, list them all to get all formatting data.
*
* NB:: table names do not need the 'tbl_' prefix in this array - it is added during processing
*/
public $formatting_tables = array('item_list' => array(''),
'item_new' => array(''));
public $credentials_index = DB_CREDENTIALS_INDEX;
function __construct()
{
/**
* REQUIRED! DO NOT EDIT THIS FUNCTION
*/
$this->db = new PDO_connection($this->credentials_index); //create a database connection//
parent::__construct(); //### MUST CALL parent constructor ###//
}
function __destruct()
{
/**
* REQUIRED! DO NOT EDIT THIS FUNCTION
*/
unset($this->db);
}
public function list_items()
{
/**
* Create $data_sql (array) of block name used in template as array key, sql needed to fill in form fields.
* sql can return zero records and the form will be created with empty fields (good for 'add new' forms)
*/
if($this->pagination_available) //checks if the pagination class is included
{
/**
* If you want pagination of the recordset, you must include "SQL_CALC_FOUND_ROWS" AS the first
* item in the SELECT SQL statement and the code $limit_sql as the last item.
* NB:. There is no comma after "SQL_CALC_FOUND_ROWS" before the rest of the SQL select Items.
*/
pagination::$records_per_page = 10; //set if required, otherwise default of 10 is used
pagination::set_values();
$limit_sql = pagination::$recordset_limiter; //get sql limit code for below
}
$data_sql = array("item_list" => "SELECT SQL_CALC_FOUND_ROWS * FROM
tbl_ ORDER BY key_id" . $limit_sql);
/**
* Create the array of data used in button in this block
*/
$this->button_data['item_list'] = array("edit" => $this->lang['edit']." Item",
"reset" => $this->lang['reset'],
"update" => $this->lang['update']. " Items",
"delete" => $this->lang['delete']." Item",
"are_you_sure" => $this->lang['are_you_sure']
);
/**
* Run the 'get_database_data()' function to get the db data & set the page template data
*/
$this->get_database_data($data_sql); //which also sets the template data
/**
* define any javascript that needs to go on the page: The default field are:
* 'header_block' - script that is inserted between the
html tags.
* 'body_event' - function code inserted in the tag - EG
* 'footer_block' - script that inserted at the end of the page.
*
* Other javascript blocks may be defined - don't forget to add [javascript.newBlockName] placeholders
* in the HTML template page.
*/
$this->javascript_data['header_block'] = <<
//
JAVASCRIPT_BLOCK;
}// end of list_units
public function new_item()
{
/**
* Create $data_sql (array) of block name used in template as array key, sql needed to fill in form fields.
* sql can return zero records and the form will be created with empty fields (good for 'add new' forms)
*/
$data_sql = array("item_new" => "SELECT * FROM tbl_ WHERE 1 = 0 ");
/**
* Create the array of data used in button in this block
*/
$this->button_data['item_new'] = array("insert" => $this->lang['insert']." Item",
"reset" => $this->lang['reset']);
/**
* Run the 'get_database_data()' function to get the db data & set the page template data
*/
$this->get_database_data($data_sql); //which also sets the template data
/**
* No specific javascript defined for this block
*/
}
public function custom_output()
{
/**
* Example of a full override function, doing whatever the hell you like
* , and even being driven by the data in the database.
*/
$url = 'http://wordpress.org/news/feed/';
$url = 'http://feeds.bbci.co.uk/news/rss.xml';
$arg_list = current(func_get_args());
/**
* $arg_list is an array with the following key / value pairs
* These may be used in this function to get the necessary data for the required output
* Array
* (
* [key_id]
* [field_name]
* [field_type]
* [lookup_type]
* [lookup_source]
* [field_size]
* [lower_constraint]
* [upper_constraint]
* [mandatory]
* [field_javascript]
* [override_function]
* [field_label]
* [hint]
* [error_message]
* [field_value]
* )
*/
// do stuff to populate $tmp with the value you wish to return for the 'custom_output' field
return $tmp;
}
public function onload_function($BlockName,&$CurrRec,$RecNum)
{
//$BlockName : name of the block that calls the function (read only)
//$CurrRec : array that contains columns of the current record (read/write)
//$RecNum : number of the current record (read only)
/**
* use any value from from the block data (passed as an array &$CurrRec)
* and run any process / database interaction / formatting on it you wish.
* Load any results back into the current record as
*
* $CurrRec['php_function'][{any name}] to be included on the page.
*
* Thus you could query the database using $CurrRec['key_id']['field_value']
* and then populate:
*
* $CurrRec['php_function']['invoice_list']
*
* as a hyperlinked unordered list.
*
* Simply then include the tag on the page as [{block_name}.php_function.invoice_list]
* EG [item_list.php_function.invoice_list]
*
*
*/
$CurrRec['php_function']['level'] = 'excellent';
}
/**
* ###############################################################
* Action (submit) buttons in forms must be named
*
* btn_update
* btn_insert
* btn_delete
*
* for this system to automagically work.
* If you have many submit buttons ensure they have unique IDs!
*
* Here is where we write the functions to perform database / data processing
* The 3 standard functions MUST be named:
*
* db_update()
* db_insert()
* db_delete($key_id)
*
* it is helpful to add values to $this->extra_page_fields['user_message'] confirming the action
* that will be displayed to the user in the [page.user_message] tag.
*
* ##################################################################
*
*/
protected function db_update()
{
//UPDATE
$sql = "UPDATE tbl_ SET x = :x ,
y = :y, z = :z WHERE key_id = :key_id";
$data_obj = new pdo_query($this->db);
$data_obj->prepare_query($sql);
$data_obj->start_transaction();
for($i=0;$iposted_data['item_list:key_id']);$i++)
{
$data = array("x" => $this->posted_data['item_list:x'][$i],
"y" => mydate::set_sql_date($this->posted_data['item_list:ty'][$i]),
"z" => $this->posted_data['item_list:z'][$i],
"key_id" => $this->posted_data['item_list:key_id'][$i]);
$data_obj->execute_query($data);
}
$result = $data_obj->commit_transaction();
unset($data_obj);
if($result){
//Success
$this->extra_page_fields['user_message'].= "".$this->lang['update_success']."
";
}else{
//failure
$this->extra_page_fields['user_message'].= "".$this->lang['update_failure']."
";
}
}
protected function db_insert()
{
//INSERT NEW
$sql = "INSERT INTO tbl_ (x, y, z)
VALUES (:x, :y, :z)";
$data_obj = new pdo_query($this->db);
$data_obj->prepare_query($sql);
$data = array("x" => $this->posted_data['item_new:x'][0],
"y" => $this->posted_data['item_new:y'][0],
"z" => $this->posted_data['item_new:z'][0]);
$result = $data_obj->execute_query($data);
$data_obj->get_last_insert_id();
$item_id = $data_obj->last_insert_id;
/**
* Do Extra stuff in other tables using new item id?
*/
unset($data_obj);
if($result){
//Success
$this->extra_page_fields['user_message'].= "".$this->lang['insert_success']."
";
}else{
//failure
$this->extra_page_fields['user_message'].= "".$this->lang['insert_failure']."
";
}
}
protected function db_delete($key_id)
{
//delete
$sql = "DELETE FROM tbl_ WHERE key_id = :key_id";
$data_obj = new pdo_query($this->db);
$data_obj->prepare_query($sql);
$data = array("key_id" => $key_id);
$result = $data_obj->execute_query($data);
unset($data_obj);
if($result){
//Success
$this->extra_page_fields['user_message'].= "".$this->lang['delete_success']."
";
}else{
//failure
$this->extra_page_fields['user_message'].= "".$this->lang['delete_failure']."
";
}
}
}
?>