PHP Classes
elePHPant
Icontem

File: test4.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Andrioli Darvin  >  Yet Another Pager  >  test4.php  >  Download  
File: test4.php
Role: Example script
Content type: text/plain
Description: Example
Class: Yet Another Pager
Database row pager with edit and search support
Author: By
Last change: Fix the include statements
Date: 10 years ago
Size: 4,637 bytes
 

Contents

Class file image Download
<?php
/*
 * test1.php
 * Module yap testing program 4 (calback function)
 * $Header: d:/cvs/classistd/yap/test4.php,v 1.3 2004/04/29 20:56:42 Administrator Exp $
 */


/*
 * In this example I allow to modify only the row with id = 6.
 * The field id is specified as row key into modify_info array
 * The parameter is the value of key field
 */
function Allow($ItemKey)
{
return(
$ItemKey==6);
}
// allow to remove only the item with id=7
function RemoveId7($ItemKey)
{
return(
$ItemKey==7);
}
/*
 * Check value callback function.
 * The following function is an example how to check the fields
 * during form processing
 * before write them to the databse.
 * If the function return false, the module show the form again
 * $InputFields is an array containing all fields from the form
 * $FieldName: name of the field to check
 * You may set the function to check many fileds. The function is
 * called many times as the numeber the fields to check.
 * In this example I set to call the following function only to
 * check the field 'errno', so when the function is called
 * $FieldName is = 'errno'.
 */
function CheckField($InputFields,$FieldName)
{
$ret=($InputFields[$FieldName]==0)?true:false;
return(
$ret);
}

function
CheckText($InputFields,$FieldName)
{
return(
true);
}

/*
 * Function called for each row while the module shows the table. It is usefull
 * to add custom link to the table
 * $RowData is an array containing all data about the current row
 * To return to the current page call this script (test4.php) without any parameter
 * The module saves its information into session.
 */
function CustomLink($RowData)
{
echo
"<TD><a href='dummypage1.php'>CustomLink1</a></TD>";
echo
"<TD><a href='dummypage2.php'>CustomLink2</a></TD>";
}

include_once(
'CYapBox.php');
include_once(
'CYap.inc');
session_start('test');
echo
'<html><body>';
$SelectQuery='select id, DEvent, errno, text, filename, line from dlog where ';
$SelectCount='select count(*) from dlog where ';
//Parameters setup
//Db Connection
$db_info=array('servername' => 'localhost',
              
'dbname' => 'log',
              
'user' => 'root',
              
'password' => '',
              
'selectquery' => $SelectQuery,
              
'selectcount' => $SelectCount,
              
'orderfield' => 'id',
              
'orderdirection' => 'A',
              
'NeedOpenDb' => false
              
);
// Field to use to perform sesrchs
$Search_field=array(array('description' => 'Event Date',
                         
'fieldname' => 'DEvent',
                         
'type' => 'A',
                         
'size' => 14,
                         
'useregex' => 1 ),
                    array(
'description' => 'Error Code',
                         
'fieldname' => 'errno',
                         
'type' => 'N'),
                    );
// Fields to shows inside the table
$Show_field=array(array('fieldname' => 'id',
                       
'header' => 'Id'),
                  array(
'fieldname' => 'DEvent',
                       
'header' => 'Event Date'),
                  array(
'fieldname' => 'errno',
                       
'header' => 'Error Code'),
                  array(
'fieldname' => 'text',
                       
'header' => 'Description'),
                  );
// I don't setup the detail mode, the add/modify/delete row functions
$Show_info=array('prefix' => 'tst4',
                
'showdethref' => true,
                
'rowcallback' => 'CustomLink',
                 );
$Modify_info=array(
                
'table' => 'dlog',
                
'keyfield' => 'id',
                
'showdelete' => true,
                
'showmodify' => true,
                
'showadd' => true,
                 
// callback function to allow the
                  // modify function
                
'modifyallow' => 'Allow',
                 
// callback function to allow the
                  // delete function
                
'deleteallow' => 'RemoveId7',
                
// set the callback function to check the contents
                 // of errno and text
                
'fieldvalidator' => array(
                                         
'errno' => 'CheckField',
                                         
'text' => 'CheckText'
                                         
),
                  );


$p=new CYap($Search_field, $Show_field, $db_info, $Show_info, $Modify_info);
$p->showpage();
echo
'</body></html>';
?>