Full Example

Full Example

The Yap extensions module

<?php

//*******************************************************************************************
/*
* pci_CYap_extension.php
* $Header$
* CYap class extensions used by PcInventory
*/



//*******************************************************************************************
/*
* CYap_MoveToPage customization.
* This class shows the link to skip forward or backward. In my application I want use
* some pictures instead of the text link. So I extended the base class and set Yap
* to use my new class by the parameter 'skippageclass'
*/
class Pci_CYap_MoveToPage  extends CYap_MoveToPage
{
/**
* Start the class.
* @param string $Lang, Language file
*/    
function Pci_CYap_MoveToPage($Lang)
{
parent::CYap_MoveToPage($Lang);
}

/**
* This function draw the box and the links. It accepts one parameter
* That parameter is an associative array. Each index is one link and the value is
* the new page.
*/
function Draw($LinkTbl)
{

echo
"
<br>
<table border=0 cellpadding=0 cellspacing=0 align=center>\n
      <tr class=navigator><td>"
;

if(
array_key_exists('FirstPage',$LinkTbl))
  { echo
"<a class=navigator href=".$LinkTbl['FirstPage']."><img src='images/inizio.gif' border='0' onMouseOver=\"YapToolTip('First page')\" onMouseOut='YapToolTip()'></a>"; }
else           
  { echo
"<img src='images/empty.gif' border='0'>"; }
echo
"</td><td>";

if(
array_key_exists('PrevPage',$LinkTbl))
  { echo
"<a class=navigator href=".$LinkTbl['PrevPage']."><img src='images/indietro.gif' border='0' onMouseOver=\"YapToolTip('Previous page')\" onMouseOut='YapToolTip()'></a>"; }
else           
  { echo
"<img src='images/empty.gif' border='0'>"; }
echo
"</td><td>";

echo
"<a class=navigator  href=".$LinkTbl['Exit']."><img src='images/uscita.gif' border='0' onMouseOver=\"YapToolTip('Exit')\" onMouseOut='YapToolTip()'></a>";
echo
"</td><td>";

// In detailmode I give the link to the 'normal' mode
if(array_key_exists('DetailMode',$LinkTbl))
  {
  echo
"<a class=navigator href=".$LinkTbl['DetailMode']."><img src='images/tabella.gif' border='0' onMouseOver=\"YapToolTip('Return to the table')\" onMouseOut='YapToolTip()'></a>";
  }
else           
  { echo
"<img src='images/empty.gif' border='0'>"; }
echo
"</td><td>";
  
if(
array_key_exists('NextPage',$LinkTbl))
  { echo
"<a class=navigator href=".$LinkTbl['NextPage']."><img src='images/avanti.gif' border='0' onMouseOver=\"YapToolTip('Next page')\" onMouseOut='YapToolTip()'></a>"; }
else           
  { echo
"<img src='images/empty.gif' border='0'>"; }
echo
"</td><td>";

if(
array_key_exists('LastPage',$LinkTbl))
  { echo
"<a class=navigator href=".$LinkTbl['LastPage']."><img src='images/fine.gif' border='0' onMouseOver=\"YapToolTip('Last page')\" onMouseOut='YapToolTip()'></a>"; }
else         
  { echo
"<img src='images/empty.gif' border='0'>"; }
echo
"</td>\n</tr></table>";   
}
}

//*******************************************************************************************
/**
* draw the table that allows to jump to the page number x
*/
class Pci_CYap_PageNumber extends CYap_PageNumber
{
/**
* Start the class.
* @param string $Lang, Language file
*/    
function Pci_CYap_PageNumber($Lang)
{
parent::CYap_PageNumber($Lang);
}

function
Draw($min,$max,$current)
{
// Open the tabel
echo "<table border=0 cellpadding=0 cellspacing=0 align=center>\n
      <tr class=navigator style='width:192px'><td style='width:192px'><p class=navigator>"
.$this->Lang['GotoPage'].":  ";

// Page number loop
for($i=$min;$i<$max+1;$i++)
   {
   if(
$i==$current)
     
// Current page
     
echo "[$i]  ";
   else
     echo
"<a href=".$_SERVER["PHP_SELF"]."?daform=1&pag=".$i.">".$i."</a>  ";
   }

echo
"</p></td>\n</tr></table>";    
}

}

