[Alba-desarrollo] SVN Alba r5225 -
prosistem/alba/trunk/alba/apps/principal/modules/informes/lib
commits en pressenter.com.ar
commits en pressenter.com.ar
Mie Oct 17 22:09:47 CEST 2007
Author: josx
Date: 2007-10-17 17:09:47 -0300 (Wed, 17 Oct 2007)
New Revision: 5225
Removed:
prosistem/alba/trunk/alba/apps/principal/modules/informes/lib/tbs_clas=
s.php
Log:
Sacando version vieja del TBS
Deleted: prosistem/alba/trunk/alba/apps/principal/modules/informes/lib/tb=
s_class.php
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- prosistem/alba/trunk/alba/apps/principal/modules/informes/lib/tbs_cla=
ss.php 2007-10-17 20:08:48 UTC (rev 5224)
+++ prosistem/alba/trunk/alba/apps/principal/modules/informes/lib/tbs_cla=
ss.php 2007-10-17 20:09:47 UTC (rev 5225)
@@ -1,3397 +0,0 @@
-<?php
-/*
-********************************************************
-TinyButStrong - Template Engine for Pro and Beginners
-------------------------
-Version : 2.05.8 for PHP >=3D 4.0.6
-Date : 2006-05-02
-Web site : www.tinybutstrong.com
-Author : skrol29 en freesurf.fr
-********************************************************
-This library is free software.
-You can redistribute and modify it even for commercial usage,
-but you must accept and respect the LPGL License (v2.1 or later).
-*/
-// Check PHP version
-if (PHP_VERSION<'4.0.6') {
- echo '<br><b>TinyButStrong Error</b> (PHP Version Check) : Your PHP ver=
sion is '.PHP_VERSION.' while TinyButStrong needs PHP version 4.0.6 or hi=
gher.';
-} elseif (PHP_VERSION<'4.1.0') {
- function array_key_exists (&$key,&$array) {
- return key_exists($key,$array);
- }
-}
-
-// Render flags
-define('TBS_NOTHING', 0);
-define('TBS_OUTPUT', 1);
-define('TBS_EXIT', 2);
-
-// Special cache actions
-define('TBS_DELETE', -1);
-define('TBS_CANCEL', -2);
-define('TBS_CACHENOW', -3);
-define('TBS_CACHEONSHOW', -4);
-define('TBS_CACHELOAD', -5);
-define('TBS_CACHEGETAGE', -6);
-define('TBS_CACHEGETNAME', -7);
-define('TBS_CACHEISONSHOW', -8);
-
-// *********************************************
-
-class clsTbsLocator {
- var $PosBeg =3D false;
- var $PosEnd =3D false;
- var $Enlarged =3D false;
- var $FullName =3D false;
- var $SubName =3D '';
- var $SubOk =3D false;
- var $SubLst =3D array();
- var $SubNbr =3D 0;
- var $PrmLst =3D array();
- var $MagnetId =3D false;
- var $BlockFound =3D false;
- var $FirstMerge =3D true;
- var $ConvProtect =3D true;
- var $ConvHtml =3D true;
- var $ConvBr =3D true;
- var $ConvSpe =3D false;
-}
-
-// *********************************************
-
-class clsTbsDataSource {
-
-var $Type =3D false;
-var $SubType =3D 0;
-var $SrcId =3D false;
-var $Query =3D '';
-var $RecSet =3D false;
-var $RecKey =3D '';
-var $RecNum =3D 0;
-var $RecNumInit =3D 0;
-var $RecSaving =3D false;
-var $RecSaved =3D false;
-var $RecBuffer =3D false;
-var $CurrRec =3D false;
-var $PrevRec =3D array();
-var $oTBS =3D false;
-var $BlockName =3D '';
-var $OnDataOk =3D false;
-var $OnDataSave =3D '';
-var $OnDataInfo =3D false;
-var $OnDataPrm =3D array();
-
-function DataAlert($Msg) {
- return $this->oTBS->meth_Misc_Alert('MergeBlock '.$this->oTBS->ChrOpen.=
$this->BlockName.$this->oTBS->ChrClose,$Msg);
-}
-
-function DataPrepare(&$SrcId,&$oTBS) {
-
- $this->SrcId =3D& $SrcId;
- $this->oTBS =3D& $oTBS;
-
- if (is_array($SrcId)) {
- $this->Type =3D 0;
- } elseif (is_resource($SrcId)) {
-
- $Key =3D get_resource_type($SrcId);
- switch ($Key) {
- case 'mysql link' : $this->Type =3D 1; break;
- case 'mysql link persistent' : $this->Type =3D 1; break;
- case 'mysql result' : $this->Type =3D 1; $this->SubType =3D 1=
; break;
- case 'pgsql link' : $this->Type =3D 8; break;
- case 'pgsql link persistent' : $this->Type =3D 8; break;
- case 'pgsql result' : $this->Type =3D 8; $this->SubType =3D 1=
; break;
- case 'sqlite database' : $this->Type =3D 9; break;
- case 'sqlite database (persistent)' : $this->Type =3D 9; break;
- case 'sqlite result' : $this->Type =3D 9; $this->SubType =3D 1=
; break;
- default :
- $SubKey =3D 'resource type';
- $this->Type =3D 7;
- $x =3D strtolower($Key);
- $x =3D str_replace('-','_',$x);
- $Function =3D '';
- $i =3D 0;
- $iMax =3D strlen($x);
- while ($i<$iMax) {
- if (($x[$i]=3D=3D=3D'_') or (($x[$i]>=3D'a') and ($x[$i]<=3D'z')) or=
(($x[$i]>=3D'0') and ($x[$i]<=3D'9'))) {
- $Function .=3D $x[$i];
- $i++;
- } else {
- $i =3D $iMax;
- }
- }
- }
-
- } elseif (is_string($SrcId)) {
-
- switch (strtolower($SrcId)) {
- case 'array' : $this->Type =3D 0; $this->SubType =3D 1; break;
- case 'clear' : $this->Type =3D 0; $this->SubType =3D 3; break;
- case 'mysql' : $this->Type =3D 1; $this->SubType =3D 2; break;
- case 'text' : $this->Type =3D 4; break;
- case 'num' : $this->Type =3D 6; break;
- default :
- if ($SrcId[0]=3D=3D=3D'~') {
- $ErrMsg =3D false;
- $this->FctOpen =3D $SrcId.'_open';
- $this->FctFetch =3D $SrcId.'_fetch';
- $this->FctClose =3D $SrcId.'_close';
- $this->FctPrm =3D array(false,0);
- if ($oTBS->meth_Misc_UserFctCheck($this->FctOpen,$ErrMsg)) {
- if ($oTBS->meth_Misc_UserFctCheck($this->FctFetch,$ErrMsg)) {
- if ($oTBS->meth_Misc_UserFctCheck($this->FctClose,$ErrMsg)) {
- $this->Type =3D 11;
- $this->SrcId =3D& $oTBS->ObjectRef;
- }
- }
- }
- if ($ErrMsg!=3D=3Dfalse) $this->Type =3D $this->DataAlert($ErrMsg);
- } else {
- $Key =3D $SrcId;
- $SubKey =3D 'keyword';
- $this->Type =3D 7;
- $Function =3D $SrcId;
- }
- }
-
- } elseif (is_object($SrcId)) {
- if (method_exists($SrcId,'tbsdb_open')) {
- if (!method_exists($SrcId,'tbsdb_fetch')) {
- $this->Type =3D $this->DataAlert('The expected method \'tbsdb_fetch\=
' is not found for the class '.get_class($SrcId).'.');
- } elseif (!method_exists($SrcId,'tbsdb_close')) {
- $this->Type =3D $this->DataAlert('The expected method \'tbsdb_close\=
' is not found for the class '.get_class($SrcId).'.');
- } else {
- $this->Type =3D 10;
- }
- } else {
- $Key =3D get_class($SrcId);
- $SubKey =3D 'object type';
- $this->Type =3D 7;
- $Function =3D $Key;
- }
- } elseif ($SrcId=3D=3D=3Dfalse) {
- $this->DataAlert('The specified source is set to FALSE. Maybe your con=
nection has failed.');
- } else {
- $this->DataAlert('Unsupported variable type : \''.gettype($SrcId).'\'.=
');
- }
-
- if ($this->Type=3D=3D=3D7) {
- $this->FctOpen =3D 'tbsdb_'.$Function.'_open';
- $Ok =3D function_exists($this->FctOpen);
- if (!$Ok) { // Some extended call can have a suffix in the class name,=
we check without the suffix
- $i =3D strpos($Function,'_');
- if ($i!=3D=3Dfalse) {
- $x =3D substr($Function,0,$i);
- $z =3D 'tbsdb_'.$x.'_open';
- $Ok =3D function_exists($z);
- if ($Ok) {
- $Function =3D $x;
- $this->FctOpen =3D $z;
- }
- }
- }
- if ($Ok) {
- $this->FctFetch =3D 'tbsdb_'.$Function.'_fetch';
- $this->FctClose =3D 'tbsdb_'.$Function.'_close';
- if (function_exists($this->FctFetch)) {
- if (!function_exists($this->FctClose)) $this->Type =3D $this->DataAl=
ert('The expected custom function \''.$this->FctClose.'\' is not found.')=
;
- } else {
- $this->Type =3D $this->DataAlert('The expected custom function \''.$=
this->FctFetch.'\' is not found.');
- }
- } else {
- $this->Type =3D $this->DataAlert('The data source Id \''.$Key.'\' is =
an unsupported '.$SubKey.' because custom function \''.$this->FctOpen.'\'=
is not found.');
- }
- }
-
- return ($this->Type!=3D=3Dfalse);
-
-}
-
-function DataOpen(&$Query,&$PageSize,&$PageNum,&$RecStop) {
-
- // Init values
- unset($this->CurrRec); $this->CurrRec =3D true;
- if ($this->RecSaved) {
- $this->FirstRec =3D true;
- unset($this->RecKey); $this->RecKey =3D '';
- $this->RecNum =3D $this->RecNumInit;
- return true;
- }
- unset($this->RecSet); $this->RecSet =3D false;
- $this->RecNumInit =3D 0;
- $this->RecNum =3D 0;
- if ($this->OnDataInfo!=3D=3Dfalse) {
- $this->OnDataOk =3D true;
- $this->OnDataPrm[0] =3D& $this->BlockName;
- $this->OnDataPrm[1] =3D& $this->CurrRec;
- $this->OnDataPrm[2] =3D& $this->RecNum;
- }
-
- switch ($this->Type) {
- case 0: // Array
- if (($this->SubType=3D=3D=3D1) and (is_string($Query))) $this->SubType=
=3D 2;
- if ($this->SubType=3D=3D=3D0) {
- if (PHP_VERSION=3D=3D=3D'4.4.1') {$this->RecSet =3D $this->SrcId;} el=
se {$this->RecSet =3D& $this->SrcId;} // bad bug in PHP 4.4.1
- } elseif ($this->SubType=3D=3D=3D1) {
- if (is_array($Query)) {
- if (PHP_VERSION=3D=3D=3D'4.4.1') {$this->RecSet =3D $Query;} else {$=
this->RecSet =3D& $Query;}
- } else {
- $this->DataAlert('Type \''.gettype($Query).'\' not supported for the=
Query Parameter going with \'array\' Source Type.');
- }
- } elseif ($this->SubType=3D=3D=3D2) {
- //Found the global variable name and the sub-keys
- $Pos =3D strpos($Query,'[');
- if ($Pos=3D=3D=3Dfalse) {
- $VarName =3D $Query;
- $Keys =3D array();
- } else {
- $VarName =3D substr($Query,0,$Pos);
- $Keys =3D substr($Query,$Pos+1,strlen($Query)-$Pos-2);
- $Keys =3D explode('][',$Keys);
- }
- // Check variable and sub-keys
- if (isset($GLOBALS[$VarName])) {
- if (PHP_VERSION=3D=3D=3D'4.4.1') {$Var =3D $GLOBALS[$VarName];} else=
{$Var =3D& $GLOBALS[$VarName];}
- if (is_array($Var)) {
- $Ok =3D true;
- $KeyMax =3D count($Keys)-1;
- $KeyNum =3D 0;
- while ($Ok and ($KeyNum<=3D$KeyMax)) {
- if (isset($Var[$Keys[$KeyNum]])) {
- $Var =3D& $Var[$Keys[$KeyNum]];
- $KeyNum++;
- if (!is_array($Var)) $Ok =3D $this->DataAlert('Invalid query \''.=
$Query.'\' because item \''.$VarName.'['.implode('][',array_splice($Keys,=
0,$KeyNum)).']\' is not an array.');
- } else {
- $Ok =3D false; // Item not found =3D> not an error, considered as=
a query with empty result.
- $this->RecSet =3D array();
- }
- }
- if ($Ok) $this->RecSet =3D& $Var;
- } else {
- $this->DataAlert('Invalid query \''.$Query.'\' because global varia=
ble \''.$VarName.'\' is not an array.');
- }
- } else {
- $this->DataAlert('Invalid query \''.$Query.'\' because global variab=
le \''.$VarName.'\' is not found.');
- }
- } elseif ($this->SubType=3D=3D=3D3) { // Clear
- $this->RecSet =3D array();
- }
- // First record
- if ($this->RecSet!=3D=3Dfalse) {
- $this->RecNbr =3D $this->RecNumInit + count($this->RecSet);
- $this->FirstRec =3D true;
- $this->RecSaved =3D true;
- $this->RecSaving =3D false;
- }
- break;
- case 1: // MySQL
- switch ($this->SubType) {
- case 0: $this->RecSet =3D @mysql_query($Query,$this->SrcId); break;
- case 1: $this->RecSet =3D $this->SrcId; break;
- case 2: $this->RecSet =3D @mysql_query($Query); break;
- }
- if ($this->RecSet=3D=3D=3Dfalse) $this->DataAlert('MySql error message=
when opening the query: '.mysql_error());
- break;
- case 4: // Text
- if (is_string($Query)) {
- $this->RecSet =3D& $Query;
- } else {
- $this->RecSet =3D ''.$Query;=09
- }
- $PageSize =3D 0;
- break;
- case 6: // Num
- $this->RecSet =3D true;
- $this->NumMin =3D 1;
- $this->NumMax =3D 1;
- $this->NumStep =3D 1;
- if (is_array($Query)) {
- if (isset($Query['min'])) $this->NumMin =3D $Query['min'];
- if (isset($Query['step'])) $this->NumStep =3D $Query['step'];
- if (isset($Query['max'])) {
- $this->NumMax =3D $Query['max'];
- } else {
- $this->RecSet =3D $this->DataAlert('The \'num\' source is an array t=
hat has no value for the \'max\' key.');
- }
- if ($this->NumStep=3D=3D0) $this->RecSet =3D $this->DataAlert('The \'=
num\' source is an array that has a step value set to zero.');
- } else {
- $this->NumMax =3D ceil($Query);
- }
- if ($this->RecSet) {
- if ($this->NumStep>0) {
- $this->NumVal =3D $this->NumMin;
- } else {
- $this->NumVal =3D $this->NumMax;
- }
- }
- break;
- case 7: // Custom function
- $FctOpen =3D $this->FctOpen;
- $this->RecSet =3D $FctOpen($this->SrcId,$Query);
- break;
- case 8: // PostgreSQL
- switch ($this->SubType) {
- case 0: $this->RecSet =3D @pg_query($this->SrcId,$Query); break;
- case 1: $this->RecSet =3D $this->SrcId; break;
- }
- if ($this->RecSet=3D=3D=3Dfalse) $this->DataAlert('PostgreSQL error me=
ssage when opening the query: '.pg_last_error($this->SrcId));
- break;
- case 9: // SQLite
- switch ($this->SubType) {
- case 0: $this->RecSet =3D @sqlite_query($this->SrcId,$Query); break;
- case 1: $this->RecSet =3D $this->SrcId; break;
- }
- if ($this->RecSet=3D=3D=3Dfalse) $this->DataAlert('SQLite error messag=
e when opening the query:'.sqlite_error_string(sqlite_last_error($this->S=
rcId)));
- break;
- case 10: // Custom method
- $this->RecSet =3D $this->SrcId->tbsdb_open($this->SrcId,$Query);
- break;
- case 11: // ObjectRef
- $this->RecSet =3D call_user_func_array($this->FctOpen,array(&$this->Sr=
cId,&$Query));
- break;
- }
-
- if ($this->Type=3D=3D=3D0) {
- unset($this->RecKey); $this->RecKey =3D '';
- } else {
- if ($this->RecSaving) {
- unset($this->RecBuffer); $this->RecBuffer =3D array();
- }
- $this->RecKey =3D& $this->RecNum; // Not array: RecKey =3D RecNum
- }
-
- //Goto the page
- if (($this->RecSet!=3D=3Dfalse) and ($PageSize>0)) {
- if ($PageNum=3D=3D-1) { // Goto end of the recordset
- if ($this->RecSaved) { // Data source is array
- $PageNum =3D intval(ceil($this->RecNbr/$PageSize));
- } else {
- // Read records, saving the last page in $this->RecBuffer
- $i =3D 0;
- unset($this->RecBuffer); $this->RecBuffer =3D array();
- $this->RecSaving =3D true;
- $this->DataFetch();
- while ($this->CurrRec!=3D=3Dfalse) {
- if ($i=3D=3D=3D$PageSize) {
- $this->RecBuffer =3D array($this->RecKey =3D> $this->CurrRec);
- $i =3D 0;
- $this->RecNumInit +=3D $PageSize;
- }
- $i++;
- $this->DataFetch();
- }
- $this->DataClose(); // Close the real recordset source
- unset($this->RecNum); $this->RecNum =3D 0+$this->RecNumInit;
- $this->FirstRec =3D true;
- }
- }
- if ($PageNum>0) {
- // We pass all record until the asked page
- $RecStop =3D ($PageNum-1) * $PageSize;
- while ($this->RecNum<$RecStop) {
- $this->DataFetch();
- if ($this->CurrRec=3D=3D=3Dfalse) $RecStop=3D$this->RecNum;=09
- }
- if ($this->CurrRec!=3D=3Dfalse) $RecStop =3D $PageNum * $PageSize;
- $this->RecNumInit =3D $this->RecNum; // Useful if RecSaved
- } else {
- $RecStop =3D 1;
- }
- }
-
- return ($this->RecSet!=3D=3Dfalse);
-
-}
-
-function DataFetch() {
-
- if ($this->RecSaved) {
- if ($this->RecNum<$this->RecNbr) {
- if ($this->FirstRec) {
- if ($this->SubType=3D=3D=3D2) { // From string
- reset($this->RecSet);
- $this->RecKey =3D key($this->RecSet);
- $this->CurrRec =3D& $this->RecSet[$this->RecKey];
- } else {
- $this->CurrRec =3D reset($this->RecSet);
- $this->RecKey =3D key($this->RecSet);
- }
- $this->FirstRec =3D false;
- } else {
- if ($this->SubType=3D=3D=3D2) { // From string
- next($this->RecSet);
- $this->RecKey =3D key($this->RecSet);
- $this->CurrRec =3D& $this->RecSet[$this->RecKey];
- } else {
- $this->CurrRec =3D next($this->RecSet);
- $this->RecKey =3D key($this->RecSet);
- }
- }
- if (!is_array($this->CurrRec)) $this->CurrRec =3D array('key'=3D>$thi=
s->RecKey, 'val'=3D>$this->CurrRec);
- $this->RecNum++;
- if ($this->OnDataOk) {
- $this->OnDataPrm[1] =3D& $this->CurrRec; // Reference has changed if=
($this->SubType=3D=3D=3D2)
- call_user_func_array($this->OnDataInfo,$this->OnDataPrm);
- }
- } else {
- unset($this->CurrRec); $this->CurrRec =3D false;
- }
- return;
- }
-
- switch ($this->Type) {
- case 1: // MySQL
- $this->CurrRec =3D mysql_fetch_assoc($this->RecSet);
- break;
- case 4: // Text
- if ($this->RecNum=3D=3D=3D0) {
- if ($this->RecSet=3D=3D=3D'') {
- $this->CurrRec =3D false;
- } else {
- $this->CurrRec =3D& $this->RecSet;
- }
- } else {
- $this->CurrRec =3D false;
- }
- break;
- case 6: // Num
- if (($this->NumVal>=3D$this->NumMin) and ($this->NumVal<=3D$this->NumM=
ax)) {
- $this->CurrRec =3D array('val'=3D>$this->NumVal);
- $this->NumVal +=3D $this->NumStep;
- } else {
- $this->CurrRec =3D false;
- }
- break;
- case 7: // Custom function
- $FctFetch =3D $this->FctFetch;
- $this->CurrRec =3D $FctFetch($this->RecSet,$this->RecNum+1);
- break;
- case 8: // PostgreSQL
- $this->CurrRec =3D @pg_fetch_array($this->RecSet,$this->RecNum,PGSQL_A=
SSOC); // warning comes when no record left.
- break;
- case 9: // SQLite
- $this->CurrRec =3D sqlite_fetch_array($this->RecSet,SQLITE_ASSOC);
- break;
- case 10: // Custom method
- $this->CurrRec =3D $this->SrcId->tbsdb_fetch($this->RecSet,$this->RecN=
um+1);
- break;
- case 11: // ObjectRef
- $this->FctPrm[0] =3D& $this->RecSet; $this->FctPrm[1] =3D $this->RecNu=
m+1;
- $this->CurrRec =3D call_user_func_array($this->FctFetch,$this->FctPrm)=
;
- break;
- }
-
- // Set the row count
- if ($this->CurrRec!=3D=3Dfalse) {
- $this->RecNum++;
- if ($this->OnDataOk) call_user_func_array($this->OnDataInfo,$this->OnD=
ataPrm);
- if ($this->RecSaving) $this->RecBuffer[$this->RecKey] =3D $this->CurrR=
ec;
- }
-
-}
-
-function DataClose() {
- if ($this->RecSaved) return;
- $this->OnDataOk =3D false;
- switch ($this->Type) {
- case 1: mysql_free_result($this->RecSet); break;
- case 7: $FctClose=3D$this->FctClose; $FctClose($this->RecSet); break;
- case 8: pg_free_result($this->RecSet); break;
- case 10: $this->SrcId->tbsdb_close($this->RecSet); break;
- case 11: call_user_func_array($this->FctClose,array(&$this->RecSet)); b=
reak;
- }
- if ($this->RecSaving) {
- $this->RecSet =3D& $this->RecBuffer;
- $this->RecNbr =3D $this->RecNumInit + count($this->RecSet);
- $this->RecSaving =3D false;
- $this->RecSaved =3D true;
- }
-}
-
-}
-
-// *********************************************
-
-class clsTinyButStrong {
-
-// Public properties
-var $Source =3D ''; // Current result of the merged template
-var $Render =3D 3;
-var $HtmlCharSet =3D '';
-var $TplVars =3D array();
-var $VarPrefix =3D '';
-var $ObjectRef =3D false;
-var $Protect =3D true;
-// Private properties
-var $_LastFile =3D ''; // The last loaded template file
-var $_CacheFile =3D false; // The name of the file to save the content i=
n.
-var $_HtmlCharFct =3D false;
-var $_Mode =3D 0;
-// Used to be globals
-var $ChrOpen =3D '[';
-var $ChrClose =3D ']';
-var $ChrVal =3D '[val]';
-var $ChrProtect =3D '[';
-var $CacheMask =3D 'cache_tbs_*.php';
-var $TurboBlock =3D true;
-var $MaxEnd =3D '...';
-
-function clsTinyButStrong($Chrs=3D'',$VarPrefix=3D'') {
- if ($Chrs!=3D=3D'') {
- $Ok =3D false;
- $Len =3D strlen($Chrs);
- if ($Len=3D=3D=3D2) { // For compatibility
- $this->ChrOpen =3D $Chrs[0];
- $this->ChrClose =3D $Chrs[1];
- $Ok =3D true;
- } else {
- $Pos =3D strpos($Chrs,',');
- if (($Pos!=3D=3Dfalse) and ($Pos>0) and ($Pos<$Len-1)) {
- $this->ChrOpen =3D substr($Chrs,0,$Pos);
- $this->ChrClose =3D substr($Chrs,$Pos+1);
- $Ok =3D true;
- }
- }
- if ($Ok) {
- $this->ChrVal =3D $this->ChrOpen.'val'.$this->ChrClose;
- $this->ChrProtect =3D '&#'.ord($this->ChrOpen[0]).';'.substr($this->C=
hrOpen,1);
- } else {
- $this->meth_Misc_Alert('Creating instance','Bad argument for tag deli=
mitors \''.$Chrs.'\'.');
- }
- }
- $this->VarPrefix =3D $VarPrefix;
- //Cache for formats
- if (!isset($GLOBALS['_tbs_FrmMultiLst'])) {
- $GLOBALS['_tbs_FrmMultiLst'] =3D array();
- $GLOBALS['_tbs_FrmSimpleLst'] =3D array();
- }
-}
-
-// Public methods
-function LoadTemplate($File,$HtmlCharSet=3D'') {
- // Load the file
- $x =3D '';
- if (!tbs_Misc_GetFile($x,$File)) return $this->meth_Misc_Alert('LoadTem=
plate Method','Unable to read the file \''.$File.'\'.');
- // CharSet analysis
- if ($HtmlCharSet=3D=3D=3D'+') {
- $this->Source .=3D $x;
- } else {
- $this->Source =3D $x;
- if ($this->_Mode=3D=3D0) {
- $this->_LastFile =3D $File;
- $this->_HtmlCharFct =3D false;
- $this->TplVars =3D array();
- if (is_string($HtmlCharSet)) {
- if (($HtmlCharSet!=3D=3D'') and ($HtmlCharSet[0]=3D=3D=3D'=3D')) {
- $ErrMsg =3D false;
- $HtmlCharSet =3D substr($HtmlCharSet,1);
- if ($this->meth_Misc_UserFctCheck($HtmlCharSet,$ErrMsg)) {
- $this->_HtmlCharFct =3D true;
- } else {
- $this->meth_Misc_Alert('LoadTemplate Method',$ErrMsg);
- $HtmlCharSet =3D '';
- }
- }
- } elseif ($HtmlCharSet=3D=3D=3Dfalse) {
- $this->Protect =3D false;
- } else {
- $this->meth_Misc_Alert('LoadTemplate Method','CharSet is not a strin=
g.');
- $HtmlCharSet =3D '';
- }
- $this->HtmlCharSet =3D $HtmlCharSet;
- }
- }
- // Automatic fields and blocks
- $this->meth_Merge_Auto($this->Source,'onload',true,true);
- return true;
-}
-
-function GetBlockSource($BlockName,$List=3Dfalse) {
- $RetVal =3D array();
- $Nbr =3D 0;
- $Pos =3D 0;
- $FieldOutside =3D false;
- $P1 =3D false;
- while ($Loc =3D $this->meth_Locator_FindBlockNext($this->Source,$BlockN=
ame,$Pos,'.',false,$P1,$FieldOutside)) {
- $P1 =3D false;
- $Nbr++;
- $RetVal[$Nbr] =3D substr($this->Source,$Loc->PosBeg,$Loc->PosEnd-$Loc-=
>PosBeg+1);
- if (!$List) return $RetVal[$Nbr];
- $Pos =3D $Loc->PosEnd;
- }
- if ($List) {
- return $RetVal;
- } else {
- return false;
- }
-}
-
-function MergeBlock($BlockName,$SrcId,$Query=3D'',$PageSize=3D0,$PageNum=
=3D0,$RecKnown=3D0) {
- if ($SrcId=3D=3D=3D'cond') {
- $Nbr =3D 0;
- $BlockLst =3D explode(',',$BlockName);
- foreach ($BlockLst as $Block) {
- $Nbr +=3D $this->meth_Merge_Auto($this->Source,$Block,false,false);
- }
- return $Nbr;
- } else {
- return $this->meth_Merge_Block($this->Source,$BlockName,$SrcId,$Query,=
$PageSize,$PageNum,$RecKnown);
- }
-}
-
-function MergeField($Name,$Value,$IsUserFct=3Dfalse) {
- $PosBeg =3D 0;
- if ($IsUserFct) {
- $FctInfo =3D $Value;
- $ErrMsg =3D false;
- if ($this->meth_Misc_UserFctCheck($FctInfo,$ErrMsg)) {
- $FctPrm =3D array('','');
- while ($Loc =3D $this->meth_Locator_FindTbs($this->Source,$Name,$PosB=
eg,'.')) {
- $FctPrm[0] =3D& $Loc->SubName; $FctPrm[1] =3D& $Loc->PrmLst;
- $x =3D call_user_func_array($FctInfo,$FctPrm);
- $PosBeg =3D $this->meth_Locator_Replace($this->Source,$Loc,$x,false)=
;
- }
- } else {
- $this->meth_Misc_Alert('MergeField Method',$ErrMsg);
- }
- } else {
- while ($Loc =3D $this->meth_Locator_FindTbs($this->Source,$Name,$PosBe=
g,'.')) {
- $PosBeg =3D $this->meth_Locator_Replace($this->Source,$Loc,$Value,tru=
e);
- }
- }
-}
-
-function MergeSpecial($Type) {
- $Type =3D strtolower($Type);
- $this->meth_Merge_Special($Type);
-}
-
-function MergeNavigationBar($BlockLst,$Options,$PageCurr,$RecCnt=3D-1,$P=
ageSize=3D1) {
- $BlockLst =3D explode(',',$BlockLst);
- foreach ($BlockLst as $BlockName) {
- $BlockName =3D trim($BlockName);
- $this->meth_Merge_NavigationBar($this->Source,$BlockName,$Options,$Pag=
eCurr,$RecCnt,$PageSize);
- }
-}
-
-function Show($Render=3D'') {
- if ($Render=3D=3D=3D'') $Render =3D $this->Render;
- if ($this->_CacheFile!=3D=3Dtrue) $this->meth_Merge_Special('onshow,var=
');
- if (is_string($this->_CacheFile)) $this->meth_Cache_Save($this->_CacheF=
ile,$this->Source);
- if (($Render & TBS_OUTPUT)=3D=3DTBS_OUTPUT) echo $this->Source;
- if (($this->_Mode=3D=3D0) and (($Render & TBS_EXIT)=3D=3DTBS_EXIT)) exi=
t;
-}
-
-function CacheAction($CacheId,$Action=3D3600,$Dir=3D'') {
-
- $CacheId =3D trim($CacheId);
- $Res =3D false;
-
- if ($Action=3D=3D=3DTBS_CANCEL) { // Cancel cache save if any
- $this->_CacheFile =3D false;
- } elseif ($CacheId =3D=3D=3D '*') {
- if ($Action=3D=3D=3DTBS_DELETE) $Res =3D tbs_Cache_DeleteAll($Dir,$thi=
s->CacheMask);
- } else {
- $CacheFile =3D tbs_Cache_File($Dir,$CacheId,$this->CacheMask);
- if ($Action=3D=3D=3DTBS_CACHENOW) {
- $this->meth_Cache_Save($CacheFile,$this->Source);
- } elseif ($Action=3D=3D=3DTBS_CACHEGETAGE) {
- if (file_exists($CacheFile)) $Res =3D time()-filemtime($CacheFile);
- } elseif ($Action=3D=3D=3DTBS_CACHEGETNAME) {
- $Res =3D $CacheFile;
- } elseif ($Action=3D=3D=3DTBS_CACHEISONSHOW) {
- $Res =3D ($this->_CacheFile!=3D=3Dfalse);
- } elseif ($Action=3D=3D=3DTBS_CACHELOAD) {
- if (file_exists($CacheFile)) {
- if (tbs_Misc_GetFile($this->Source,$CacheFile)) {
- $this->_CacheFile =3D $CacheFile;
- $Res =3D true;
- }
- }
- if ($Res=3D=3D=3Dfalse) $this->Source =3D '';
- } elseif ($Action=3D=3D=3DTBS_DELETE) {
- if (file_exists($CacheFile)) $Res =3D @unlink($CacheFile);
- } elseif ($Action=3D=3D=3DTBS_CACHEONSHOW) {
- $this->_CacheFile =3D $CacheFile;
- @touch($CacheFile);
- } elseif($Action>=3D0) {
- $Res =3D tbs_Cache_IsValide($CacheFile,$Action);
- if ($Res) { // Load the cache
- if (tbs_Misc_GetFile($this->Source,$CacheFile)) {
- $this->_CacheFile =3D true; // Special value
- $this->Show();
- } else {
- $this->meth_Misc_Alert('CacheAction Method','Unable to read the fil=
e \''.$CacheFile.'\'.');
- $Res=3D=3Dfalse;
- }
- $this->_CacheFile =3D false;
- } else {
- // The result will be saved in the cache when the Show() method is c=
alled
- $this->_CacheFile =3D $CacheFile;
- @touch($CacheFile);
- }
- }
- }
-
- return $Res;
-
-}
-
-// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
-
-function meth_Locator_FindTbs(&$Txt,$Name,$Pos,$ChrSub) {
-// Find a TBS Locator
-
- $PosEnd =3D false;
- $PosMax =3D strlen($Txt) -1;
- $Start =3D $this->ChrOpen.$Name;
-
- do {
- // Search for the opening char
- if ($Pos>$PosMax) return false;
- $Pos =3D strpos($Txt,$Start,$Pos);
-
- // If found =3D> next chars are analyzed
- if ($Pos=3D=3D=3Dfalse) {
- return false;
- } else {
- $Loc =3D& new clsTbsLocator;
- $ReadPrm =3D false;
- $PosX =3D $Pos + strlen($Start);
- $x =3D $Txt[$PosX];
-
- if ($x=3D=3D=3D$this->ChrClose) {
- $PosEnd =3D $PosX;
- } elseif ($x=3D=3D=3D$ChrSub) {
- $Loc->SubOk =3D true; // it is no longer the false value
- $ReadPrm =3D true;
- $PosX++;
- } elseif (strpos(';',$x)!=3D=3Dfalse) {
- $ReadPrm =3D true;
- $PosX++;
- } else {
- $Pos++;
- }
-
- if ($ReadPrm) {
- tbs_Locator_PrmRead($Txt,$PosX,false,'\'',$this->ChrOpen,$this->ChrC=
lose,$Loc,$PosEnd);
- if ($PosEnd=3D=3D=3Dfalse) {
- $this->meth_Misc_Alert('Tag definition','Can\'t found the end of th=
e tag \''.substr($Txt,$Pos,$PosX-$Pos+10).'...\'.');
- $Pos++;
- }
- }
- =09
- }
-
- } while ($PosEnd=3D=3D=3Dfalse);
-
- $Loc->PosBeg =3D $Pos;
- $Loc->PosEnd =3D $PosEnd;
- if ($Loc->SubOk) {
- $Loc->FullName =3D $Name.'.'.$Loc->SubName;
- $Loc->SubLst =3D explode('.',$Loc->SubName);
- $Loc->SubNbr =3D count($Loc->SubLst);
- } else {
- $Loc->FullName =3D $Name;
- }
- if ($ReadPrm and isset($Loc->PrmLst['comm'])) {
- $Loc->PosBeg0 =3D $Loc->PosBeg;
- $Loc->PosEnd0 =3D $Loc->PosEnd;
- $Loc->Enlarged =3D tbs_Locator_EnlargeToStr($Txt,$Loc,'<!--' ,'-->');
- }
-
- return $Loc;
-
-}
-
-// Search and cache TBS locators founded in $Txt.
-function meth_Locator_SectionCache(&$LocR,$Bid) {
-
- $LocR->BlockChk[$Bid] =3D false;
-
- $LocLst =3D& $LocR->BlockLoc[$Bid];
- $Txt =3D& $LocR->BlockSrc[$Bid];
- $BlockName =3D& $LocR->BlockName[$Bid];
-
- $Pos =3D 0;
- $PrevEnd =3D -1;
- $Nbr =3D 0;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$BlockName,$Pos,'.')) =
{
- if (($Loc->SubName=3D=3D=3D'#') or ($Loc->SubName=3D=3D=3D'$')) {
- $Loc->IsRecInfo =3D true;
- $Loc->RecInfo =3D $Loc->SubName;
- $Loc->SubName =3D '';
- } else {
- $Loc->IsRecInfo =3D false;
- }
- if ($Loc->PosBeg>$PrevEnd) {
- // The previous tag is not embeding =3D> increment
- $Nbr++;
- } else {
- // The previous tag is embeding =3D> no increment, then previous is o=
ver writed
- $LocR->BlockChk[$Bid] =3D true;
- }
- $PrevEnd =3D $Loc->PosEnd;
- if ($Loc->Enlarged) { // Parameter 'comm'
- $Pos =3D $Loc->PosBeg0+1;
- $Loc->Enlarged =3D false;
- } else {
- $Pos =3D $Loc->PosBeg+1;
- }
- $LocLst[$Nbr] =3D $Loc;
- }
-
- $LocLst[0] =3D $Nbr;
-
-}
-
-function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$CheckSub) {
-// This function enables to merge a locator with a text and returns the =
position just after the replaced block
-// This position can be useful because we don't know in advance how $Val=
ue will be replaced.
-
- // Found the value if there is a subname
- if ($CheckSub and $Loc->SubOk) {
- $SubId =3D 0;
- while ($SubId<$Loc->SubNbr) {
- $x =3D $Loc->SubLst[$SubId]; // &$Loc... brings an error with Event E=
xample, I don't know why.
- if (is_array($Value)) {
- if (isset($Value[$x])) {
- $Value =3D& $Value[$x];
- } elseif (array_key_exists($x,$Value)) {// can happens when value is=
NULL
- $Value =3D& $Value[$x];
- } else {
- unset($Value); $Value =3D '';
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Array va=
lue','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' beca=
use sub-item \''.$x.'\' is not an existing key in the array.',true);
- }
- $SubId++;
- } elseif (is_object($Value)) {
- if (method_exists($Value,$x)) {
- $x =3D call_user_func(array(&$Value,$x));
- } elseif (isset($Value->$x)) {
- $x =3D $Value->$x;
- } else {
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Object v=
alue','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' bec=
ause \''.$x.'\' is neither a method nor a property in the class \''.get_c=
lass($Value).'\'.',true);
- unset($x); $x =3D '';
- }
- $Value =3D& $x;
- unset($x); $x =3D '';
- $SubId++;
- } else {
- if (isset($Loc->PrmLst['selected'])) {
- $SelArray =3D& $Value;
- } else {
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Object o=
r Array value expected','Can\'t merge '.$this->ChrOpen.$Loc->FullName.$th=
is->ChrClose.' because the item before \''.$x.'\' is neither an object no=
r an array. Its type is '.gettype($Value).'.',true);
- }
- unset($Value); $Value =3D '';
- $SubId =3D $Loc->SubNbr;
- }
- }
- }
-
- $CurrVal =3D $Value;
-
- // File inclusion
- if (isset($Loc->PrmLst['file'])) {
- $File =3D $Loc->PrmLst['file'];
- $this->meth_Merge_PhpVar($File,false);
- $File =3D str_replace($this->ChrVal,$CurrVal,$File);
- $OnlyBody =3D !(isset($Loc->PrmLst['htmlconv']) and (strtolower($Loc->=
PrmLst['htmlconv'])=3D=3D=3D'no')); // It's a text file, we don't get the=
BODY part
- if (tbs_Misc_GetFile($CurrVal,$File)) {
- if ($OnlyBody) $CurrVal =3D tbs_Html_GetPart($CurrVal,'BODY',false,tr=
ue);
- } else {
- $CurrVal =3D '';
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter =
\'file\'','Field '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' : unab=
le to read the file \''.$File.'\'.',true);
- }
- $Loc->ConvHtml =3D false;
- $Loc->ConvProtect =3D false;
- }
-
- // OnFormat event
- if (isset($Loc->PrmLst['onformat'])) {
- if ($Loc->FirstMerge) {
- $Loc->OnFrmInfo =3D $Loc->PrmLst['onformat'];
- $Loc->OnFrmPrm =3D array(&$Loc->FullName,'',&$Loc->PrmLst,&$this);
- $ErrMsg =3D false;
- if (!$this->meth_Misc_UserFctCheck($Loc->OnFrmInfo,$ErrMsg)) {
- unset($Loc->PrmLst['onformat']);
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter=
\'onformat\'',$ErrMsg);
- $Loc->OnFrmInfo =3D 'pi'; // Execute the function pi() just to avoid=
extra error messages=20
- }
- }
- $Loc->OnFrmPrm[1] =3D& $CurrVal;
- if (isset($Loc->PrmLst['subtpl'])) {
- $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal,true,true);
- call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmPrm);
- $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal,true,true);
- } else {
- call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmPrm);
- }
- }
-
- // Select a value in a HTML option list
- $Select =3D isset($Loc->PrmLst['selected']);
- if ($Select) {
- if (is_array($CurrVal)) {
- $SelArray =3D& $CurrVal;
- unset($CurrVal); $CurrVal =3D ' ';
- } else {
- $SelArray =3D false;
- }
- }
-
- // Convert the value to a string, use format if specified
- if (isset($Loc->PrmLst['frm'])) {
- $CurrVal =3D tbs_Misc_Format($Loc,$CurrVal);
- $Loc->ConvHtml =3D false;
- } else {
- if (!is_string($CurrVal)) $CurrVal =3D @strval($CurrVal);
- }
-
- // case of an 'if' 'then' 'else' options
- $OVal =3D& $CurrVal; // Must be assigner after $SelArray, if any
- $Script =3D isset($Loc->PrmLst['script']);
- if (isset($Loc->PrmLst['if'])) {
- if ($Loc->FirstMerge) {
- $this->meth_Merge_PhpVar($Loc->PrmLst['if'],false);
- if (isset($Loc->PrmLst['then'])) $this->meth_Merge_PhpVar($Loc->PrmLs=
t['then'],true);
- if (isset($Loc->PrmLst['else'])) $this->meth_Merge_PhpVar($Loc->PrmLs=
t['else'],true);
- }
- $x =3D str_replace($this->ChrVal,$CurrVal,$Loc->PrmLst['if']);
- if (tbs_Misc_CheckCondition($x)) {
- if (isset($Loc->PrmLst['then'])) {
- unset($CurrVal); $CurrVal =3D ''.$Loc->PrmLst['then']; // Now $CurrV=
al and $OVal are different
- }
- } else {
- $Script =3D false;
- if (isset($Loc->PrmLst['else'])) {
- unset($CurrVal); $CurrVal =3D ''.$Loc->PrmLst['else']; // Now $CurrV=
al and $OVal are different
- } else {
- $CurrVal =3D '';
- }
- }
- }
-
- if ($Script) {// Include external PHP script
- $File =3D $Loc->PrmLst['script'];
- $this->meth_Merge_PhpVar($File,false);
- $File =3D str_replace($this->ChrVal,$CurrVal,$File);
- $Switch =3D isset($Loc->PrmLst['subtpl']);
- $GetOb =3D ($Switch or isset($Loc->PrmLst['getob']));
- $CurrPrm =3D& $Loc->PrmLst; // Local var for users
- $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal,$Switch,$GetOb);
- if (isset($Loc->PrmLst['once'])) {$x =3D @include_once($File);} else {=
$x =3D @include($File);}
- if ($x=3D=3D=3Dfalse) {
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Parameter =
\'script\'','Field '.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' cann=
ot be merged because file \''.$File.'\' is not found or not readable.',tr=
ue);
- }
- $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal,$Switch,$GetOb);
- }
-
- if ($Loc->FirstMerge) {
- $Loc->FirstMerge =3D false;
- // Check HtmlConv parameter
- if (isset($Loc->PrmLst['htmlconv'])) {
- $x =3D strtolower($Loc->PrmLst['htmlconv']);
- $x =3D '+'.str_replace(' ','',$x).'+';
- if (strpos($x,'+esc+')!=3D=3Dfalse) {tbs_Misc_ConvSpe($Loc); $Loc->C=
onvHtml =3D false; $Loc->ConvEsc =3D true; }
- if (strpos($x,'+wsp+')!=3D=3Dfalse) {tbs_Misc_ConvSpe($Loc); $Loc->C=
onvWS =3D true; }
- if (strpos($x,'+js+')!=3D=3Dfalse) {tbs_Misc_ConvSpe($Loc); $Loc->C=
onvHtml =3D false; $Loc->ConvJS =3D true; }
- if (strpos($x,'+no+')!=3D=3Dfalse) $Loc->ConvHtml =3D false;
- if (strpos($x,'+yes+')!=3D=3Dfalse) $Loc->ConvHtml =3D true;
- if (strpos($x,'+nobr+')!=3D=3Dfalse) {$Loc->ConvHtml =3D true; $Loc->=
ConvBr =3D false; }
- if (strpos($x,'+look+')!=3D=3Dfalse) {tbs_Misc_ConvSpe($Loc); $Loc->C=
onvLook =3D true; }
- } else {
- if ($this->HtmlCharSet=3D=3D=3Dfalse) $Loc->ConvHtml =3D false; // No=
HTML
- }
- // We protect the data that does not come from the source of the templ=
ate
- if (isset($Loc->PrmLst['protect'])) {
- $x =3D strtolower($Loc->PrmLst['protect']);
- switch ($x) {
- case 'no' : $Loc->ConvProtect =3D false; break;
- case 'yes': $Loc->ConvProtect =3D true; break;
- }
- } else {
- if ($this->Protect=3D=3D=3Dfalse) $Loc->ConvProtect =3D false;
- }
- }
-
- // MaxLength
- if (isset($Loc->PrmLst['max'])) {
- $x =3D intval($Loc->PrmLst['max']);
- if (strlen($CurrVal)>$x) {
- if ($Loc->ConvHtml or ($this->HtmlCharSet=3D=3D=3Dfalse)) {
- $CurrVal =3D substr($CurrVal,0,$x-1).$this->MaxEnd;
- } else {
- tbs_Html_Max($CurrVal,$x);
- }
- }
- }
-
- // HTML conversion, and TBS protection
- if ($Loc->ConvSpe) { // Using special parameters
- if ($Loc->ConvLook) {
- $Loc->ConvHtml =3D !tbs_Html_IsHtml($OVal);
- if ($Loc->ConvHtml=3D=3D=3Dfalse) $OVal =3D tbs_Html_GetPart($OVal,'B=
ODY',false,true);
- }
- if ($Loc->ConvHtml) {
- $this->meth_Conv_Html($OVal);
- if ($Loc->ConvBr) $OVal =3D nl2br($OVal);
- }
- if ($Loc->ConvEsc) $OVal =3D str_replace('\'','\'\'',$OVal);
- if ($Loc->ConvWS) {
- $check =3D ' ';
- $nbsp =3D ' ';
- do {
- $pos =3D strpos($OVal,$check);
- if ($pos!=3D=3Dfalse) $OVal =3D substr_replace($OVal,$nbsp,$pos,1);
- } while ($pos!=3D=3Dfalse);
- }
- if ($Loc->ConvJS) {
- $OVal =3D addslashes($OVal); // apply to ('), ("), (\) and (null)
- $OVal =3D str_replace("\n",'\n',$OVal);
- $OVal =3D str_replace("\r",'\r',$OVal);
- $OVal =3D str_replace("\t",'\t',$OVal);
- }
- } elseif ($Loc->ConvHtml) {
- $this->meth_Conv_Html($OVal);
- if ($Loc->ConvBr) $OVal =3D nl2br($OVal);
- }
- if ($Loc->ConvProtect) $OVal =3D str_replace($this->ChrOpen,$this->ChrP=
rotect,$OVal);
- if ($CurrVal!=3D=3D$OVal) $CurrVal =3D str_replace($this->ChrVal,$OVal,=
$CurrVal);
-
- // Case when it's an empty string
- if ($CurrVal=3D=3D=3D'') {
-
- if ($Loc->MagnetId=3D=3D=3Dfalse) {
- if (isset($Loc->PrmLst['.'])) {
- $Loc->MagnetId =3D -1;
- } elseif (isset($Loc->PrmLst['ifempty'])) {
- $Loc->MagnetId =3D -2;
- } elseif (isset($Loc->PrmLst['magnet'])) {
- $Loc->MagnetId =3D 1;
- $Loc->PosBeg0 =3D $Loc->PosBeg;
- $Loc->PosEnd0 =3D $Loc->PosEnd;
- if (isset($Loc->PrmLst['mtype'])) {
- switch ($Loc->PrmLst['mtype']) {
- case 'm+m': $Loc->MagnetId =3D 2; break;
- case 'm*': $Loc->MagnetId =3D 3; break;
- case '*m': $Loc->MagnetId =3D 4; break;
- }
- }
- } else {
- $Loc->MagnetId =3D 0;
- }
- }
-
- switch ($Loc->MagnetId) {
- case 0: break;
- case -1: $CurrVal =3D ' '; break; // Enables to avoid blanks in H=
TML tables
- case -2: $CurrVal =3D $Loc->PrmLst['ifempty']; break;
- case 1:
- $Loc->Enlarged =3D true;
- tbs_Locator_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false,false=
);
- break;
- case 2:
- $Loc->Enlarged =3D true;
- $CurrVal =3D tbs_Locator_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'=
],false,true);
- break;
- case 3:
- $Loc->Enlarged =3D true;
- $Loc2 =3D tbs_Html_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->Pos=
Beg,false,1,false);
- if ($Loc2!=3D=3Dfalse) {
- $Loc->PosBeg =3D $Loc2->PosBeg;
- if ($Loc->PosEnd<$Loc2->PosEnd) $Loc->PosEnd =3D $Loc2->PosEnd;
- }
- break;
- case 4:
- $Loc->Enlarged =3D true;
- $Loc2 =3D tbs_Html_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->Pos=
Beg,true,1,false);
- if ($Loc2!=3D=3Dfalse) $Loc->PosEnd =3D $Loc2->PosEnd;
- break;
- }
- $NewEnd =3D $Loc->PosBeg; // Useful when mtype=3D'm+m'
- } else {
- $NewEnd =3D $Loc->PosBeg + strlen($CurrVal);
- }
-
- $Txt =3D substr_replace($Txt,$CurrVal,$Loc->PosBeg,$Loc->PosEnd-$Loc->P=
osBeg+1);
-
- if ($Select) tbs_Html_MergeItems($Txt,$Loc,$CurrVal,$SelArray,$NewEnd);
-
- return $NewEnd; // Returns the new end position of the field
-
-}
-
-function meth_Locator_FindBlockNext(&$Txt,$BlockName,$PosBeg,$ChrSub,$Sp=
ecial,&$P1,&$FieldBefore) {
-// Return the first block locator object just after the PosBeg position
-// If $Special=3D=3Dtrue =3D> don't set ->BlockSrc and accept TBS Fields=
(used for automatic blocks)
-
- $SearchDef =3D true;
- $FirstField =3D false;
-
- // Search for the first tag with parameter "block"
- while ($SearchDef and ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Block=
Name,$PosBeg,$ChrSub))) {
- if (isset($Loc->PrmLst['block'])) {
- $Block =3D $Loc->PrmLst['block'];
- if ($P1) {
- if (isset($Loc->PrmLst['p1'])) return false;
- } else {
- if (isset($Loc->PrmLst['p1'])) $P1 =3D true;
- }
- $SearchDef =3D false;
- } elseif ($Special) {
- return $Loc;
- } elseif ($FirstField=3D=3D=3Dfalse) {
- $FirstField =3D $Loc;
- }
- $PosBeg =3D $Loc->PosEnd;
- }
-
- if ($SearchDef) {
- if ($FirstField!=3D=3Dfalse) $FieldBefore =3D true;
- return false;
- }
-
- if ($Block=3D=3D=3D'begin') { // Block definied using begin/end
-
- if (($FirstField!=3D=3Dfalse) and ($FirstField->PosEnd<$Loc->PosBeg)) =
$FieldBefore =3D true;
-
- $Opened =3D 1;
- while ($Loc2 =3D $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,$=
ChrSub)) {
- if (isset($Loc2->PrmLst['block'])) {
- switch ($Loc2->PrmLst['block']) {
- case 'end': $Opened--; break;
- case 'begin': $Opened++; break;
- }
- if ($Opened=3D=3D0) {
- if ($Special) {
- $Loc->PosBeg2 =3D $Loc2->PosBeg;
- $Loc->PosEnd2 =3D $Loc2->PosEnd;
- } else {
- $Loc->BlockSrc =3D substr($Txt,$Loc->PosEnd+1,$Loc2->PosBeg-$Loc->=
PosEnd-1);
- $Loc->PosEnd =3D $Loc2->PosEnd;
- $Loc->PosDef =3D 0;
- }
- $Loc->BlockFound =3D true;
- return $Loc;
- }
- }
- $PosBeg =3D $Loc2->PosEnd;
- }
-
- return $this->meth_Misc_Alert('Block definition','At least one block '=
.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' with parameter \'block=3D=
end\' is missing.');
-
- }
-
- if ($Special) {
- $Loc->PosBeg2 =3D false;
- } else {
-
- $Loc->PosDef =3D $Loc->PosBeg;
- if (!$Loc->SubOk) {
- $PosBeg1 =3D $Loc->PosBeg;
- $PosEnd1 =3D $Loc->PosEnd;
- }
- if (tbs_Locator_EnlargeToTag($Txt,$Loc,$Block,true,false)=3D=3D=3Dfals=
e) return $this->meth_Misc_Alert('Block definition',$this->ChrOpen.$Loc->=
FullName.$this->ChrClose.' can not be defined because tag <'.$Loc->PrmLst=
['block'].'> or </'.$Loc->PrmLst['block'].'> is not found.');
- $Loc->PosDef =3D $Loc->PosDef - $Loc->PosBeg;
- if ($Loc->SubOk) {
- $Loc->BlockSrc =3D substr($Txt,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg=
+1);
- $Loc->PosDef++;
- } else {
- $Loc->BlockSrc =3D substr($Txt,$Loc->PosBeg,$PosBeg1-$Loc->PosBeg).su=
bstr($Txt,$PosEnd1+1,$Loc->PosEnd-$PosEnd1); =09
- }
- }
-
- $Loc->BlockFound =3D true;
- if (($FirstField!=3D=3Dfalse) and ($FirstField->PosEnd<$Loc->PosBeg)) $=
FieldBefore =3D true;
- return $Loc; // methods return by ref by default
-
-}
-
-function meth_Locator_FindBlockLst(&$Txt,$BlockName,$Pos) {
-// Return a locator object covering all block definitions, even if there=
is no block definition found.
-
- $LocR =3D& new clsTbsLocator;
- $LocR->P1 =3D false;
- $LocR->FieldOutside =3D false;
- $LocR->BlockNbr =3D 0;
- $LocR->BlockSrc =3D array(); // 1 to BlockNbr
- $LocR->BlockLoc =3D array(); // 1 to BlockNbr
- $LocR->BlockChk =3D array(); // 1 to BlockNbr
- $LocR->BlockName =3D array(); // 1 to BlockNbr
- $LocR->NoDataBid =3D false;
- $LocR->SpecialBid =3D false;
- $LocR->HeaderFound =3D false;
- $LocR->FooterFound =3D false;
- $LocR->WhenFound =3D false;
- $LocR->WhenDefaultBid =3D false;
- $LocR->SectionNbr =3D 0;
- $LocR->SectionBid =3D array(); // 1 to SectionNbr
- $LocR->SectionIsSerial =3D array(); // 1 to SectionNbr
- $LocR->SectionSerialBid =3D array(); // 1 to SectionNbr
- $LocR->SectionSerialOrd =3D array(); // 1 to SectionNbr
- $LocR->SerialEmpty =3D false;
-
- $Bid =3D& $LocR->BlockNbr;
- $Sid =3D& $LocR->SectionNbr;
- $Pid =3D 0;
-
- do {
-
- $Loc =3D $this->meth_Locator_FindBlockNext($Txt,$BlockName,$Pos,'.',fa=
lse,$LocR->P1,$LocR->FieldOutside);
-
- if ($Loc=3D=3D=3Dfalse) {
-
- if ($Pid>0) { // parentgrp mode =3D> disconnect $Txt from the source
- $Src =3D $Txt;
- $Txt =3D& $Parent[$Pid]['txt'];
- if ($LocR->BlockFound) {
- // Redefine the Header block
- $LocR->BlockSrc[$Parent[$Pid]['bid']] =3D substr($Src,0,$LocR->PosB=
eg);
- // Add a Footer block
- tbs_Locator_SectionAddBlk($LocR,$BlockName,substr($Src,$LocR->PosEn=
d+1));
- tbs_Locator_SectionAddGrp($LocR,$Bid,'F',$Parent[$Pid]['fld']);
- }
- // Now gowing down to previous level
- $Pos =3D $Parent[$Pid]['pos'];
- $LocR->PosBeg =3D $Parent[$Pid]['beg'];
- $LocR->PosEnd =3D $Parent[$Pid]['end'];
- $LocR->BlockFound =3D true;
- unset($Parent[$Pid]);
- $Pid--;
- $Loc =3D true;
- }
-
- } else {
-
- $Pos =3D $Loc->PosEnd;
- =09
- // Define the block limits
- if ($LocR->BlockFound) {
- if ( $LocR->PosBeg > $Loc->PosBeg ) $LocR->PosBeg =3D $Loc->PosBeg;
- if ( $LocR->PosEnd < $Loc->PosEnd ) $LocR->PosEnd =3D $Loc->PosEnd;
- } else {
- $LocR->BlockFound =3D true;
- $LocR->PosBeg =3D $Loc->PosBeg;
- $LocR->PosEnd =3D $Loc->PosEnd;
- }
-=09
- // Merge block parameters
- if (count($Loc->PrmLst)>0) $LocR->PrmLst =3D array_merge($LocR->PrmLs=
t,$Loc->PrmLst);
-=09
- // Save the block and cache its tags (incrments $LocR->BlockNbr)
- tbs_Locator_SectionAddBlk($LocR,$BlockName,$Loc->BlockSrc);
-=09
- // Add the text in the list of blocks
- if (isset($Loc->PrmLst['nodata'])) { // Nodata section
- $LocR->NoDataBid =3D $Bid;
- } elseif (isset($Loc->PrmLst['currpage'])) { // Special section (used=
for navigation bar)
- $LocR->SpecialBid =3D $Bid;
- } elseif (isset($Loc->PrmLst['when'])) {
- if ($LocR->WhenFound=3D=3D=3Dfalse) {
- $LocR->WhenFound =3D true;
- $LocR->WhenSeveral =3D false;
- $LocR->WhenNbr =3D 0;
- $LocR->WhenSectionBid[] =3D array(); // Bid of the section to displ=
ay
- $LocR->WhenCondBid[] =3D array(); // Bid of the condition to che=
ck
- $LocR->WhenBeforeNS[] =3D array(); // True if the When section mu=
st be displayed before a=20
- }
- $LocR->WhenNbr++;
- if (isset($Loc->PrmLst['several'])) $LocR->WhenSeveral =3D true;
- $LocR->WhenSectionBid[$LocR->WhenNbr] =3D $Bid;
- $this->meth_Merge_PhpVar($Loc->PrmLst['when'],false);
- tbs_Locator_SectionAddBlk($LocR,$BlockName,$Loc->PrmLst['when']);
- $LocR->WhenCondBid[$LocR->WhenNbr] =3D $Bid;
- $LocR->WhenBeforeNS[$LocR->WhenNbr] =3D ($Sid=3D=3D=3D0);
- } elseif (isset($Loc->PrmLst['default'])) {
- $LocR->WhenDefaultBid =3D $Bid;
- $LocR->WhenDefaultBeforeNS =3D ($Sid=3D=3D=3D0);
- } elseif (isset($Loc->PrmLst['headergrp'])) {
- tbs_Locator_SectionAddGrp($LocR,$Bid,'H',$Loc->PrmLst['headergrp']);
- } elseif (isset($Loc->PrmLst['footergrp'])) {
- tbs_Locator_SectionAddGrp($LocR,$Bid,'F',$Loc->PrmLst['footergrp']);
- } elseif (isset($Loc->PrmLst['splittergrp'])) {
- tbs_Locator_SectionAddGrp($LocR,$Bid,'S',$Loc->PrmLst['splittergrp']=
);
- } elseif (isset($Loc->PrmLst['parentgrp'])) {
- tbs_Locator_SectionAddGrp($LocR,$Bid,'H',$Loc->PrmLst['parentgrp']);
- $Pid++;
- $Parent[$Pid]['bid'] =3D $Bid;
- $Parent[$Pid]['fld'] =3D $Loc->PrmLst['parentgrp'];
- $Parent[$Pid]['txt'] =3D& $Txt;
- $Parent[$Pid]['pos'] =3D $Pos;
- $Parent[$Pid]['beg'] =3D $LocR->PosBeg;
- $Parent[$Pid]['end'] =3D $LocR->PosEnd;
- $Txt =3D& $LocR->BlockSrc[$Bid];
- $Pos =3D $Loc->PosDef + 1;
- $LocR->BlockFound =3D false;
- $LocR->PosBeg =3D false;
- $LocR->PosEnd =3D false;
- } elseif (isset($Loc->PrmLst['serial'])) {
- // Section with Serial Sub-Sections
- $Src =3D& $LocR->BlockSrc[$Bid];
- $Loc0 =3D false;
- if ($LocR->SerialEmpty=3D=3D=3Dfalse) {
- $NameSr =3D $BlockName.'_0';
- $x =3D false;
- $LocSr =3D $this->meth_Locator_FindBlockNext($Src,$NameSr,0,'.',fal=
se,$x,$x);
- if ($LocSr!=3D=3Dfalse) {
- $LocR->SerialEmpty =3D $LocSr->BlockSrc;
- $Src =3D substr_replace($Src,'',$LocSr->PosBeg,$LocSr->PosEnd-$Loc=
Sr->PosBeg+1);
- }
- }
- $NameSr =3D $BlockName.'_1';
- $x =3D false;
- $LocSr =3D $this->meth_Locator_FindBlockNext($Src,$NameSr,0,'.',fals=
e,$x,$x);
- if ($LocSr!=3D=3Dfalse) {
- $Sid++;
- $LocR->SectionBid[$Sid] =3D $Bid;
- $LocR->SectionIsSerial[$Sid] =3D true;
- $LocR->SectionSerialBid[$Sid] =3D array();
- $LocR->SectionSerialOrd[$Sid] =3D array();
- $SrBid =3D& $LocR->SectionSerialBid[$Sid];
- $SrOrd =3D& $LocR->SectionSerialOrd[$Sid];
- $BidParent =3D $Bid;
- $SrNum =3D 1;
- do {
- // Save previous sub-section
- $LocR->BlockLoc[$BidParent][$SrNum] =3D $LocSr;
- tbs_Locator_SectionAddBlk($LocR,$NameSr,$LocSr->BlockSrc);
- $SrBid[$SrNum] =3D $Bid;
- $SrOrd[$SrNum] =3D $SrNum;
- $i =3D $SrNum;
- while (($i>1) and ($LocSr->PosBeg<$LocR->BlockLoc[$BidParent][$SrO=
rd[$i-1]]->PosBeg)) {
- $SrOrd[$i] =3D $SrOrd[$i-1];
- $SrOrd[$i-1] =3D $SrNum;
- $i--;
- }
- // Search next section
- $SrNum++;
- $NameSr =3D $BlockName.'_'.$SrNum;
- $x =3D false;
- $LocSr =3D $this->meth_Locator_FindBlockNext($Src,$NameSr,0,'.',fa=
lse,$x,$x);
- } while ($LocSr!=3D=3Dfalse);
- $SrBid[0] =3D $SrNum-1;
- }
- } else {
- // Normal section
- $Sid++;
- $LocR->SectionBid[$Sid] =3D $Bid;
- $LocR->SectionIsSerial[$Sid] =3D false;
- }
- =09
- }
-
- } while ($Loc!=3D=3Dfalse);
-
- if ($LocR->WhenFound and ($Sid=3D=3D=3D0)) {
- // Add a blank section if When is used without a normal section
- tbs_Locator_SectionAddBlk($LocR,$BlockName,'');
- $Sid++;
- $LocR->SectionBid[$Sid] =3D $Bid;
- $LocR->SectionIsSerial[$Sid] =3D false;
- }
-
- // Calculate Cache
- if ($this->TurboBlock) {
- for ($i=3D1;$i<=3D$LocR->BlockNbr;$i++) {
- $this->meth_Locator_SectionCache($LocR,$i);
- }
- }
-
- return $LocR; // methods return by ref by default
-
-}
-
-function meth_Merge_Block(&$Txt,&$BlockName,&$SrcId,&$Query,$PageSize,$P=
ageNum,$RecKnown) {
-
- // Get source type and info
- $Src =3D& new clsTbsDataSource;
- $Src->BlockName =3D $BlockName;
- if (!$Src->DataPrepare($SrcId,$this)) return 0;
-
- $BlockId =3D 0;
- $BlockLst =3D explode(',',$BlockName);
- $BlockNbr =3D count($BlockLst);
- $WasP1 =3D false;
- $NbrRecTot =3D 0;
- $QueryZ =3D& $Query;
-
- while ($BlockId<$BlockNbr) {
-
- $RecStop =3D 0; // Stop the merge after this row
- $RecSpe =3D 0; // Row with a special block's definition (used for the=
navigation bar)
- $QueryOk =3D true;
- $NoFct =3D true;
- $Src->BlockName =3D trim($BlockLst[$BlockId]);
-
- // Search the block
- $LocR =3D $this->meth_Locator_FindBlockLst($Txt,$Src->BlockName,0);
-
- if ($LocR->BlockFound) {
- if ($LocR->SpecialBid!=3D=3Dfalse) $RecSpe =3D $RecKnown;
- // OnSection
- if (isset($LocR->PrmLst['onsection'])) {
- $LocR->OnSecInfo =3D $LocR->PrmLst['onsection'];
- $ErrMsg =3D false;
- if ($this->meth_Misc_UserFctCheck($LocR->OnSecInfo,$ErrMsg)) {
- $LocR->OnSecPrm =3D array($BlockName,'','','');
- $NoFct =3D false;
- } else {
- $this->meth_Misc_Alert('Block definition \''.$BlockName.'\'',$ErrMs=
g);
- }
- }
- // OnData
- if (isset($LocR->PrmLst['ondata'])) {
- if ($LocR->PrmLst['ondata']!=3D=3D$Src->OnDataSave) {
- $Src->OnDataSave =3D $LocR->PrmLst['ondata'];
- $Src->OnDataInfo =3D $Src->OnDataSave;
- $ErrMsg =3D false;
- if ($this->meth_Misc_UserFctCheck($Src->OnDataInfo,$ErrMsg)) {
- $Src->OnDataPrm =3D array($BlockName,'','');
- } else {
- $Src->OnDataInfo =3D false;
- $this->meth_Misc_Alert('Block definition \''.$BlockName.'\'',$ErrM=
sg);
- }
- }
- }
- // Dynamic query
- if ($LocR->P1) {
- if (is_string($Query)) {
- $Src->RecSaved =3D false;
- unset($QueryZ); $QueryZ =3D ''.$Query;
- $i =3D 1;
- do {
- $x =3D 'p'.$i;
- if (isset($LocR->PrmLst[$x])) {
- $QueryZ =3D str_replace('%p'.$i.'%',$LocR->PrmLst[$x],$QueryZ);
- $i++;
- } else {
- $i =3D false;
- }
- } while ($i!=3D=3Dfalse);
- }
- $WasP1 =3D true;
- } elseif (($Src->RecSaved=3D=3D=3Dfalse) and ($BlockNbr-$BlockId>1)) =
{
- $Src->RecSaving =3D true;
- }
- } else {
- if ($WasP1) {
- $QueryOk =3D false;
- $WasP1 =3D false;
- } else {
- $RecStop =3D 1;
- }
- }
-
- // Open the recordset
- if ($QueryOk) {
- if ((!$LocR->BlockFound) and (!$LocR->FieldOutside)) {
- $QueryOk =3D false;
- } else {
- $QueryOk =3D $Src->DataOpen($QueryZ,$PageSize,$PageNum,$RecStop);
- }
- }
-
- // Merge sections
- if ($QueryOk) {
- if ($Src->Type=3D=3D=3D4) { // Special for Text merge
- if ($LocR->BlockFound) {
- $Src->RecNum =3D 1;
- $Src->CurrRec =3D false;
- if ($NoFct=3D=3D=3Dfalse) {
- $LocR->OnSecPrm[1] =3D& $Src->CurrRec ; $LocR->OnSecPrm[2] =3D& $S=
rc->RecSet; $LocR->OnSecPrm[3] =3D& $Src->RecNum;
- call_user_func_array($LocR->OnSecInfo,$LocR->OnSecPrm);
- }
- $Txt =3D substr_replace($Txt,$Src->RecSet,$LocR->PosBeg,$LocR->PosE=
nd-$LocR->PosBeg+1);
- } else {
- $Src->DataAlert('Can\'t merge the block with a text value because t=
he block definition is not found.');
- }
- } else { // Other data source type
- $Src->DataFetch();
- if ($LocR->BlockFound!=3D=3Dfalse) $this->meth_Merge_BlockSections($=
Txt,$LocR,$Src,$NoFct,$RecSpe,$RecStop);
- // Mode Page: Calculate the value to return
- if (($PageSize>0) and ($Src->RecNum>=3D$RecStop)) {
- if ($RecKnown<0) { // Pass pages in order to count all records
- do {
- $Src->DataFetch();
- } while ($Src->CurrRec!=3D=3Dfalse);
- } else { // We know that there is more records
- if ($RecKnown>$Src->RecNum) $Src->RecNum =3D $RecKnown;
- }
- }
- }
- $Src->DataClose(); // Close the resource
- }
-
- if (!$WasP1) {
- $NbrRecTot +=3D $Src->RecNum;
- if ($LocR->FieldOutside and $QueryOk) {
- // Merge last record on the entire template
- $Pos =3D 0;
- $ChkSub =3D ($Src->CurrRec!=3D=3Dfalse);
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Src->BlockName,$Po=
s,'.')) {
- if ($Loc->SubName=3D=3D=3D'#') {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$Src->RecNum,false)=
;
- } else {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$Src->CurrRec,$ChkS=
ub);
- }
- }
- }
- $BlockId++;
- }
-
- } // -> while ($BlockId<$BlockNbr) {...
-
- // End of the merge
- unset($Src); unset($LocR); return $NbrRecTot;
-
-}
-
-function meth_Merge_BlockSections(&$Txt,&$LocR,&$Src,&$NoFct,&$RecSpe,&$=
RecStop) {
-
- // Initialise
- $SecId =3D 0;
- $SecOk =3D ($LocR->SectionNbr>0);
- $SecIncr =3D true;
- $BlockRes =3D ''; // The result of the chained merged blocks
- $SerialMode =3D false;
- $SerialNum =3D 0;
- $SerialMax =3D 0;
- $SerialTxt =3D array();
- $GrpFound =3D ($LocR->HeaderFound or $LocR->FooterFound);
-
- // Main loop
- //$Src->DataFetch();
- while($Src->CurrRec!=3D=3Dfalse) {
-
- // Headers and Footers
- if ($GrpFound) {
- $grp_change =3D false;
- $grp_src =3D '';
- if ($LocR->FooterFound) {
- $change =3D false;
- for ($i=3D$LocR->FooterNbr;$i>=3D1;$i--) {
- $x =3D $Src->CurrRec[$LocR->FooterField[$i]];
- if ($Src->RecNum=3D=3D=3D1) {
- $LocR->FooterPrevValue[$i] =3D $x;
- } else {
- if ($LocR->FooterIsFooter[$i]) {
- $change_i =3D& $change;
- } else {
- unset($change_i); $change_i =3D false;
- }
- if (!$change_i) $change_i =3D !($LocR->FooterPrevValue[$i]=3D=3D=3D=
$x);
- if ($change_i) {
- $grp_change =3D true;
- $grp_src =3D $this->meth_Merge_SectionNormal($LocR,$LocR->FooterB=
id[$i],$PrevRec,$PrevNum,$PrevKey,$NoFct).$grp_src;
- $LocR->FooterPrevValue[$i] =3D $x;
- }
- }
- }
- $PrevRec =3D $Src->CurrRec;
- $PrevNum =3D $Src->RecNum;
- $PrevKey =3D $Src->RecKey;
- }
- if ($LocR->HeaderFound) {
- $change =3D ($Src->RecNum=3D=3D=3D1);
- for ($i=3D1;$i<=3D$LocR->HeaderNbr;$i++) {
- $x =3D $Src->CurrRec[$LocR->HeaderField[$i]];
- if (!$change) $change =3D !($LocR->HeaderPrevValue[$i]=3D=3D=3D$x);
- if ($change) {
- $grp_src .=3D $this->meth_Merge_SectionNormal($LocR,$LocR->HeaderB=
id[$i],$Src->CurrRec,$Src->RecNum,$Src->RecKey,$NoFct);
- $LocR->HeaderPrevValue[$i] =3D $x;
- }
- }
- $grp_change =3D ($grp_change or $change);
- }
- if ($grp_change) {
- if ($SerialMode) {
- $BlockRes .=3D $this->meth_Merge_SectionSerial($LocR,$SecId,$Serial=
Num,$SerialMax,$SerialTxt);
- $SecIncr =3D true;
- }
- $BlockRes .=3D $grp_src;
- }
- } // end of header and footer
-
- // Increment Section
- if ($SecIncr and $SecOk) {
- $SecId++;
- if ($SecId>$LocR->SectionNbr) $SecId =3D 1;
- $SerialMode =3D $LocR->SectionIsSerial[$SecId];
- if ($SerialMode) {
- $SerialNum =3D 0;
- $SerialMax =3D $LocR->SectionSerialBid[$SecId][0];
- $SecIncr =3D false;
- }
- }
-
- // Serial Mode Activation
- if ($SerialMode) { // Serial Merge
- $SerialNum++;
- $Bid =3D $LocR->SectionSerialBid[$SecId][$SerialNum];
- $SerialTxt[$SerialNum] =3D $this->meth_Merge_SectionNormal($LocR,$Bid=
,$Src->CurrRec,$Src->RecNum,$Src->RecKey,$NoFct);
- if ($SerialNum>=3D$SerialMax) {
- $BlockRes .=3D $this->meth_Merge_SectionSerial($LocR,$SecId,$SerialN=
um,$SerialMax,$SerialTxt);
- $SecIncr =3D true;
- }
- } else { // Classic merge
- if ($Src->RecNum=3D=3D=3D$RecSpe) {
- $Bid =3D $LocR->SpecialBid;
- } else {
- $Bid =3D $LocR->SectionBid[$SecId];
- }
- if ($LocR->WhenFound) { // With conditional blocks
- $x =3D $this->meth_Merge_SectionNormal($LocR,$Bid,$Src->CurrRec,$Src=
->RecNum,$Src->RecKey,$NoFct);
- $found =3D false;
- $continue =3D true;
- $i =3D 1;
- do {
- $cond =3D $this->meth_Merge_SectionNormal($LocR,$LocR->WhenCondBid[=
$i],$Src->CurrRec,$Src->RecNum,$Src->RecKey,$NoFct);
- if (tbs_Misc_CheckCondition($cond)) {
- $x_when =3D $this->meth_Merge_SectionNormal($LocR,$LocR->WhenSecti=
onBid[$i],$Src->CurrRec,$Src->RecNum,$Src->RecKey,$NoFct);
- if ($LocR->WhenBeforeNS[$i]) {$x =3D $x_when.$x;} else {$x =3D $x.=
$x_when;}
- $found =3D true;
- if ($LocR->WhenSeveral=3D=3D=3Dfalse) $continue =3D false;
- }
- $i++;
- if ($i>$LocR->WhenNbr) $continue =3D false;
- } while ($continue);
- if (($found=3D=3D=3Dfalse) and ($LocR->WhenDefaultBid!=3D=3Dfalse)) =
{
- $x_when =3D $this->meth_Merge_SectionNormal($LocR,$LocR->WhenDefaul=
tBid,$Src->CurrRec,$Src->RecNum,$Src->RecKey,$NoFct);
- if ($LocR->WhenDefaultBeforeNS) {$x =3D $x_when.$x;} else {$x =3D $=
x.$x_when;}
- }
- $BlockRes .=3D $x;
- } else { // Without conditional blocks
- $BlockRes .=3D $this->meth_Merge_SectionNormal($LocR,$Bid,$Src->Curr=
Rec,$Src->RecNum,$Src->RecKey,$NoFct);
- }
- }
-
- // Next row
- if ($Src->RecNum=3D=3D=3D$RecStop) {
- $Src->CurrRec =3D false;
- } else {
- // $CurrRec can be set to False by the OnSection event function.
- if ($Src->CurrRec!=3D=3Dfalse) $Src->DataFetch();
- }
-
- } //--> while($CurrRec!=3D=3Dfalse) {
-
- // Serial: merge the extra the sub-blocks
- if ($SerialMode and !$SecIncr) {
- $BlockRes .=3D $this->meth_Merge_SectionSerial($LocR,$SecId,$SerialNum=
,$SerialMax,$SerialTxt);
- }
-
- // Footer
- if ($LocR->FooterFound) {
- if ($Src->RecNum>0) {
- for ($i=3D1;$i<=3D$LocR->FooterNbr;$i++) {
- if ($LocR->FooterIsFooter[$i]) $BlockRes .=3D $this->meth_Merge_Sect=
ionNormal($LocR,$LocR->FooterBid[$i],$PrevRec,$PrevNum,$PrevKey,$NoFct);
- }
- }
- }
-
- // NoData
- if (($Src->RecNum=3D=3D=3D0) and ($LocR->NoDataBid!=3D=3Dfalse)) $Block=
Res =3D $LocR->BlockSrc[$LocR->NoDataBid];
-=09
- // Merge the result
- $Txt =3D substr_replace($Txt,$BlockRes,$LocR->PosBeg,$LocR->PosEnd-$Loc=
R->PosBeg+1);
-
-}
-
-function meth_Merge_PhpVar(&$Txt,$HtmlConv) {
-// Merge the PHP global variables of the main script.
-
- $Pref =3D& $this->VarPrefix;
- $PrefL =3D strlen($Pref);
- $PrefOk =3D ($PrefL>0);
-
- if ($HtmlConv=3D=3D=3Dfalse) {
- $HtmlCharSet =3D $this->HtmlCharSet;
- $this->HtmlCharSet =3D false;
- }
-
- // Then we scann all fields in the model
- $x =3D '';
- $Pos =3D 0;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,'var',$Pos,'.')) {
- if ($Loc->SubNbr>0) {
- if ($Loc->SubLst[0]=3D=3D=3D'') {
- $Pos =3D $this->meth_Merge_System($Txt,$Loc);
- } elseif ($Loc->SubLst[0][0]=3D=3D=3D'~') {
- if (!isset($ObjOk)) $ObjOk =3D (is_object($this->ObjectRef) or is_ar=
ray($this->ObjectRef));
- if ($ObjOk) {
- $Loc->SubLst[0] =3D substr($Loc->SubLst[0],1);
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$this->ObjectRef,tru=
e);
- } elseif (isset($Loc->PrmLst['noerr'])) {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- } else {
- $this->meth_Misc_Alert('Merge ObjectRef sub item','Can\'t merge '.$=
this->ChrOpen.$Loc->FullName.$this->ChrClose.' because property ObjectRef=
is neither an object nor an array. Its type is \''.gettype($this->Object=
Ref).'\'.',true);
- $Pos =3D $Loc->PosEnd + 1;
- }
- } elseif ($PrefOk and (substr($Loc->SubLst[0],0,$PrefL)!=3D=3D$Pref))=
{
- if (isset($Loc->PrmLst['noerr'])) {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- } else {
- $this->meth_Misc_Alert('Merge PHP global variables','Can\'t merge '=
.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' because allowed prefix i=
s set to \''.$Pref.'\'.',true);
- $Pos =3D $Loc->PosEnd + 1;
- }
- } elseif (isset($GLOBALS[$Loc->SubLst[0]])) {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$GLOBALS,true);
- } else {
- if (isset($Loc->PrmLst['noerr'])) {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- } else {
- $Pos =3D $Loc->PosEnd + 1;
- $this->meth_Misc_Alert('Merge PHP global variables','Can\'t merge '=
.$this->ChrOpen.$Loc->FullName.$this->ChrClose.' because there is no PHP =
global variable named \''.$Loc->SubLst[0].'\'.',true);
- }
- }
- }
- }
-
- if ($HtmlConv=3D=3D=3Dfalse) $this->HtmlCharSet =3D $HtmlCharSet;
-
-}
-
-function meth_Merge_System(&$Txt,&$Loc) {
-// This function enables to merge TBS special fields
-
- if (isset($Loc->SubLst[1])) {
- switch ($Loc->SubLst[1]) {
- case 'now':
- $x =3D mktime();
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'version':
- $x =3D '2.05.8';
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'script_name':
- if (isset($_SERVER)) { // PHP<4.1.0 compatibilty
- $x =3D tbs_Misc_GetFilePart($_SERVER['PHP_SELF'],1);
- } else {
- global $HTTP_SERVER_VARS;
- $x =3D tbs_Misc_GetFilePart($HTTP_SERVER_VARS['PHP_SELF'],1);
- }
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'template_name':
- return $this->meth_Locator_Replace($Txt,$Loc,$this->_LastFile,false);
- case 'template_date':
- $x =3D filemtime($this->_LastFile);
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'template_path':
- $x =3D tbs_Misc_GetFilePart($this->_LastFile,0);
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'name':
- $x =3D 'TinyButStrong';
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'logo':
- $x =3D '**TinyButStrong**';
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- case 'charset':
- return $this->meth_Locator_Replace($Txt,$Loc,$this->HtmlCharSet,false=
);
- case 'tplvars':
- if ($Loc->SubNbr=3D=3D2) {
- $x =3D implode(',',array_keys($this->TplVars));
- return $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- } else {
- if (isset($this->TplVars[$Loc->SubLst[2]])) {
- array_shift($Loc->SubLst);
- array_shift($Loc->SubLst);
- $Loc->SubNbr =3D $Loc->SubNbr - 2;
- return $this->meth_Locator_Replace($Txt,$Loc,$this->TplVars,true);
- } else {
- $this->meth_Misc_Alert('System Fields','Can\'t merge ['.$Loc->FullN=
ame.'] because property TplVars doesn\'t have any item named \''.$Loc->Su=
bLst[2].'\'.');
- return $Loc->PosBeg+1;
- }
- }
- case '':
- $this->meth_Misc_Alert('System Fields','Can\'t merge ['.$Loc->FullNam=
e.'] because it doesn\'t have any requested keyword.');
- return $Loc->PosBeg+1;
- default:
- $this->meth_Misc_Alert('System Fields','Can\'t merge ['.$Loc->FullNam=
e.'] because \''.$Loc->SubLst[1].'\' is an unknown keyword.');
- return $Loc->PosBeg+1;
- }
- } else {
- $this->meth_Misc_Alert('System Fields','Can\'t merge ['.$Loc->FullName=
.'] because it doesn\'t have any subname.');
- return $Loc->PosBeg+1;
- }
-
-}
-
-function meth_Merge_Special($Type) {
-// Proceed to one of the special merge
-
- if ($Type=3D=3D=3D'*') $Type =3D 'onload,onshow,var';
-
- $TypeLst =3D explode(',',$Type);
- foreach ($TypeLst as $Type) {
- switch ($Type) {
- case 'var': $this->meth_Merge_PhpVar($this->Source,true); break;
- case 'onload': $this->meth_Merge_Auto($this->Source,'onload',true,true=
); break;
- case 'onshow': $this->meth_Merge_Auto($this->Source,'onshow',false,tru=
e); break;
- }
- }
-
-}
-
-function meth_Merge_SectionNormal(&$LocR,&$BlockId,&$CurrRec,&$RecNum,&$=
RecKey,&$NoFct) {
-
- $Txt =3D $LocR->BlockSrc[$BlockId];
-
- if ($NoFct) {
- $LocLst =3D& $LocR->BlockLoc[$BlockId];
- $iMax =3D $LocLst[0];
- $PosMax =3D strlen($Txt);
- $DoUnCached =3D& $LocR->BlockChk[$BlockId];
- } else {
- $Txt0 =3D $Txt;
- $LocR->OnSecPrm[1] =3D& $CurrRec ; $LocR->OnSecPrm[2] =3D& $Txt; $LocR=
->OnSecPrm[3] =3D& $RecNum;
- call_user_func_array($LocR->OnSecInfo,$LocR->OnSecPrm);
- if ($Txt0=3D=3D=3D$Txt) {
- $LocLst =3D& $LocR->BlockLoc[$BlockId];
- $iMax =3D $LocLst[0];
- $PosMax =3D strlen($Txt);
- $DoUnCached =3D& $LocR->BlockChk[$BlockId];
- } else {
- $iMax =3D 0;
- $DoUnCached =3D true;
- }
- }
-
- if ($RecNum=3D=3D=3Dfalse) { // Erase all fields
-
- $x =3D '';
-
- // Chached locators
- for ($i=3D$iMax;$i>0;$i--) {
- if ($LocLst[$i]->PosBeg<$PosMax) {
- $this->meth_Locator_Replace($Txt,$LocLst[$i],$x,false);
- if ($LocLst[$i]->Enlarged) {
- $PosMax =3D $LocLst[$i]->PosBeg;
- $LocLst[$i]->PosBeg =3D $LocLst[$i]->PosBeg0;
- $LocLst[$i]->PosEnd =3D $LocLst[$i]->PosEnd0;
- $LocLst[$i]->Enlarged =3D false;
- }
- }
- }
-
- // Unchached locators
- if ($DoUnCached) {
- $BlockName =3D& $LocR->BlockName[$BlockId];
- $Pos =3D 0;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$BlockName,$Pos,'.')=
) $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$x,false);
- } =09
-
- } else {
-
- // Chached locators
- for ($i=3D$iMax;$i>0;$i--) {
- if ($LocLst[$i]->PosBeg<$PosMax) {
- if ($LocLst[$i]->IsRecInfo) {
- if ($LocLst[$i]->RecInfo=3D=3D=3D'#') {
- $this->meth_Locator_Replace($Txt,$LocLst[$i],$RecNum,false);
- } else {
- $this->meth_Locator_Replace($Txt,$LocLst[$i],$RecKey,false);
- }
- } else {
- $this->meth_Locator_Replace($Txt,$LocLst[$i],$CurrRec,true);
- }
- if ($LocLst[$i]->Enlarged) {
- $PosMax =3D $LocLst[$i]->PosBeg;
- $LocLst[$i]->PosBeg =3D $LocLst[$i]->PosBeg0;
- $LocLst[$i]->PosEnd =3D $LocLst[$i]->PosEnd0;
- $LocLst[$i]->Enlarged =3D false;
- }
- }
- }
-
- // Unchached locators
- if ($DoUnCached) {
- $BlockName =3D& $LocR->BlockName[$BlockId];
- foreach ($CurrRec as $key =3D> $val) {
- $Pos =3D 0;
- $Name =3D $BlockName.'.'.$key;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Name,$Pos,'.')) {
- $Pos =3D $this->meth_Locator_Replace($Txt,$Loc,$val,true);
- }
- }
- $Pos =3D 0;
- $Name =3D $BlockName.'.#';
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Name,$Pos,'.')) $Po=
s =3D $this->meth_Locator_Replace($Txt,$Loc,$RecNum,true);
- $Pos =3D 0;
- $Name =3D $BlockName.'.$';
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Name,$Pos,'.')) $Po=
s =3D $this->meth_Locator_Replace($Txt,$Loc,$RecKey,true);
- }
-
- }
-
- return $Txt;
-
-}
-
-function meth_Merge_SectionSerial(&$LocR,&$SecId,&$SerialNum,&$SerialMax=
,&$SerialTxt) {
-
- $Txt =3D $LocR->BlockSrc[$LocR->SectionBid[$SecId]];
- $LocLst =3D& $LocR->BlockLoc[$LocR->SectionBid[$SecId]];
- $OrdLst =3D& $LocR->SectionSerialOrd[$SecId];
-
- // Prepare the Empty Item
- if ($SerialNum<$SerialMax) {
- if ($LocR->SerialEmpty=3D=3D=3Dfalse) {
- $F =3D false;
- $NoFct =3D true;
- } else {
- $EmptySrc =3D& $LocR->SerialEmpty;
- }
- }
-
- // All Items
- for ($i=3D$SerialMax;$i>0;$i--) {
- $Sr =3D $OrdLst[$i];
- if ($Sr>$SerialNum) {
- if ($LocR->SerialEmpty=3D=3D=3Dfalse) {
- $k =3D $LocR->SectionSerialBid[$SecId][$Sr];
- $EmptySrc =3D $this->meth_Merge_SectionNormal($LocR,$k,$F,$F,$F,$NoF=
ct);
- }
- $Txt =3D substr_replace($Txt,$EmptySrc,$LocLst[$Sr]->PosBeg,$LocLst[$=
Sr]->PosEnd-$LocLst[$Sr]->PosBeg+1);
- } else {
- $Txt =3D substr_replace($Txt,$SerialTxt[$Sr],$LocLst[$Sr]->PosBeg,$Lo=
cLst[$Sr]->PosEnd-$LocLst[$Sr]->PosBeg+1);
- }
- }
-
- // Update variables
- $SerialNum =3D 0;
- $SerialTxt =3D array();
-
- return $Txt;
-
-}
-
-function meth_Merge_Auto(&$Txt,$Name,$TplVar,$AcceptGrp) {
-// onload - onshow
-
- $GrpDisplayed =3D array();
- $GrpExclusive =3D array();
- $P1 =3D false;
- $FieldBefore =3D false;
- $Pos =3D 0;
-
- if ($AcceptGrp) {
- $ChrSub =3D '_';
- } else {
- $ChrSub =3D '';
- }
-
- while ($LocA=3D$this->meth_Locator_FindBlockNext($Txt,$Name,$Pos,$ChrSu=
b,true,$P1,$FieldBefore)) {
-
- if ($LocA->BlockFound) {
-
- if (!isset($GrpDisplayed[$LocA->SubName])) {
- $GrpDisplayed[$LocA->SubName] =3D false;
- $GrpExclusive[$LocA->SubName] =3D !($AcceptGrp and ($LocA->SubName=3D=
=3D=3D''));
- }
- $Displayed =3D& $GrpDisplayed[$LocA->SubName];
- $Exclusive =3D& $GrpExclusive[$LocA->SubName];
-
- $DelBlock =3D false;
- $DelField =3D false;
- if ($Displayed and $Exclusive) {
- $DelBlock =3D true;
- } else {
- if (isset($LocA->PrmLst['when'])) {
- if (isset($LocA->PrmLst['several'])) $Exclusive=3Dfalse;
- $x =3D $LocA->PrmLst['when'];
- $this->meth_Merge_PhpVar($x,false);
- if (tbs_Misc_CheckCondition($x)) {
- $DelField =3D true;
- $Displayed =3D true;
- } else {
- $DelBlock =3D true;
- }
- } elseif(isset($LocA->PrmLst['default'])) {
- if ($Displayed) {
- $DelBlock =3D true;
- } else {
- $Displayed =3D true;
- $DelField =3D true;
- }
- $Exclusive =3D true; // No more block displayed for the group after=
VisElse
- }
- }
- =09
- // Del parts
- if ($DelField) {
- if ($LocA->PosBeg2!=3D=3Dfalse) $Txt =3D substr_replace($Txt,'',$Loc=
A->PosBeg2,$LocA->PosEnd2-$LocA->PosBeg2+1);
- $Txt =3D substr_replace($Txt,'',$LocA->PosBeg,$LocA->PosEnd-$LocA->P=
osBeg+1);
- $Pos =3D $LocA->PosBeg;
- } else {
- if ($LocA->PosBeg2=3D=3D=3Dfalse) {
- tbs_Locator_EnlargeToTag($Txt,$LocA,$LocA->PrmLst['block'],true,fal=
se);
- } else {
- $LocA->PosEnd =3D $LocA->PosEnd2;
- }
- if ($DelBlock) {
- $Txt =3D substr_replace($Txt,'',$LocA->PosBeg,$LocA->PosEnd-$LocA->=
PosBeg+1);
- } else {
- // Merge the block as if it was a field
- $x =3D '';
- $this->meth_Locator_Replace($Txt,$LocA,$x,false);
- }
- $Pos =3D $LocA->PosBeg;
- }
-
- } else { // Field
-
- // Check for Template Var
- if ($TplVar and isset($LocA->PrmLst['tplvars'])) {
- $Ok =3D false;
- foreach ($LocA->PrmLst as $Key =3D> $Val) {
- if ($Ok) {
- $this->TplVars[$Key] =3D $Val;
- } else {
- if ($Key=3D=3D=3D'tplvars') $Ok =3D true;
- }
- }
- }
-
- $x =3D '';
- $Pos =3D $this->meth_Locator_Replace($Txt,$LocA,$x,false);
- $Pos =3D $LocA->PosBeg;
-
- }
-
- }
-
- return count($GrpDisplayed);
-
-}
-
-function meth_Merge_NavigationBar(&$Txt,$BlockName,$Options,$PageCurr,$R=
ecCnt,$PageSize) {
-
- // Get block parameters
- $PosBeg =3D 0;
- $PrmLst =3D array();
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,'.'=
)) {
- if (isset($Loc->PrmLst['block'])) $PrmLst =3D array_merge($PrmLst,$Loc=
->PrmLst);
- $PosBeg =3D $Loc->PosEnd;
- }
-
- // Prepare options
- if (!is_array($Options)) $Options =3D array('navsize'=3D>intval($Option=
s));
- $Options =3D array_merge($Options,$PrmLst);
-
- // Default options
- if (!isset($Options['navsize'])) $Options['navsize'] =3D 10;
- if (!isset($Options['navpos'])) $Options['navpos'] =3D 'step';
- if (!isset($Options['navdel'])) $Options['navdel'] =3D '';
- if (!isset($Options['pagemin'])) $Options['pagemin'] =3D 1;
-
- // Check options
- if ($Options['navsize']<=3D0) $Options['navsize'] =3D 10;
- if ($PageSize<=3D0) $PageSize =3D 1;
- if ($PageCurr<$Options['pagemin']) $PageCurr =3D $Options['pagemin'];
-
- $CurrPos =3D 0;
- $CurrNav =3D array('curr'=3D>$PageCurr,'first'=3D>$Options['pagemin'],'=
last'=3D>-1,'bound'=3D>false);
-
- // Calculate displayed PageMin and PageMax
- if ($Options['navpos']=3D=3D'centred') {
- $PageMin =3D $Options['pagemin']-1+$PageCurr - intval(floor($Options['=
navsize']/2));
- } else {
- // Display by block
- $PageMin =3D $Options['pagemin']-1+$PageCurr - ( ($PageCurr-1) % $Opti=
ons['navsize']);
- }
- $PageMin =3D max($PageMin,$Options['pagemin']);
- $PageMax =3D $PageMin + $Options['navsize'] - 1;
-
- // Calculate previous and next pages
- $CurrNav['prev'] =3D $PageCurr - 1;
- if ($CurrNav['prev']<$Options['pagemin']) {
- $CurrNav['prev'] =3D $Options['pagemin'];
- $CurrNav['bound'] =3D $Options['pagemin'];
- }
- $CurrNav['next'] =3D $PageCurr + 1;
- if ($RecCnt>=3D0) {
- $PageCnt =3D $Options['pagemin']-1 + intval(ceil($RecCnt/$PageSize));
- $PageMax =3D min($PageMax,$PageCnt);
- $PageMin =3D max($Options['pagemin'],$PageMax-$Options['navsize']+1);
- } else {
- $PageCnt =3D $Options['pagemin']-1;
- }
- if ($PageCnt>=3D$Options['pagemin']) {
- if ($PageCurr>=3D$PageCnt) {
- $CurrNav['next'] =3D $PageCnt;
- $CurrNav['last'] =3D $PageCnt;
- $CurrNav['bound'] =3D $PageCnt;
- } else {
- $CurrNav['last'] =3D $PageCnt;
- }
- }=09
-
- // Display or hide the bar
- if ($Options['navdel']=3D=3D'') {
- $Display =3D true;
- } else {
- $Display =3D (($PageMax-$PageMin)>0);
- }
-
- // Merge general information
- $Pos =3D 0;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$BlockName,$Pos,'.')) =
{
- $Pos =3D $Loc->PosBeg + 1;
- $x =3D strtolower($Loc->SubName);
- if (isset($CurrNav[$x])) {
- $Val =3D $CurrNav[$x];
- if ($CurrNav[$x]=3D=3D$CurrNav['bound']) {
- if (isset($Loc->PrmLst['endpoint'])) {
- $Val =3D '';
- }
- }
- $this->meth_Locator_Replace($Txt,$Loc,$Val,false);
- }
- }
-
- // Merge pages
- $Query =3D '';
- if ($Display) {
- $Data =3D array();
- $RecSpe =3D 0;
- $RecCurr =3D 0;
- for ($PageId=3D$PageMin;$PageId<=3D$PageMax;$PageId++) {
- $RecCurr++;
- if ($PageId=3D=3D$PageCurr) $RecSpe =3D $RecCurr;
- $Data[] =3D array('page'=3D>$PageId);
- }
- $this->meth_Merge_Block($Txt,$BlockName,$Data,$Query,0,0,$RecSpe);
- if ($Options['navdel']!=3D'') { // Delete the block definition tags
- $PosBeg =3D 0;
- while ($Loc =3D $this->meth_Locator_FindTbs($Txt,$Options['navdel'],$=
PosBeg,'.')) {
- $PosBeg =3D $Loc->PosBeg;
- $Txt =3D substr_replace($Txt,'',$Loc->PosBeg,$Loc->PosEnd-$Loc->PosB=
eg+1);
- }
- }
- } else {
- if ($Options['navdel']!=3D'') {
- $SrcType =3D 'text';
- $this->meth_Merge_Block($Txt,$Options['navdel'],$SrcType,$Query,0,0,0=
);
- }
- }
-
-}
-
-// Convert a string to Html with several options
-function meth_Conv_Html(&$Txt) {
- if ($this->HtmlCharSet=3D=3D=3D'') {
- $Txt =3D htmlspecialchars($Txt); // Faster
- } elseif ($this->_HtmlCharFct) {
- $Txt =3D call_user_func($this->HtmlCharSet,$Txt);
- } else {
- $Txt =3D htmlspecialchars($Txt,ENT_COMPAT,$this->HtmlCharSet);
- }
-}
-
-// Standard alert message provided by TinyButStrong, return False is the=
message is cancelled.
-function meth_Misc_Alert($Source,$Message,$NoErrMsg=3Dfalse) {
- $x =3D '<br /><b>TinyButStrong Error</b> ('.$Source.'): '.htmlentities(=
$Message);
- if ($NoErrMsg) $x =3D $x.' <em>This message can be cancelled using para=
meter \'noerr\'.</em>';
- $x =3D $x."<br />\n";
- $x =3D str_replace($this->ChrOpen,$this->ChrProtect,$x);
- echo $x;
- return false;
-}
-
-function meth_Misc_ChangeMode($Init,&$Loc,&$CurrVal,$Switch,$GetOb) {
- if ($Init) {
- // Save contents configuration
- if ($Switch) {
- $Loc->SaveSrc =3D& $this->Source;
- $Loc->SaveRender =3D $this->Render;
- $Loc->SaveCache =3D $this->_CacheFile;
- $Loc->SaveMode =3D $this->_Mode;
- unset($this->Source); $this->Source =3D '';
- $this->Render =3D TBS_OUTPUT;
- $this->_CacheFile =3D false;
- $this->_Mode =3D 1;
- $File =3D $Loc->PrmLst['subtpl'];
- if (is_string($File) and (strlen($File)>0)) {
- $this->meth_Merge_PhpVar($File,false);
- $File =3D str_replace($this->ChrVal,$CurrVal,$File);
- if (tbs_Misc_GetFile($this->Source,$File)) {
- $this->meth_Merge_Auto($this->Source,'onload',true,true);
- } else {
- if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert('Paramete=
r subtpl','Unable to read the file \''.$File.'\'.');
- }
- }
- }
- if ($GetOb) ob_start();
- } else {
- // Restore contents configuration
- if ($Switch) {
- $this->Source =3D& $Loc->SaveSrc;
- $this->Render =3D $Loc->SaveRender;
- $this->_CacheFile =3D $Loc->SaveCache;
- $this->_Mode =3D $Loc->SaveMode;
- }
- if ($GetOb) {
- $CurrVal =3D ob_get_contents();
- ob_end_clean();
- }
- $Loc->ConvHtml =3D false;
- $Loc->ConvProtect =3D false;
- }
-}
-
-function meth_Misc_UserFctCheck(&$FctInfo,&$ErrMsg) {
- if (substr($FctInfo,0,1)=3D=3D=3D'~') {
- $ObjRef =3D& $this->ObjectRef;
- $Lst =3D explode('.',substr($FctInfo,1));
- $iMax =3D count($Lst) - 1;
- for ($i=3D0;$i<=3D$iMax;$i++) {
- $x =3D& $Lst[$i];
- if (is_object($ObjRef)) {
- if (method_exists($ObjRef,$x)) {
- if ($i=3D=3D=3D$iMax) {
- $FctInfo =3D array(&$ObjRef,$x);
- } else {
- $ObjRef =3D call_user_func(array(&$ObjRef,$x));
- }
- } elseif ($i=3D=3D=3D$iMax) {
- $ErrMsg =3D 'Expression \''.$FctInfo.'\' is invalid because \''.$x.=
'\' is not a method in the class \''.get_class($ObjRef).'\'.';
- return false;
- } elseif (isset($ObjRef->$x)) {
- $ObjRef =3D& $ObjRef->$x;
- } else {
- $ErrMsg =3D 'Expression \''.$FctInfo.'\' is invalid because sub-ite=
m \''.$x.'\' is neither a method nor a property in the class \''.get_clas=
s($ObjRef).'\'.';
- return false;
- }
- } elseif (($i<$iMax) and is_array($ObjRef)) {
- if (isset($ObjRef[$x])) {
- $ObjRef =3D& $ObjRef[$x];
- } else {
- $ErrMsg =3D 'Expression \''.$FctInfo.'\' is invalid because sub-ite=
m \''.$x.'\' is not a existing key in the array.';
- return false;
- }
- } else {
- $ErrMsg =3D 'Expression \''.$FctInfo.'\' is invalid because '.(($i=3D=
=3D=3D0)?'property ObjectRef':'sub-item \''.$x.'\'').' is not an object'.=
(($i<$iMax)?' or an array.':'.');
- return false;
- }
- }
- } else {
- if (!function_exists($FctInfo)) {
- $ErrMsg =3D 'Custom function \''.$FctInfo.'\' is not found.';
- return false;
- }
- }
- return true;
-}
-
-function meth_Cache_Save($CacheFile,&$Txt) {
- $fid =3D @fopen($CacheFile, 'w');
- if ($fid=3D=3D=3Dfalse) {
- $this->meth_Misc_Alert('Cache System','The cache file \''.$CacheFile.'=
\' can not be saved.');
- return false;
- } else {
- flock($fid,2); // acquire an exlusive lock
- fwrite($fid,$Txt);
- flock($fid,3); // release the lock
- fclose($fid);
- return true;
- }
-}
-
-} // class clsTinyButStrong
-
-// *********************************************
-
-function tbs_Misc_ConvSpe(&$Loc) {
- if ($Loc->ConvSpe=3D=3D=3Dfalse) {
- $Loc->ConvSpe =3D true;
- $Loc->ConvEsc =3D false;
- $Loc->ConvWS =3D false;
- $Loc->ConvJS =3D false;
- $Loc->ConvLook =3D false;
- }
-}
-
-function tbs_Misc_GetStrId($Txt) {
- $Txt =3D strtolower($Txt);
- $Txt =3D str_replace('-','_',$Txt);
- $x =3D '';
- $i =3D 0;
- $iMax =3D strlen($Txt2);
- while ($i<$iMax) {
- if (($Txt[$i]=3D=3D=3D'_') or (($Txt[$i]>=3D'a') and ($Txt[$i]<=3D'z')=
) or (($Txt[$i]>=3D'0') and ($Txt[$i]<=3D'9'))) {
- $x .=3D $Txt[$i];
- $i++;
- } else {
- $i =3D $iMax;
- }
- }
- return $x;
-}
-
-function tbs_Misc_CheckCondition($Str) {
-// Check if an expression like "exrp1=3Dexpr2" is true or false.
-
- // Find operator and position
- $Ope =3D '=3D';
- $Len =3D 1;
- $Max =3D strlen($Str)-1;
- $Pos =3D strpos($Str,$Ope);
- if ($Pos=3D=3D=3Dfalse) {
- $Ope =3D '+';
- $Pos =3D strpos($Str,$Ope);
- if ($Pos=3D=3D=3Dfalse) return false;
- if (($Pos>0) and ($Str[$Pos-1]=3D=3D=3D'-')) {
- $Ope =3D '-+'; $Pos--; $Len=3D2;
- } elseif (($Pos<$Max) and ($Str[$Pos+1]=3D=3D=3D'-')) {
- $Ope =3D '+-'; $Len=3D2;
- } else {
- return false;
- }
- } else {
- if ($Pos>0) {
- $x =3D $Str[$Pos-1];
- if ($x=3D=3D=3D'!') {
- $Ope =3D '!=3D'; $Pos--; $Len=3D2;
- } elseif ($Pos<$Max) {
- $y =3D $Str[$Pos+1];
- if ($y=3D=3D=3D'=3D') {
- $Len=3D2;
- } elseif (($x=3D=3D=3D'+') and ($y=3D=3D=3D'-')) {
- $Ope =3D '+=3D-'; $Pos--; $Len=3D3;
- } elseif (($x=3D=3D=3D'-') and ($y=3D=3D=3D'+')) {
- $Ope =3D '-=3D+'; $Pos--; $Len=3D3;
- }
- } else {
- }
- }
- }
-
- // Read values
- $Val1 =3D trim(substr($Str,0,$Pos));
- $Nude1 =3D tbs_Misc_DelDelimiter($Val1,'\'');
- $Val2 =3D trim(substr($Str,$Pos+$Len));
- $Nude2 =3D tbs_Misc_DelDelimiter($Val2,'\'');
-
- // Compare values
- if ($Ope=3D=3D=3D'=3D') {
- return (strcasecmp($Val1,$Val2)=3D=3D0);
- } elseif ($Ope=3D=3D=3D'!=3D') {
- return (strcasecmp($Val1,$Val2)!=3D0);
- } else {
- if ($Nude1) $Val1 =3D (float) $Val1;
- if ($Nude2) $Val2 =3D (float) $Val2;
- if ($Ope=3D=3D=3D'+-') {
- return ($Val1>$Val2);
- } elseif ($Ope=3D=3D=3D'-+') {
- return ($Val1 < $Val2);
- } elseif ($Ope=3D=3D=3D'+=3D-') {
- return ($Val1 >=3D $Val2);
- } elseif ($Ope=3D=3D=3D'-=3D+') {
- return ($Val1<=3D$Val2);
- } else {
- return false;
- }
- }
-
-}
-
-function tbs_Misc_DelDelimiter(&$Txt,$Delim) {
-// Delete the string delimiters
- $len =3D strlen($Txt);
- if (($len>1) and ($Txt[0]=3D=3D=3D$Delim)) {
- if ($Txt[$len-1]=3D=3D=3D$Delim) $Txt =3D substr($Txt,1,$len-2);
- return false;
- } else {
- return true;
- }
-}
-
-function tbs_Misc_GetFile(&$Txt,$File) {
-// Load the content of a file into the text variable.
- $Txt =3D '';
- $fd =3D @fopen($File, 'r'); // 'rb' if binary for some OS
- if ($fd=3D=3D=3Dfalse) return false;
- $fs =3D @filesize($File); // return False for an URL
- if ($fs=3D=3D=3Dfalse) {
- while (!feof($fd)) $Txt .=3D fread($fd,4096);
- } else {
- if ($fs>0) $Txt =3D fread($fd,$fs);
- }=09
- fclose($fd);
- return true;
-}
-
-function tbs_Misc_GetFilePart($File,$Part) {
- $Pos =3D strrpos($File,'/');
- if ($Part=3D=3D=3D0) { // Path
- if ($Pos=3D=3D=3Dfalse) {
- return '';
- } else {
- return substr($File,0,$Pos+1);
- }
- } else { // File
- if ($Pos=3D=3D=3Dfalse) {
- return $File;
- } else {
- return substr($File,$Pos+1);
- }
- }
-}
-
-function tbs_Misc_Format(&$Loc,&$Value) {
-// This function return the formated representation of a Date/Time or nu=
meric variable using a 'VB like' format syntax instead of the PHP syntax.
-
- global $_tbs_FrmSimpleLst;
-
- $FrmStr =3D $Loc->PrmLst['frm'];
- $CheckNumeric =3D true;
- if (is_string($Value)) $Value =3D trim($Value);
-
- // Manage Multi format strings
- if (strpos($FrmStr,'|')!=3D=3Dfalse) {
-
- global $_tbs_FrmMultiLst;
-
- // Save the format if it doesn't exist
- if (isset($_tbs_FrmMultiLst[$FrmStr])) {
- $FrmLst =3D& $_tbs_FrmMultiLst[$FrmStr];
- } else {
- $FrmLst =3D explode('|',$FrmStr); // syntax : PostiveFrm|NegativeFrm|=
ZeroFrm|NullFrm
- $FrmNbr =3D count($FrmLst);
- if (($FrmNbr<=3D1) or ($FrmLst[1]=3D=3D=3D'')) {
- $FrmLst[1] =3D& $FrmLst[0]; // negativ
- $FrmLst['abs'] =3D false;
- } else {
- $FrmLst['abs'] =3D true;
- }
- if (($FrmNbr<=3D2) or ($FrmLst[2]=3D=3D=3D'')) $FrmLst[2] =3D& $FrmLs=
t[0]; // zero
- if (($FrmNbr<=3D3) or ($FrmLst[3]=3D=3D=3D'')) $FrmLst[3] =3D ''; // =
null
- $_tbs_FrmMultiLst[$FrmStr] =3D $FrmLst;
- }
-
- // Select the format
- if (is_numeric($Value)) {
- if (is_string($Value)) $Value =3D 0.0 + $Value;
- if ($Value>0) {
- $FrmStr =3D& $FrmLst[0];
- } elseif ($Value<0) {
- $FrmStr =3D& $FrmLst[1];
- if ($FrmLst['abs']) $Value =3D abs($Value);
- } else { // zero
- $FrmStr =3D& $FrmLst[2];
- $Minus =3D '';
- }
- $CheckNumeric =3D false;
- } else {
- $Value =3D ''.$Value;
- if ($Value=3D=3D=3D'') {
- return $FrmLst[3]; // Null value
- } else {
- $t =3D strtotime($Value); // We look if it's a date
- if ($t=3D=3D=3D-1) { // Date not recognized
- return $FrmLst[1];
- } elseif ($t=3D=3D=3D943916400) { // Date to zero
- return $FrmLst[2];
- } else { // It's a date
- $Value =3D $t;
- $FrmStr =3D& $FrmLst[0];
- }
- }
- }
-
- }
-
- if ($FrmStr=3D=3D=3D'') return ''.$Value;
-
- // Retrieve the correct simple format
- if (!isset($_tbs_FrmSimpleLst[$FrmStr])) tbs_Misc_FormatSave($FrmStr);
-
- $Frm =3D& $_tbs_FrmSimpleLst[$FrmStr];
-
- switch ($Frm['type']) {
- case 'num' :
- // NUMERIC
- if ($CheckNumeric) {
- if (is_numeric($Value)) {
- if (is_string($Value)) $Value =3D 0.0 + $Value;
- } else {
- return ''.$Value;
- }
- }
- if ($Frm['PerCent']) $Value =3D $Value * 100;
- $Value =3D number_format($Value,$Frm['DecNbr'],$Frm['DecSep'],$Frm['Th=
sSep']);
- return substr_replace($FrmStr,$Value,$Frm['Pos'],$Frm['Len']);
- break;
- case 'date' :
- // DATE
- if (is_string($Value)) {
- if ($Value=3D=3D=3D'') return '';
- $x =3D strtotime($Value);
- if ($x=3D=3D=3D-1) {
- if (!is_numeric($Value)) $Value =3D 0;
- } else {
- $Value =3D& $x;
- }
- } else {
- if (!is_numeric($Value)) return ''.$Value;
- }
- if (isset($Loc->PrmLst['locale'])) {
- return strftime($Frm['str_loc'],$Value);
- } else {
- return date($Frm['str_us'],$Value);
- }
- break;
- default:
- return $Frm['string'];
- break;
- }
-
-}
-
-function tbs_Misc_FormatSave(&$FrmStr) {
-
- global $_tbs_FrmSimpleLst;
-
- $nPosEnd =3D strrpos($FrmStr,'0');
-
- if ($nPosEnd!=3D=3Dfalse) {
-
- // Numeric format
- $nDecSep =3D '.';
- $nDecNbr =3D 0;
- $nDecOk =3D true;
-
- if (substr($FrmStr,$nPosEnd+1,1)=3D=3D=3D'.') {
- $nPosEnd++;
- $nPosCurr =3D $nPosEnd;
- } else {
- $nPosCurr =3D $nPosEnd - 1;
- while (($nPosCurr>=3D0) and ($FrmStr[$nPosCurr]=3D=3D=3D'0')) {
- $nPosCurr--;
- }
- if (($nPosCurr>=3D1) and ($FrmStr[$nPosCurr-1]=3D=3D=3D'0')) {
- $nDecSep =3D $FrmStr[$nPosCurr];
- $nDecNbr =3D $nPosEnd - $nPosCurr;
- } else {
- $nDecOk =3D false;
- }
- }
-
- // Thousand separator
- $nThsSep =3D '';
- if (($nDecOk) and ($nPosCurr>=3D5)) {
- if ((substr($FrmStr,$nPosCurr-3,3)=3D=3D=3D'000') and ($FrmStr[$nPosC=
urr-4]!=3D=3D'') and ($FrmStr[$nPosCurr-5]=3D=3D=3D'0')) {
- $nPosCurr =3D $nPosCurr-4;
- $nThsSep =3D $FrmStr[$nPosCurr];
- }
- }
-
- // Pass next zero
- if ($nDecOk) $nPosCurr--;
- while (($nPosCurr>=3D0) and ($FrmStr[$nPosCurr]=3D=3D=3D'0')) {
- $nPosCurr--;
- }
-
- // Percent
- $nPerCent =3D (strpos($FrmStr,'%')=3D=3D=3Dfalse) ? false : true;
-
- $_tbs_FrmSimpleLst[$FrmStr] =3D array('type'=3D>'num','Pos'=3D>($nPosC=
urr+1),'Len'=3D>($nPosEnd-$nPosCurr),'ThsSep'=3D>$nThsSep,'DecSep'=3D>$nD=
ecSep,'DecNbr'=3D>$nDecNbr,'PerCent'=3D>$nPerCent);
-
- } else { // if ($nPosEnd!=3D=3Dfalse)
-
- // Date format
- $FrmPHP =3D '';
- $FrmLOC =3D '';
- $Local =3D false;
- $StrIn =3D false;
- $iMax =3D strlen($FrmStr);
- $Cnt =3D 0;
-
- for ($i=3D0;$i<$iMax;$i++) {
-
- if ($StrIn) {
- // We are in a string part
- if ($FrmStr[$i]=3D=3D=3D$StrChr) {
- if (substr($FrmStr,$i+1,1)=3D=3D=3D$StrChr) {
- $FrmPHP .=3D '\\'.$FrmStr[$i]; // protected char
- $FrmLOC .=3D $FrmStr[$i];
- $i++;
- } else {
- $StrIn =3D false;
- }
- } else {
- $FrmPHP .=3D '\\'.$FrmStr[$i]; // protected char
- $FrmLOC .=3D $FrmStr[$i];
- }
- } else {
- if (($FrmStr[$i]=3D=3D=3D'"') or ($FrmStr[$i]=3D=3D=3D'\'')) {
- // Check if we have the opening string char
- $StrIn =3D true;
- $StrChr =3D $FrmStr[$i];
- } else {
- $Cnt++;
- if (strcasecmp(substr($FrmStr,$i,4),'yyyy')=3D=3D=3D0) { $FrmPH=
P .=3D 'Y'; $FrmLOC .=3D '%Y'; $i +=3D 3; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'yy' )=3D=3D=3D0) { $FrmPH=
P .=3D 'y'; $FrmLOC .=3D '%y'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,4),'mmmm')=3D=3D=3D0) { $FrmPH=
P .=3D 'F'; $FrmLOC .=3D '%B'; $i +=3D 3; }
- elseif (strcasecmp(substr($FrmStr,$i,3),'mmm' )=3D=3D=3D0) { $FrmPH=
P .=3D 'M'; $FrmLOC .=3D '%b'; $i +=3D 2; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'mm' )=3D=3D=3D0) { $FrmPH=
P .=3D 'm'; $FrmLOC .=3D '%m'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,1),'m' )=3D=3D=3D0) { $FrmPH=
P .=3D 'n'; $FrmLOC .=3D '%m'; }
- elseif (strcasecmp(substr($FrmStr,$i,4),'wwww')=3D=3D=3D0) { $FrmPH=
P .=3D 'l'; $FrmLOC .=3D '%A'; $i +=3D 3; }
- elseif (strcasecmp(substr($FrmStr,$i,3),'www' )=3D=3D=3D0) { $FrmPH=
P .=3D 'D'; $FrmLOC .=3D '%a'; $i +=3D 2; }
- elseif (strcasecmp(substr($FrmStr,$i,1),'w' )=3D=3D=3D0) { $FrmPH=
P .=3D 'w'; $FrmLOC .=3D '%u'; }
- elseif (strcasecmp(substr($FrmStr,$i,4),'dddd')=3D=3D=3D0) { $FrmPH=
P .=3D 'l'; $FrmLOC .=3D '%A'; $i +=3D 3; }
- elseif (strcasecmp(substr($FrmStr,$i,3),'ddd' )=3D=3D=3D0) { $FrmPH=
P .=3D 'D'; $FrmLOC .=3D '%a'; $i +=3D 2; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'dd' )=3D=3D=3D0) { $FrmPH=
P .=3D 'd'; $FrmLOC .=3D '%d'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,1),'d' )=3D=3D=3D0) { $FrmPH=
P .=3D 'j'; $FrmLOC .=3D '%d'; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'hh' )=3D=3D=3D0) { $FrmPH=
P .=3D 'H'; $FrmLOC .=3D '%H'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'nn' )=3D=3D=3D0) { $FrmPH=
P .=3D 'i'; $FrmLOC .=3D '%M'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'ss' )=3D=3D=3D0) { $FrmPH=
P .=3D 's'; $FrmLOC .=3D '%S'; $i +=3D 1; }
- elseif (strcasecmp(substr($FrmStr,$i,2),'xx' )=3D=3D=3D0) { $FrmPH=
P .=3D 'S'; $FrmLOC .=3D '' ; $i +=3D 1; }
- else {
- $FrmPHP .=3D '\\'.$FrmStr[$i]; // protected char
- $FrmLOC .=3D $FrmStr[$i]; // protected char
- $Cnt--;
- }
- }
- } //-> if ($StrIn) {...} else
-
- } //-> for ($i=3D0;$i<$iMax;$i++)
-
- if ($Cnt>0) {
- $_tbs_FrmSimpleLst[$FrmStr] =3D array('type'=3D>'date','str_us'=3D>$F=
rmPHP,'str_loc'=3D>$FrmLOC);
- } else {
- $_tbs_FrmSimpleLst[$FrmStr] =3D array('type'=3D>'else','string'=3D>$F=
rmStr);
- }
-
- } // if ($nPosEnd!=3D=3Dfalse) {...} else
-
-}
-
-function tbs_Locator_SectionAddBlk(&$LocR,$BlockName,$Txt) {
- $LocR->BlockNbr++;
- $LocR->BlockName[$LocR->BlockNbr] =3D $BlockName;
- $LocR->BlockSrc[$LocR->BlockNbr] =3D $Txt;
- $LocR->BlockLoc[$LocR->BlockNbr] =3D array(0=3D>0);
- $LocR->BlockChk[$LocR->BlockNbr] =3D true;
- return $LocR->BlockNbr;
-}
-
-function tbs_Locator_SectionAddGrp(&$LocR,$Bid,$Type,$Field) {
-
- if ($Type=3D=3D=3D'H') {
- if ($LocR->HeaderFound=3D=3D=3Dfalse) {
- $LocR->HeaderFound =3D true;
- $LocR->HeaderNbr =3D 0;
- $LocR->HeaderBid =3D array(); // 1 to HeaderNbr
- $LocR->HeaderPrevValue =3D array(); // 1 to HeaderNbr
- $LocR->HeaderField =3D array(); // 1 to HeaderNbr
- }
- $LocR->HeaderNbr++;
- $LocR->HeaderBid[$LocR->HeaderNbr] =3D $Bid;
- $LocR->HeaderPrevValue[$LocR->HeaderNbr] =3D false;
- $LocR->HeaderField[$LocR->HeaderNbr] =3D $Field;
- } else {
- if ($LocR->FooterFound=3D=3D=3Dfalse) {
- $LocR->FooterFound =3D true;
- $LocR->FooterNbr =3D 0;
- $LocR->FooterBid =3D array(); // 1 to FooterNbr
- $LocR->FooterPrevValue =3D array(); // 1 to FooterNbr
- $LocR->FooterField =3D array(); // 1 to FooterNbr
- $LocR->FooterIsFooter =3D array(); // 1 to FooterNbr
- }
- $LocR->FooterNbr++;
- $LocR->FooterBid[$LocR->FooterNbr] =3D $Bid;
- $LocR->FooterPrevValue[$LocR->FooterNbr] =3D false;
- if ($Type=3D=3D=3D'F') {
- $LocR->FooterField[$LocR->FooterNbr] =3D $Field;
- $LocR->FooterIsFooter[$LocR->FooterNbr] =3D true;
- } else {
- $LocR->FooterField[$LocR->FooterNbr] =3D $Field;
- $LocR->FooterIsFooter[$LocR->FooterNbr] =3D false;
- }
- }
-=09
-}
-
-function tbs_Locator_PrmRead(&$Txt,$Pos,$HtmlTag,$DelimChrs,$BegStr,$End=
Str,&$Loc,&$PosEnd) {
-
- // =C0 mettre dans la classe TBS
- $BegLen =3D strlen($BegStr);
- $BegChr =3D $BegStr[0];
- $BegIs1 =3D ($BegLen=3D=3D=3D1);
-
- $DelimIdx =3D false;
- $DelimCnt =3D 0;
- $DelimChr =3D '';
- $BegCnt =3D 0;
- $SubName =3D $Loc->SubOk;
-=09
- $Status =3D 0; // 0: name not started, 1: name started, 2: name ended, =
3: equal found, 4: value started
- $PosName =3D 0;
- $PosNend =3D 0;
- $PosVal =3D 0;
-=09
- // Param=E8tres de v=E9rif de la boucle
- $PosEnd =3D strpos($Txt,$EndStr,$Pos);
- if ($PosEnd=3D=3D=3Dfalse) return;
- $Continue =3D ($Pos<$PosEnd);
-=09
- while ($Continue) {
- =09
- $Chr =3D $Txt[$Pos];
-
- if ($DelimIdx) { // Lecture dans une cha=EEne
-
- if ($Chr=3D=3D=3D$DelimChr) { // Quote rencontr=E9
- if ($Chr=3D=3D=3D$Txt[$Pos+1]) { // Double quote =3D> la cha=EEne co=
ntinue en d=E9doublant le quote
- $Pos++;
- } else { // Simple quote =3D> fin de la cha=EEne
- $DelimIdx =3D false;
- }
- }
-
- } else { // Lecture hors cha=EEne
- =09
- if ($BegCnt=3D=3D=3D0) {
- =09
- // Analyse des param=E8tre
- $CheckChr =3D false;
- if ($Chr=3D=3D=3D' ') {
- if ($Status=3D=3D=3D1) {
- $Status =3D 2;
- $PosNend =3D $Pos;
- } elseif ($HtmlTag and ($Status=3D=3D=3D4)) {
- tbs_Locator_PrmCompute($Txt,$Loc,$SubName,$Status,$HtmlTag,$DelimC=
hr,$DelimCnt,$PosName,$PosNend,$PosVal,$Pos);
- $Status =3D 0;
- }
- } elseif (($HtmlTag=3D=3D=3Dfalse) and ($Chr=3D=3D=3D';')) {
- tbs_Locator_PrmCompute($Txt,$Loc,$SubName,$Status,$HtmlTag,$DelimCh=
r,$DelimCnt,$PosName,$PosNend,$PosVal,$Pos);
- $Status =3D 0;
- } elseif ($Status=3D=3D=3D4) {
- $CheckChr =3D true;
- } elseif ($Status=3D=3D=3D3) {
- $Status =3D 4;
- $DelimCnt =3D 0;
- $PosVal =3D $Pos;
- $CheckChr =3D true;
- } elseif ($Status=3D=3D=3D2) {
- if ($Chr=3D=3D=3D'=3D') {
- $Status =3D 3;
- } elseif ($HtmlTag) {
- tbs_Locator_PrmCompute($Txt,$Loc,$SubName,$Status,$HtmlTag,$DelimC=
hr,$DelimCnt,$PosName,$PosNend,$PosVal,$Pos);
- $Status =3D 1;
- $PosName =3D $Pos;
- $CheckChr =3D true;
- } else {
- $Status =3D 4;
- $DelimCnt =3D 0;
- $PosVal =3D $Pos;
- $CheckChr =3D true;
- }
- } elseif ($Status=3D=3D=3D1) {
- if ($Chr=3D=3D=3D'=3D') {
- $Status =3D 3;
- $PosNend =3D $Pos;
- } else {
- $CheckChr =3D true;
- }
- } else {
- $Status =3D 1;
- $PosName =3D $Pos;
- $CheckChr =3D true;
- }
- =09
- if ($CheckChr) {
- $DelimIdx =3D strpos($DelimChrs,$Chr);
- if ($DelimIdx=3D=3D=3Dfalse) {
- if ($Chr=3D=3D=3D$BegChr) {
- if ($BegIs1) {
- $BegCnt++;
- } elseif(substr($Txt,$Pos,$BegLen)=3D=3D=3D$BegStr) {
- $BegCnt++;
- }
- }
- } else {
- $DelimChr =3D $DelimChrs[$DelimIdx];
- $DelimCnt++;
- $DelimIdx =3D true;
- }
- }
- =09
- } else {
- if ($Chr=3D=3D=3D$BegChr) {
- if ($BegIs1) {
- $BegCnt++;
- } elseif(substr($Txt,$Pos,$BegLen)=3D=3D=3D$BegStr) {
- $BegCnt++;
- }
- }
- }
- =09
- }
- =09
- // Charact=E8re suivant
- $Pos++;
-
- // On v=E9rifie si c'est la fin
- if ($Pos=3D=3D=3D$PosEnd) {
- if ($DelimIdx=3D=3D=3Dfalse) {
- if ($BegCnt>0) {
- $BegCnt--;
- } else {
- $Continue =3D false;
- }
- }
- if ($Continue) {
- $PosEnd =3D strpos($Txt,$EndStr,$PosEnd+1);
- if ($PosEnd=3D=3D=3Dfalse) return;
- } else {
- tbs_Locator_PrmCompute($Txt,$Loc,$SubName,$Status,$HtmlTag,$DelimChr=
,$DelimCnt,$PosName,$PosNend,$PosVal,$Pos);
- }
- }
-=09
- }
-=09
- $PosEnd =3D $PosEnd + (strlen($EndStr)-1);
-
-}
-
-function tbs_Locator_PrmCompute(&$Txt,&$Loc,&$SubName,$Status,$HtmlTag,$=
DelimChr,$DelimCnt,$PosName,$PosNend,$PosVal,$Pos) {
-=09
- if ($Status=3D=3D=3D0) {
- $SubName =3D false;
- } else {
- if ($Status=3D=3D=3D1) {
- $x =3D substr($Txt,$PosName,$Pos-$PosName);
- } else {
- $x =3D substr($Txt,$PosName,$PosNend-$PosName);
- }
- if ($HtmlTag) $x =3D strtolower($x);
- if ($SubName) {
- $Loc->SubName =3D $x;
- $SubName =3D false;
- } elseif ($Status=3D=3D=3D4) {
- $v =3D trim(substr($Txt,$PosVal,$Pos-$PosVal));
- if ($DelimCnt=3D=3D=3D1) { // Delete quotes inside the value
- if ($v[0]=3D=3D=3D$DelimChr) {
- $len =3D strlen($v);
- if ($v[$len-1]=3D=3D=3D$DelimChr) {
- $v =3D substr($v,1,$len-2);
- $v =3D str_replace($DelimChr.$DelimChr,$DelimChr,$v);
- }
- }
- }
- $Loc->PrmLst[$x] =3D $v;
- } else {
- $Loc->PrmLst[$x] =3D true;
- }
- }
-
-}
-
-function tbs_Locator_EnlargeToStr(&$Txt,&$Loc,$StrBeg,$StrEnd) {
-/*
-This function enables to enlarge the pos limits of the Locator.
-If the search result is not correct, $PosBeg must not change its value, =
and $PosEnd must be False.
-This is because of the calling function.
-*/
-
- // Search for the begining string
- $Pos =3D $Loc->PosBeg;
- $Ok =3D false;
- do {
- $Pos =3D strrpos(substr($Txt,0,$Pos),$StrBeg[0]);
- if ($Pos!=3D=3Dfalse) {
- if (substr($Txt,$Pos,strlen($StrBeg))=3D=3D=3D$StrBeg) $Ok =3D true;
- }
- } while ( (!$Ok) and ($Pos!=3D=3Dfalse) );
-
- if ($Ok) {
- $PosEnd =3D strpos($Txt,$StrEnd,$Loc->PosEnd + 1);
- if ($PosEnd=3D=3D=3Dfalse) {
- $Ok =3D false;
- } else {
- $Loc->PosBeg =3D $Pos;
- $Loc->PosEnd =3D $PosEnd + strlen($StrEnd) - 1;
- }
- }
-
- return $Ok;
-
-}
-
-function tbs_Locator_EnlargeToTag(&$Txt,&$Loc,$Tag,$IsBlock,$ReturnSrc) =
{
-//Modify $Loc, return false if tags not found, returns the source of the=
locator if $ReturnSrc=3Dtrue
-
- if ($Tag=3D=3D=3D'') { return false; }
- elseif ($Tag=3D=3D=3D'row') {$Tag =3D 'tr'; }
- elseif ($Tag=3D=3D=3D'opt') {$Tag =3D 'option'; }
-
- $RetVal =3D true;
- $Encaps =3D 1;
- if ($IsBlock and isset($Loc->PrmLst['encaps'])) $Encaps =3D abs(intval(=
$Loc->PrmLst['encaps']));
-
- $TagO =3D tbs_Html_FindTag($Txt,$Tag,true,$Loc->PosBeg-1,false,$Encaps,=
false);
- if ($TagO=3D=3D=3Dfalse) return false;
- $TagC =3D tbs_Html_FindTag($Txt,$Tag,false,$Loc->PosEnd+1,true,$Encaps,=
false);
- if ($TagC=3D=3Dfalse) return false;
- $PosBeg =3D $TagO->PosBeg;
- $PosEnd =3D $TagC->PosEnd;
-
- if ($IsBlock) {
- =09
- $ExtendFw =3D false;
- $ExtendBw =3D false;
- if (isset($Loc->PrmLst['extend'])) {
- $s =3D ',';
- $x =3D str_replace(' ','',''.$Loc->PrmLst['extend']);
- if (is_numeric($x)) {
- $x =3D intval($Loc->PrmLst['extend']);
- if ($x>0) {
- $lst =3D& $ExtendFw;
- } else {
- $lst =3D& $ExtendBw;
- }
- $x =3D str_repeat($Tag.$s,abs($x));
- } else {
- $lst =3D& $ExtendFw;
- }
- $lst =3D explode($s,$x);
- } =09
- =09
- if ($ExtendFw!=3D=3Dfalse) { // Forward
- $TagC =3D true;
- foreach ($ExtendFw as $Tag) {
- if (($Tag!=3D=3D'') and ($TagC!=3D=3Dfalse)) {
- $TagO =3D tbs_Html_FindTag($Txt,$Tag,true,$PosEnd+1,true,1,false);
- if ($TagO!=3D=3Dfalse) {
- $TagC =3D tbs_Html_FindTag($Txt,$Tag,false,$TagO->PosEnd+1,true,0,=
false);
- if ($TagC!=3D=3Dfalse) {
- $PosEnd =3D $TagC->PosEnd;
- }
- }
- }
- }
- }
- =09
- if ($ExtendBw!=3D=3Dfalse) { // Backward
- $TagO =3D true;
- for ($i=3Dcount($ExtendBw)-1;$i>=3D0;$i--) {
- $Tag =3D $ExtendBw[$i];
- if (($Tag!=3D=3D'') and ($TagO!=3D=3Dfalse)) {
- $TagC =3D tbs_Html_FindTag($Txt,$Tag,false,$PosBeg-1,false,1,false)=
;
- if ($TagC!=3D=3Dfalse) {
- $TagO =3D tbs_Html_FindTag($Txt,$Tag,true,$TagC->PosBeg-1,false,0,=
false);
- if ($TagO!=3D=3Dfalse) {
- $PosBeg =3D $TagO->PosBeg;
- }
- }
- }
- }
- }
- =09
- } elseif ($ReturnSrc) {
- =09
- $RetVal =3D '';
- if ($Loc->PosBeg>$TagO->PosEnd) $RetVal .=3D substr($Txt,$TagO->PosEnd=
+1,min($Loc->PosBeg,$TagC->PosBeg)-$TagO->PosEnd-1);
- if ($Loc->PosEnd<$TagC->PosBeg) $RetVal .=3D substr($Txt,max($Loc->Pos=
End,$TagO->PosEnd)+1,$TagC->PosBeg-max($Loc->PosEnd,$TagO->PosEnd)-1);
- =09
- }
-
- $Loc->PosBeg =3D $PosBeg;
- $Loc->PosEnd =3D $PosEnd;
- return $RetVal;
-
-}
-
-function tbs_Html_Max(&$Txt,&$Nbr) {
-// Limit the number of HTML chars
-
- $pMax =3D strlen($Txt)-1;
- $p=3D0;
- $n=3D0;
- $in =3D false;
- $ok =3D true;
-
- while ($ok) {
- if ($in) {
- if ($Txt[$p]=3D=3D=3D';') {
- $in =3D false;
- $n++;
- }
- } else {
- if ($Txt[$p]=3D=3D=3D'&') {
- $in =3D true;
- } else {
- $n++;
- }
- }
- if (($n>=3D$Nbr) or ($p>=3D$pMax)) {
- $ok =3D false;
- } else {
- $p++;
- }
- }
-
- if (($n>=3D$Nbr) and ($p<$pMax)) $Txt =3D substr($Txt,0,$p).'...';
-
-}
-
-function tbs_Html_IsHtml(&$Txt) {
-// This function returns True if the text seems to have some HTML tags.
-
- // Search for opening and closing tags
- $pos =3D strpos($Txt,'<');
- if ( ($pos!=3D=3Dfalse) and ($pos<strlen($Txt)-1) ) {
- $pos =3D strpos($Txt,'>',$pos + 1);
- if ( ($pos!=3D=3Dfalse) and ($pos<strlen($Txt)-1) ) {
- $pos =3D strpos($Txt,'</',$pos + 1);
- if ( ($pos!=3D=3Dfalse)and ($pos<strlen($Txt)-1) ) {
- $pos =3D strpos($Txt,'>',$pos + 1);
- if ($pos!=3D=3Dfalse) return true;
- }
- }
- }
-
- // Search for special char
- $pos =3D strpos($Txt,'&');
- if ( ($pos!=3D=3Dfalse) and ($pos<strlen($Txt)-1) ) {
- $pos2 =3D strpos($Txt,';',$pos+1);
- if ($pos2!=3D=3Dfalse) {
- $x =3D substr($Txt,$pos+1,$pos2-$pos-1); // We extract the found text=
between the couple of tags
- if (strlen($x)<=3D10) {
- if (strpos($x,' ')=3D=3D=3Dfalse) return true;
- }
- }
- }
-
- // Look for a simple tag
- $Loc1 =3D tbs_Html_FindTag($Txt,'BR',true,0,true,0,false); // line brea=
k
- if ($Loc1!=3D=3Dfalse) return true;
- $Loc1 =3D tbs_Html_FindTag($Txt,'HR',true,0,true,0,false); // horizonta=
l line
- if ($Loc1!=3D=3Dfalse) return true;
-
- return false;
-
-}
-
-function tbs_Html_GetPart(&$Txt,$Tag,$WithTags=3Dfalse,$CancelIfEmpty=3D=
false) {
-// This function returns a part of the HTML document (HEAD or BODY)
-// The $CancelIfEmpty parameter enables to cancel the extraction when th=
e part is not found.
-
- $x =3D false;
-
- $LocOpen =3D tbs_Html_FindTag($Txt,$Tag,true,0,true,0,false);
- if ($LocOpen!=3D=3Dfalse) {
- $LocClose =3D tbs_Html_FindTag($Txt,$Tag,false,$LocOpen->PosEnd+1,true=
,0,false);
- if ($LocClose!=3D=3Dfalse) {
- if ($WithTags) {
- $x =3D substr($Txt,$LocOpen->PosBeg,$LocClose->PosEnd - $LocOpen->Po=
sBeg + 1);
- } else {
- $x =3D substr($Txt,$LocOpen->PosEnd+1,$LocClose->PosBeg - $LocOpen->=
PosEnd - 1);
- }
- }
- }
-
- if ($x=3D=3D=3Dfalse) {
- if ($CancelIfEmpty) {
- $x =3D $Txt;
- } else {
- $x =3D '';
- }
- }
-
- return $x;
-
-}
-
-function tbs_Html_InsertAttribute(&$Txt,&$Attr,$Pos) {
- // Check for XHTML end characters
- if ($Txt[$Pos-1]=3D=3D=3D'/') {
- $Pos--;
- if ($Txt[$Pos-1]=3D=3D=3D' ') $Pos--;
- }
- // Insert the parameter
- $Txt =3D substr_replace($Txt,$Attr,$Pos,0);
-}
-
-function tbs_Html_FindTag(&$Txt,$Tag,$Opening,$PosBeg,$Forward,$Encaps,$=
WithPrm) {
-/* This function is a smarter issue to find an HTML tag.
-It enables to ignore full opening/closing couple of tag that could be in=
serted before the searched tag.
-It also enables to pass a number of encapsulations.
-To ignore encapsulation and opengin/closing just set $Encaps=3D0.
-*/
- if ($Forward) {
- $Pos =3D $PosBeg - 1;
- } else {
- $Pos =3D $PosBeg + 1;
- }
- $TagIsOpening =3D false;
- $TagClosing =3D '/'.$Tag;
- if ($Opening) {
- $EncapsEnd =3D $Encaps;
- } else {
- $EncapsEnd =3D - $Encaps;
- }
- $EncapsCnt =3D 0;
- $TagOk =3D false;
-
- do {
-
- // Look for the next tag def
- if ($Forward) {
- $Pos =3D strpos($Txt,'<',$Pos+1);
- } else {
- if ($Pos<=3D0) {
- $Pos =3D false;
- } else {
- $Pos =3D strrpos(substr($Txt,0,$Pos - 1),'<');
- }
- }
-
- if ($Pos!=3D=3Dfalse) {
- // Check the name of the tag
- if (strcasecmp(substr($Txt,$Pos+1,strlen($Tag)),$Tag)=3D=3D0) {
- $PosX =3D $Pos + 1 + strlen($Tag); // The next char
- $TagOk =3D true;
- $TagIsOpening =3D true;
- } elseif (strcasecmp(substr($Txt,$Pos+1,strlen($TagClosing)),$TagClos=
ing)=3D=3D0) {
- $PosX =3D $Pos + 1 + strlen($TagClosing); // The next char
- $TagOk =3D true;
- $TagIsOpening =3D false;
- }
-
- if ($TagOk) {
- // Check the next char
- if (($Txt[$PosX]=3D=3D=3D' ') or ($Txt[$PosX]=3D=3D=3D'>')) {
- // Check the encapsulation count
- if ($EncapsEnd=3D=3D0) {
- // No encaplusation check
- if ($TagIsOpening!=3D=3D$Opening) $TagOk =3D false;
- } else {
- // Count the number of encapsulation
- if ($TagIsOpening) {
- $EncapsCnt++;
- } else {
- $EncapsCnt--;
- }
- // Check if it's the expected count
- if ($EncapsCnt!=3D$EncapsEnd) $TagOk =3D false;
- }
- } else {
- $TagOk =3D false;
- }
- } //--> if ($TagOk)
-
- }
- } while (($Pos!=3D=3Dfalse) and ($TagOk=3D=3D=3Dfalse));
-
- // Search for the end of the tag
- if ($TagOk) {
- $Loc =3D& new clsTbsLocator;
- if ($WithPrm) {
- $PosEnd =3D 0;
- tbs_Locator_PrmRead($Txt,$PosX,true,'\'"','<','>',$Loc,$PosEnd);
- } else {
- $PosEnd =3D strpos($Txt,'>',$PosX);
- if ($PosEnd=3D=3D=3Dfalse) {
- $TagOk =3D false;
- }
- }
- }
-
- // Result
- if ($TagOk) {
- $Loc->PosBeg =3D $Pos;
- $Loc->PosEnd =3D $PosEnd;
- return $Loc;
- } else {
- return false;
- }
-
-}
-
-function tbs_Html_MergeItems(&$Txt,&$Loc,&$SelValue,&$SelArray,&$NewEnd)=
{
-// Merge items of a list, or radio or check buttons.
-// At this point, the Locator is already merged with $SelValue.
-
- if ($Loc->PrmLst['selected']=3D=3D=3Dtrue) {
- $IsList =3D true;
- $MainTag =3D 'SELECT';
- $ItemTag =3D 'OPTION';
- $ItemPrm =3D 'selected';
- } else {
- $IsList =3D false;
- $MainTag =3D 'FORM';
- $ItemTag =3D 'INPUT';
- $ItemPrm =3D 'checked';
- }
- if (isset($Loc->PrmLst['selbounds'])) $MainTag =3D $Loc->PrmLst['selbou=
nds'];
- $ItemPrmZ =3D ' '.$ItemPrm.'=3D"'.$ItemPrm.'"';
-
- $TagO =3D tbs_Html_FindTag($Txt,$MainTag,true,$Loc->PosBeg-1,false,0,fa=
lse);
-
- if ($TagO!=3D=3Dfalse) {
-
- $TagC =3D tbs_Html_FindTag($Txt,$MainTag,false,$Loc->PosBeg,true,0,fal=
se);
- if ($TagC!=3D=3Dfalse) {
-
- // We get the main block without the main tags
- $MainSrc =3D substr($Txt,$TagO->PosEnd+1,$TagC->PosBeg - $TagO->PosEn=
d -1);
-
- if ($IsList) {
- // Information about the item that was used for the TBS field
- $Item0Beg =3D $Loc->PosBeg - ($TagO->PosEnd+1);
- $Item0Src =3D '';
- $Item0Ok =3D false;
- } else {
- // We delete the merged value
- $MainSrc =3D substr_replace($MainSrc,'',$Loc->PosBeg - ($TagO->PosEn=
d+1), strlen($SelValue));
- }
-
- // Now, we going to scan all of the item tags
- $Pos =3D 0;
- $SelNbr =3D 0;
- while ($ItemLoc =3D tbs_Html_FindTag($MainSrc,$ItemTag,true,$Pos,true=
,0,true)) {
-
- // we get the value of the item
- $ItemValue =3D false;
-
- if ($IsList) {
- // Look for the end of the item
- $OptCPos =3D strpos($MainSrc,'<',$ItemLoc->PosEnd+1);
- if ($OptCPos=3D=3D=3Dfalse) $OptCPos =3D strlen($MainSrc);
- if (($Item0Ok=3D=3D=3Dfalse) and ($ItemLoc->PosBeg<$Item0Beg) and (=
$Item0Beg<=3D$OptCPos)) {
- // If it's the original item, we save it and delete it.
- if (($OptCPos+1<strlen($MainSrc)) and ($MainSrc[$OptCPos+1]=3D=3D=3D=
'/')) {
- $OptCPos =3D strpos($MainSrc,'>',$OptCPos);
- if ($OptCPos=3D=3D=3Dfalse) {
- $OptCPos =3D strlen($MainSrc);
- } else {
- $OptCPos++;
- }
- }
- $Item0Src =3D substr($MainSrc,$ItemLoc->PosBeg,$OptCPos-$ItemLoc->=
PosBeg);
- $MainSrc =3D substr_replace($MainSrc,'',$ItemLoc->PosBeg,strlen($I=
tem0Src));
- if (!isset($ItemLoc->PrmLst[$ItemPrm])) tbs_Html_InsertAttribute($=
Item0Src,$ItemPrmZ,$ItemLoc->PosEnd-$ItemLoc->PosBeg);
- $OptCPos =3D min($ItemLoc->PosBeg,strlen($MainSrc)-1);
- $Select =3D false;
- $Item0Ok =3D true;
- } else {
- if (isset($ItemLoc->PrmLst['value'])) {
- $ItemValue =3D $ItemLoc->PrmLst['value'];
- } else { // The value of the option is its caption.
- $ItemValue =3D substr($MainSrc,$ItemLoc->PosEnd+1,$OptCPos - $Ite=
mLoc->PosEnd - 1);
- $ItemValue =3D str_replace(chr(9),' ',$ItemValue);
- $ItemValue =3D str_replace(chr(10),' ',$ItemValue);
- $ItemValue =3D str_replace(chr(13),' ',$ItemValue);
- $ItemValue =3D trim($ItemValue);
- }
- }
- $Pos =3D $OptCPos;
- } else {
- if ((isset($ItemLoc->PrmLst['name'])) and (isset($ItemLoc->PrmLst['=
value']))) {
- if (strcasecmp($Loc->PrmLst['selected'],$ItemLoc->PrmLst['name'])=3D=
=3D0) {
- $ItemValue =3D $ItemLoc->PrmLst['value'];
- }
- }
- $Pos =3D $ItemLoc->PosEnd;
- }
-
- if ($ItemValue!=3D=3Dfalse) {
- // we look if we select the item
- $Select =3D false;
- if ($SelArray=3D=3D=3Dfalse) {
- if (strcasecmp($ItemValue,$SelValue)=3D=3D0) {
- if ($SelNbr=3D=3D0) $Select =3D true;
- }
- } else {
- if (array_search($ItemValue,$SelArray,false)!=3D=3Dfalse) $Select =
=3D true;
- }
- // Select the item
- if ($Select) {
- if (!isset($ItemLoc->PrmLst[$ItemPrm])) {
- tbs_Html_InsertAttribute($MainSrc,$ItemPrmZ,$ItemLoc->PosEnd);
- $Pos =3D $Pos + strlen($ItemPrmZ);
- if ($IsList and ($ItemLoc->PosBeg<$Item0Beg)) $Item0Beg =3D $Item=
0Beg + strlen($ItemPrmZ);
- }
- $SelNbr++;
- }
- }
-
- } //--> while ($ItemLoc =3D ... ) {
-
- if ($IsList) {
- // Add the original item if it's not found
- if (($SelArray=3D=3D=3Dfalse) and ($SelNbr=3D=3D0)) $MainSrc =3D $Ma=
inSrc.$Item0Src;
- $NewEnd =3D $TagO->PosEnd;
- } else {
- $NewEnd =3D $Loc->PosBeg;
- }
-
- $Txt =3D substr_replace($Txt,$MainSrc,$TagO->PosEnd+1,$TagC->PosBeg-$=
TagO->PosEnd-1);
-
- } //--> if ($TagC!=3D=3Dfalse) {
- } //--> if ($TagO!=3D=3Dfalse) {
-
-
-}
-
-function tbs_Cache_IsValide($CacheFile,$TimeOut) {
-// Return True if there is a existing valid cache for the given file id.
- if (file_exists($CacheFile)) {
- if (time()-filemtime($CacheFile)>$TimeOut) {
- return false;
- } else {
- return true;
- }
- } else {
- return false;
- }
-}
-
-function tbs_Cache_File($Dir,$CacheId,$Mask) {
-// Return the cache file path for a given Id.
- if (strlen($Dir)>0) {
- if ($Dir[strlen($Dir)-1]<>'/') {
- $Dir .=3D '/';
- }
- }
- return $Dir.str_replace('*',$CacheId,$Mask);
-}
-
-function tbs_Cache_DeleteAll($Dir,$Mask) {
-
- if (strlen($Dir)=3D=3D0) {
- $Dir =3D '.';
- }
- if ($Dir[strlen($Dir)-1]<>'/') {
- $Dir .=3D '/';
- }
- $DirObj =3D dir($Dir);
- $Nbr =3D 0;
- $PosL =3D strpos($Mask,'*');
- $PosR =3D strlen($Mask) - $PosL - 1;
-
- // Get the list of cache files
- $FileLst =3D array();
- while ($FileName =3D $DirObj->read()) {
- $FullPath =3D $Dir.$FileName;
- if (strtolower(filetype($FullPath))=3D=3D=3D'file') {
- if (strlen($FileName)>=3Dstrlen($Mask)) {
- if ((substr($FileName,0,$PosL)=3D=3D=3Dsubstr($Mask,0,$PosL)) and (s=
ubstr($FileName,-$PosR)=3D=3D=3Dsubstr($Mask,-$PosR))) {
- $FileLst[] =3D $FullPath;
- }
- }
- }
- }
- // Delete all listed files
- foreach ($FileLst as $FullPath) {
- if (@unlink($FullPath)) $Nbr++;
- }
-
- return $Nbr;
-
-}
-
-?>
\ No newline at end of file
--=20
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que est=E1 limpio.
For all your IT requirements visit: http://www.transtec.co.uk
Más información sobre la lista de distribución Alba-desarrollo