<?php
/**
*******************************************************************************
FiForms -- A collection of PHP classes designed
to facilitate rapid development of web-database software
Copyright (C) 2003-2008 Daniel McFeeters
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The original author of this library can be contacted at the following
address:
Daniel McFeeters
182 Baker Rd.
Faubush, KY 42544-6526
email:databases [at] fiforms [dot] org
http://www.fiforms.org/
Project Started May 4, 2003
*******************************************************************************
FiForms_iFormControl.inc.php
iFormControl is an iContainer which generates the navigation controls on a form
*******************************************************************************
**/
if(!isset($FIFORMS_CONFIG))
{
die('No Configuration found. Did you perhaps call an include file' .
' directly instead of calling it as part of the FiForms' .
' application?');
}
require_once("FiForms_iContainer.inc.php");
/* ?><code><?php */
class iFormControl extends iContainer
{
var $boundForm; //the form this control is on
var $htmlClass; //class to use for HTML elements
function buildURLs()
// Build the URLs for the navigation links
{
$myURL = $this->buildMyURL($this->boundForm->excludeLinkTerms);
$this->myURL = $myURL;
$cur = $this->boundForm->currentRec;
$lim = $this->boundForm->recordLimit;
$max = $this->boundForm->maxRec;
if(trim($this->boundForm->currentRec." ") == "new")
// this is a new record
{
$this->nextRec = $myURL."currentRec=new";
$this->previousRec = $myURL."currentRec=0";
}
else
{
// calculate the current record offsets
// for the next and previous links
$nxt = $cur - ($cur % $lim)+$lim;
if($max && $nxt > $max)
{
$nxt = $max - ($max % $lim);
}
$this->nextRec = $myURL."currentRec=".$nxt;
if($cur < $lim)
{
$cur = $lim;
}
$prv = ($cur-($cur % $lim));
if($prv == $cur)
{
$prv -= $lim;
}
if($prv < 0)
{
$prv = 0;
}
$this->previousRec = $myURL."currentRec=".$prv;
} // if not new record
// Set all remaining URLs for navigation and actions
$lst = ($this->boundForm->maxRec -
($this->boundForm->maxRec % $this->boundForm->recordLimit));
if($lst == $this->boundForm->maxRec)
{
$lst -= $this->boundForm->recordLimit;
}
$this->lastRec = $myURL."currentRec=".($max-1);
$this->firstRec = $myURL."currentRec=0";
$this->newRec = $this->buildMyURL(array_merge($this->boundForm->excludeLinkTerms,array('sheetView')))."currentRec=new";
$this->deleteRec = $myURL."currentRec=".
$this->boundForm->currentRec.
"&deleteRec=confirm&PRIMARYKEYS=".
$this->boundForm->primaryKeyFilter;
if($this->boundForm->currentRec === "new")
{
$this->sheetV = $myURL."sheetView=YES";
}
else
{
$this->sheetV = $myURL."currentRec=".
$this->boundForm->currentRec."&sheetView=YES";
}
$this->myURL = $myURL;
} // function buildURLs
function drawHead()
{
return("<div class=\"$this->htmlClass\"><table><tr>\n");
}
function drawBody()
{
return("<td>$this->drawInput</td>\n");
}
function drawFoot()
{
return('</tr></table></div>');
}
function buildDeleteConfirm()
{
$this->inputs["_DELETECONFIRM"] =
new iHidden("_DELETECONFIRM","yes");
$this->inputs["_DELETECONFIRM"]->value = "yes";
$this->inputs["_ConfirmText"] =
new iROText("Are you sure you want to delete this record?");
$this->readOnly = TRUE;
$this->inputs["submit"] = new iSubmit("Yes (Delete Record)");
$this->inputs["cancel"] = new iLink($this->myURL."currentRec=".
$boundForm->currentRec,"No (Cancel)");
$this->inputs["cancel"]->title = "Cancel the Delete";
} // function buildDeleteConfirm
function createNavInputs()
{
$bType = $this->icons->buttonType;
if(!$this->boundForm->noNavigation)
{
$navback = $this->boundForm->currentRec >=
$this->boundForm->recordLimit;
$navforward = $this->boundForm->currentRec !==
"new" && $this->boundForm->maxRec !== "0" &&
(!$this->boundForm->maxRec || $this->boundForm->currentRec +
$this->boundForm->recordLimit < $this->boundForm->maxRec);
$newrec = $this->boundForm->currentRec === "new";
if($newrec)
{
$this->inputs["firstRec"] =
new iLink($this->firstRec,$this->icons->first,"","",$bType);
$this->inputs["firstRec"]->title = "Go to First Record (Ctrl-M)";
//print_r($this->inputs["firstRec"]);
//die();
$this->inputs["firstRec"]->staticValue = true;
$this->inputs["previousRec"] =
new iLink("#",$this->icons->previousDisabled,"","",$bType);
$this->inputs["previousRec"]->title = "Go to Previous Record (Ctrl-Comma)";
}
elseif($navback)
{
$this->inputs["firstRec"] =
new iLink($this->firstRec,$this->icons->first,"","",$bType);
$this->inputs["firstRec"]->title = "Go to First Record (Ctrl-M)";
$this->inputs["firstRec"]->staticValue = true;
$this->inputs["previousRec"] =
new iLink($this->previousRec,$this->icons->previous,"","",$bType);
$this->inputs["previousRec"]->title = "Go to Previous Record (Ctrl-,)";
$this->inputs["previousRec"]->staticValue = true;
}
elseif($navforward)
{
$this->inputs["firstRec"] =
new iLink("#",$this->icons->firstDisabled,"","",$bType);
$this->inputs["previousRec"] =
new iLink("#",$this->icons->previousDisabled,"","",$bType);
}
if($navforward)
{
$this->inputs["nextRec"] =
new iLink($this->nextRec,$this->icons->next,"","",$bType);
$this->inputs["nextRec"]->title = "Go to Next Record (Ctrl-.)";
$this->inputs["nextRec"]->staticValue = true;
$this->inputs["lastRec"] =
new iLink($this->lastRec,$this->icons->last,"","",$bType);
$this->inputs["lastRec"]->title = "Go to Last Record (Ctrl-/)";
$this->inputs["lastRec"]->staticValue = true;
}
elseif($navback || $newrec)
{
$this->inputs["nextRec"] =
new iLink("#",$this->icons->nextDisabled,"","",$bType);
$this->inputs["lastRec"] =
new iLink("#",$this->icons->lastDisabled,"","",$bType);
}
if($this->boundForm->allowNewView)
{
$this->inputs["newRec"] =
new iLink($this->newRec,$this->icons->new,"","",$bType);
$this->inputs["newRec"]->title = "Go to New Record (Ctrl-N)";
$this->inputs["newRec"]->staticValue = true;
}
$this->inputs["sheetV"] =
new iLink($this->sheetV,$this->icons->sv,"","",$bType);
$this->inputs["sheetV"]->title = "Go to Sheet View (Ctrl-B)";
$this->inputs["sheetV"]->staticValue = true;
} // if not noNavigation
if(!$this->boundForm->noNavigation || $this->boundForm->showDelete)
{
$this->inputs["deleteRec"] =
new iLink($this->deleteRec,$this->icons->delete,"","",$bType);
$this->inputs["deleteRec"]->title = "Delete Record (Ctrl-D)";
$this->inputs["deleteRec"]->staticValue = true;
}
unset($this->inputs['submit']);
if($this->boundForm->noNavigation)
// exit if noNavigation
{
return false;
}
// need to print navigation links
if($this->boundForm->currentRec === "new")
{
$this->inputs["recNum"] =
new iCustomInput("New Record");
}
elseif($this->boundForm->sheetView)
{
// show Page # of #
$this->inputs["recNum"] =
new iCustomInput((floor(($this->boundForm->currentRec /
$this->boundForm->recordLimit))+1)." of ".
ceil(($this->boundForm->maxRec /
$this->boundForm->recordLimit))," ");
// Put a dropdown box if there are less than 150 pages
if(ceil(($this->boundForm->maxRec /
$this->boundForm->recordLimit)) > 1 &&
ceil(($this->boundForm->maxRec /
$this->boundForm->recordLimit)) < 150)
{
$numberString = "\n<select class=\"p\" name=\"FiFormRecordNavigation\" onchange=\"window.location.href = '".$this->myURL."&currentRec='+this.value;\">\n";
for($i = 0; $i < ceil(($this->boundForm->maxRec /
$this->boundForm->recordLimit)); $i++)
{
$numberString .= "<option ".($i ==
floor(($this->boundForm->currentRec /
$this->boundForm->recordLimit)) ?
"selected=\"selected\" " : "")
."value=\"".($i*$this->boundForm->recordLimit)."\">".
($i+1)."</option>\n";
}
$numberString .= "</select>\n";
$this->inputs["recNav"] =
new iCustomInput($numberString);
} // end if < 150 pages
}
else
{
$this->inputs["recNum"] =
new iCustomInput(($this->boundForm->currentRec+1)." of ".
$this->boundForm->maxRec," ");
}
} // function createNavInputs
function createSubmitButton()
{
if(!$this->boundForm->readOnly)
{
if($this->boundForm->currentRec === "new")
{
$this->inputs["submit"] =
new iSubmit($this->icons->insert);
}
else
{
$this->inputs["submit"] =
new iSubmit($this->icons->update);
} // if currentRec = new
} // if not readOnly
else
{
$this->inputs['noInput'] = new iROText(" "," ");
} // if not readOnly
}
function iFormControl(&$boundForm)
{
$this->boundForm = &$boundForm;
$this->icons = &$this->boundForm->wrapper->icons;
$this->visible = TRUE;
$this->htmlClass = "FiForm_Control";
} // function iFormControl
function processControls()
{
$this->buildURLs();
if($_GET["deleteRec"] == "confirm" &&
$_POST["_DELETECONFIRM"] != "yes")
{
$this->buildDeleteConfirm();
}
else
{
$this->createNavInputs();
$this->createSubmitButton();
} // if deleteRec
} // function processControls
function drawInput()
{
if($this->boundForm->sheetView)
{
$output= "<div class=\"".$this->htmlClass."\"><table><tr>";
if($this->inputs["firstRec"])
{
$output .= "<td>".$this->inputs["firstRec"]->drawInput()."</td>";
$output .= "<td>".
$this->inputs["previousRec"]->drawInput()."</td>";
$output .= "<td>".$this->inputs["nextRec"]->drawInput()."</td>";
$output .= "<td>".$this->inputs["lastRec"]->drawInput()."</td>";
}
if($this->boundForm->allowFormView &&
$this->boundForm->allowNewView && $this->inputs["newRec"])
{
$output .= "<td>".$this->inputs["newRec"]->drawInput()."</td>";
}
//$output .= "<td>".$this->inputs["recNum"]->drawInput()."</td>";
if($this->inputs["recNav"])
{
$output .= "<td>".$this->inputs["recNav"]->drawInput()."</td>";
}
$output .= "</tr></table></div>";
}
else
{
unset($this->inputs["recNum"]);
$output = $this->drawHead();
$output .= $this->outputRow($this,false);
$output .= $this->drawFoot();
}
if($GLOBALS['FIFORMS_CONFIG']['USE_XHTML'])
{
$codeStart = '<![CDATA[';
$codeEnd = ']]>';
}
$script = '
<script type="text/javascript">
'.$codeStart.'
URL_firstRec = "'.html_entity_decode($this->inputs['firstRec']->value).'";
URL_previousRec = "'.html_entity_decode($this->inputs['previousRec']->value).'";
URL_nextRec = "'.html_entity_decode($this->inputs['nextRec']->value).'";
URL_lastRec = "'.html_entity_decode($this->inputs['lastRec']->value).'";
URL_newRec = "'.html_entity_decode($this->inputs['newRec']->value).'";
URL_deleteRec = "'.html_entity_decode($this->inputs['deleteRec']->value).'";
URL_sheetV = "'.html_entity_decode($this->inputs['sheetV']->value).'";
'.$codeEnd.'
</script>
';
$output .= $script;
return($output);
} // function drawInput
} // class iFormControl
/* ?></code><?php */
?>