/*******************************************************************************************
* This is the class that shows the full table rows. Again I want the detail/modify/delete
* links as picture.
*/
class Pci_CYap_TableView extends CYap_TableView
{

function
Pci_CYap_TableView($Lang)
{
parent::CYap_TableView($Lang);    
}   

/**
* The row's cells that contains the detail/modify/delete links are printed out by by an own function
* the SpecialCell.
* The function is called one time for each link.
* This functions takes 3 parameters:
* @param string $link http link to the new page
* @param string $type what kind of link is to be shown. The values are: MODIFY (the modify link),
*                     'DELETE' (the delete link), 'DETAIL' (... the detail link).
* @param integer $offset which column should be used to show the link.
*/
function SpecialCell($link,$type,$offset=-1)
{
if(
$link!='')
  {    
  switch(
$type)
    {
    case
'MODIFY':    
         
$text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipModify'].'\')" onMouseOut="YapToolTip()" ><img src=\'images/modify.gif\' border=0></a>';
         break;
    case
'DELETE':    
         
$text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipRemove'].'\')" onMouseOut="YapToolTip()" ><img src=\'images/delete.gif\' border=0></a>';
         break;     
    case
'DETAIL':    
         
$text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipDetail'].'\')" onMouseOut="YapToolTip()" ><img src=\'images/detail.gif\' border=0></a>';
         break;                           
     }      
  }
else
  
$text='&nbsp;';       
$this->Cell($text,$type,$offset);     
}

/**
* Add a new row that contains only one cell: the new row link
* @param string $link the link code to write into the cell
* @access public
*/
function AddRowCell($link)
{
// if($this->PendingRow)
  
$this->NewRow();
$col=99;
$col=($this->colSpecial['MODIFY']<$this->colSpecial['DELETE'])?$this->colSpecial['MODIFY']:$this->colSpecial['DELETE'];
$col=($col<$this->colSpecial['DETAIL'])?$col:$this->colSpecial['DETAIL'];
$col=($col==99)?0:$col;
$text='<a href='.$link.' onMouseOver="YapToolTip(\''.$this->Lang['TipNewRow'].'\')" onMouseOut="YapToolTip()" ><img src=\'images/addrow.gif\' border=0></a>';
$this->Cell($text,'ADDROW',$col);      
}
}

/*******************************************************************************************
* This class build the HTML code to made the modify/add form.
* In this case I made the ok/abort button as picture.
*/
class Pci_CYap_form extends CYap_form {

function
Pci_CYap_form($Controls,$modify_info,$LangName)
{
parent::CYap_form($Controls,$modify_info,$LangName);    
}

/**
* Build the HTMl required to draw the form
* @access public
* @param boolean $Add Am I add or modify the row?
* @param String $KeyValue Value of the index key for the row to modify
*/
function MakeForm($Add,$KeyValue,$WrongFields,$cmdAbort)
{
// show the box
$msg='
      <table border=1 cellpadding=0 cellspacing=0 align=center>
      <tr><td>'
;

$msg.='</td></tr>
     <tr><td>
     <form action='
.$_SERVER['PHP_SELF'].' method=post >';
if(
$Add)
   
$msg.='<input type=hidden name=cmd value=ea>';
else
   
$msg.='<input type=hidden name=cmd value=em>';
$msg.='<input type=hidden name=daform value=1>';
if(!
$Add)
   
$msg.='<input type=hidden name=id value=\''.htmlentities($KeyValue,ENT_QUOTES).'\'>';

$js='';   // javascript code
foreach($this->Controls as $Key => $obj)
    {
    
$js.=$obj->GetJsCode();        
   
// I don't ask the autoincrement field, and the key field if i'm updating the row
   
if((($Key!=$this->modify_info['keyfield']&&!$Add)||$Add)
      && !
$obj->GetInfo('autoincrement'))
     {
     
//var_dump($Key);
     
$msg.='<tr><td>'.$Key.'</td><td>';
     
$msg.=$obj->Draw(false);     
     
// Show some text if the current field has a wrong value (i.e from a previous input form)
     
if(array_key_exists($Key,$WrongFields))
       
$msg.=$WrongFields[$Key];
     
$msg.='</td><td>'.$obj->GetInfo('type').'</td></tr>';
     }
   }

$msg.='<tr><td>&nbsp;</td><td>';
$msg.=$this->_SubmitButton();
$msg.=$this->_AbortButton($cmdAbort);
$msg.='</form>
     </td></tr>
     </table>'
;
$msg.='<script>'.$js.'</script>';
$msgbox=new CPciBox($msg);
$msgbox->Show();
}

/**
* Submit button
*/
function _SubmitButton()
{
    return(
'<button onclick=\'javascript:this.form.submit\' style=\'background-color:#E8F2DE\'><img src=images/ok.gif></button>');     
}

/**
* Abort button
* @param string $cmdAbort link to the page to call if the user clicks the button.
*/

function _AbortButton($cmdAbort)
{
    return(
'<button  onclick="javascript:this.form.elements[\'cmd\'].value=\'\';window.location.href=\''.$cmdAbort.'\'" style=\'background-color:#E8F2DE\'><img src=images/abort.gif></button>');    
}

}
   

?>