PageRenderTime 58ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/xkid_framework/template/tbs_class_php5.php

http://xfw-xkid-framework.googlecode.com/
PHP | 3324 lines | 2817 code | 330 blank | 177 comment | 765 complexity | c175d61c9f1d9b63ad2b37e09eea37bf MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. ********************************************************
  4. TinyButStrong - Template Engine for Pro and Beginners
  5. ------------------------
  6. Version : 3.4.0 for PHP 5
  7. Date : 2008-06-06
  8. Web site : http://www.tinybutstrong.com
  9. Author : http://www.tinybutstrong.com/onlyyou.html
  10. ********************************************************
  11. This library is free software.
  12. You can redistribute and modify it even for commercial usage,
  13. but you must accept and respect the LPGL License version 2.1.
  14. */
  15. // Check PHP version
  16. if (PHP_VERSION<'5.0') echo '<br><b>TinyButStrong Error</b> (PHP Version Check) : Your PHP version is '.PHP_VERSION.' while TinyButStrong needs PHP version 5.0 or higher. You should try with TinyButStrong Edition for PHP 4.';
  17. // Render flags
  18. define('TBS_NOTHING', 0);
  19. define('TBS_OUTPUT', 1);
  20. define('TBS_EXIT', 2);
  21. // Plug-ins actions
  22. define('TBS_INSTALL', -1);
  23. define('TBS_ISINSTALLED', -3);
  24. // *********************************************
  25. class clsTbsLocator {
  26. public $PosBeg = false;
  27. public $PosEnd = false;
  28. public $Enlarged = false;
  29. public $FullName = false;
  30. public $SubName = '';
  31. public $SubOk = false;
  32. public $SubLst = array();
  33. public $SubNbr = 0;
  34. public $PrmLst = array();
  35. public $PrmIfNbr = false;
  36. public $MagnetId = false;
  37. public $BlockFound = false;
  38. public $FirstMerge = true;
  39. public $ConvProtect = true;
  40. public $ConvHtml = true;
  41. public $ConvMode = 1; // Normal
  42. public $ConvBr = true;
  43. }
  44. // *********************************************
  45. class clsTbsDataSource {
  46. public $Type = false;
  47. public $SubType = 0;
  48. public $SrcId = false;
  49. public $Query = '';
  50. public $RecSet = false;
  51. public $RecKey = '';
  52. public $RecNum = 0;
  53. public $RecNumInit = 0;
  54. public $RecSaving = false;
  55. public $RecSaved = false;
  56. public $RecBuffer = false;
  57. public $CurrRec = false;
  58. public $TBS = false;
  59. public $OnDataOk = false;
  60. public $OnDataPrm = false;
  61. public $OnDataPrmDone = array();
  62. public $OnDataPi = false;
  63. function DataAlert($Msg) {
  64. return $this->TBS->meth_Misc_Alert('when merging block '.$this->TBS->_ChrOpen.$this->TBS->_CurrBlock.$this->TBS->_ChrClose,$Msg);
  65. }
  66. function DataPrepare(&$SrcId,&$TBS) {
  67. $this->SrcId =& $SrcId;
  68. $this->TBS =& $TBS;
  69. $FctInfo = false;
  70. $FctObj = false;
  71. if (is_array($SrcId)) {
  72. $this->Type = 0;
  73. } elseif (is_resource($SrcId)) {
  74. $Key = get_resource_type($SrcId);
  75. switch ($Key) {
  76. case 'mysql link' : $this->Type = 6; break;
  77. case 'mysql link persistent' : $this->Type = 6; break;
  78. case 'mysql result' : $this->Type = 6; $this->SubType = 1; break;
  79. case 'pgsql link' : $this->Type = 7; break;
  80. case 'pgsql link persistent' : $this->Type = 7; break;
  81. case 'pgsql result' : $this->Type = 7; $this->SubType = 1; break;
  82. case 'sqlite database' : $this->Type = 8; break;
  83. case 'sqlite database (persistent)' : $this->Type = 8; break;
  84. case 'sqlite result' : $this->Type = 8; $this->SubType = 1; break;
  85. default :
  86. $FctInfo = $Key;
  87. $FctCat = 'r';
  88. }
  89. } elseif (is_string($SrcId)) {
  90. switch (strtolower($SrcId)) {
  91. case 'array' : $this->Type = 0; $this->SubType = 1; break;
  92. case 'clear' : $this->Type = 0; $this->SubType = 3; break;
  93. case 'mysql' : $this->Type = 6; $this->SubType = 2; break;
  94. case 'text' : $this->Type = 2; break;
  95. case 'num' : $this->Type = 1; break;
  96. default :
  97. $FctInfo = $SrcId;
  98. $FctCat = 'k';
  99. }
  100. } elseif (is_object($SrcId)) {
  101. $FctInfo = get_class($SrcId);
  102. $FctCat = 'o';
  103. $FctObj =& $SrcId;
  104. $this->SrcId =& $SrcId;
  105. } elseif ($SrcId===false) {
  106. $this->DataAlert('the specified source is set to FALSE. Maybe your connection has failed.');
  107. } else {
  108. $this->DataAlert('unsupported variable type : \''.gettype($SrcId).'\'.');
  109. }
  110. if ($FctInfo!==false) {
  111. $ErrMsg = false;
  112. if ($TBS->meth_Misc_UserFctCheck($FctInfo,$FctCat,$FctObj,$ErrMsg)) {
  113. $this->Type = $FctInfo['type'];
  114. if ($this->Type!==5) {
  115. if ($this->Type===4) { //
  116. $this->FctPrm = array(false,0);
  117. $this->SrcId =& $FctInfo['open'][0];
  118. }
  119. $this->FctOpen =& $FctInfo['open'];
  120. $this->FctFetch =& $FctInfo['fetch'];
  121. $this->FctClose =& $FctInfo['close'];
  122. }
  123. } else {
  124. $this->Type = $this->DataAlert($ErrMsg);
  125. }
  126. }
  127. return ($this->Type!==false);
  128. }
  129. function DataOpen(&$Query) {
  130. // Init values
  131. unset($this->CurrRec); $this->CurrRec = true;
  132. if ($this->RecSaved) {
  133. $this->FirstRec = true;
  134. unset($this->RecKey); $this->RecKey = '';
  135. $this->RecNum = $this->RecNumInit;
  136. if ($this->OnDataOk) $this->OnDataArgs[1] =& $this->CurrRec;
  137. return true;
  138. }
  139. unset($this->RecSet); $this->RecSet = false;
  140. $this->RecNumInit = 0;
  141. $this->RecNum = 0;
  142. if (isset($this->TBS->_piOnData)) {
  143. $this->OnDataPi = true;
  144. $this->OnDataPiRef =& $this->TBS->_piOnData;
  145. $this->OnDataOk = true;
  146. }
  147. if ($this->OnDataOk) {
  148. $this->OnDataArgs = array();
  149. $this->OnDataArgs[0] =& $this->TBS->_CurrBlock;
  150. $this->OnDataArgs[1] =& $this->CurrRec;
  151. $this->OnDataArgs[2] =& $this->RecNum;
  152. $this->OnDataArgs[3] =& $this->TBS;
  153. }
  154. switch ($this->Type) {
  155. case 0: // Array
  156. if (($this->SubType===1) and (is_string($Query))) $this->SubType = 2;
  157. if ($this->SubType===0) {
  158. $this->RecSet =& $this->SrcId;
  159. } elseif ($this->SubType===1) {
  160. if (is_array($Query)) {
  161. $this->RecSet =& $Query;
  162. } else {
  163. $this->DataAlert('type \''.gettype($Query).'\' not supported for the Query Parameter going with \'array\' Source Type.');
  164. }
  165. } elseif ($this->SubType===2) {
  166. // TBS query string for array and objects, syntax: "var[item1][item2]->item3[item4]..."
  167. $x = trim($Query);
  168. $z = chr(0);
  169. $x = str_replace(']->',$z,$x);
  170. $x = str_replace('][',$z,$x);
  171. $x = str_replace('->',$z,$x);
  172. $x = str_replace('[',$z,$x);
  173. if (substr($x,strlen($x)-1,1)===']') $x = substr($x,0,strlen($x)-1);
  174. $ItemLst = explode($z,$x);
  175. $ItemNbr = count($ItemLst);
  176. $Item0 =& $ItemLst[0];
  177. // Check first item
  178. if ($Item0[0]==='~') {
  179. $Item0 = substr($Item0,1);
  180. if ($this->TBS->ObjectRef!==false) {
  181. $Var =& $this->TBS->ObjectRef;
  182. $i = 0;
  183. } else {
  184. $i = $this->DataAlert('invalid query \''.$Query.'\' because property ObjectRef is not set.');
  185. }
  186. } else {
  187. if (isset($GLOBALS[$Item0])) {
  188. $Var =& $GLOBALS[$Item0];
  189. $i = 1;
  190. } else {
  191. $i = $this->DataAlert('invalid query \''.$Query.'\' because global variable \''.$Item0.'\' is not found.');
  192. }
  193. }
  194. // Check sub-items
  195. $Empty = false;
  196. while (($i!==false) and ($i<$ItemNbr) and ($Empty===false)) {
  197. $x = $ItemLst[$i];
  198. if (is_array($Var)) {
  199. if (isset($Var[$x])) {
  200. $Var =& $Var[$x];
  201. } else {
  202. $Empty = true;
  203. }
  204. } elseif (is_object($Var)) {
  205. $ArgLst = $this->f_Misc_CheckArgLst($x);
  206. if (method_exists($Var,$x)) {
  207. $f = array(&$Var,$x); unset($Var);
  208. $Var = call_user_func_array($f,$ArgLst);
  209. } elseif (isset($Var->$x)) {
  210. $Var =& $Var->$x;
  211. } else {
  212. $Empty = true;
  213. }
  214. } else {
  215. $i = $this->DataAlert('invalid query \''.$Query.'\' because item \''.$ItemLst[$i].'\' is neither an Array nor an Object. Its type is \''.gettype($Var).'\'.');
  216. }
  217. if ($i!==false) $i++;
  218. }
  219. // Assign data
  220. if ($i!==false) {
  221. if ($Empty) {
  222. $this->RecSet = array();
  223. } else {
  224. $this->RecSet =& $Var;
  225. }
  226. }
  227. } elseif ($this->SubType===3) { // Clear
  228. $this->RecSet = array();
  229. }
  230. // First record
  231. if ($this->RecSet!==false) {
  232. $this->RecNbr = $this->RecNumInit + count($this->RecSet);
  233. $this->FirstRec = true;
  234. $this->RecSaved = true;
  235. $this->RecSaving = false;
  236. }
  237. break;
  238. case 6: // MySQL
  239. switch ($this->SubType) {
  240. case 0: $this->RecSet = @mysql_query($Query,$this->SrcId); break;
  241. case 1: $this->RecSet = $this->SrcId; break;
  242. case 2: $this->RecSet = @mysql_query($Query); break;
  243. }
  244. if ($this->RecSet===false) $this->DataAlert('MySql error message when opening the query: '.mysql_error());
  245. break;
  246. case 1: // Num
  247. $this->RecSet = true;
  248. $this->NumMin = 1;
  249. $this->NumMax = 1;
  250. $this->NumStep = 1;
  251. if (is_array($Query)) {
  252. if (isset($Query['min'])) $this->NumMin = $Query['min'];
  253. if (isset($Query['step'])) $this->NumStep = $Query['step'];
  254. if (isset($Query['max'])) {
  255. $this->NumMax = $Query['max'];
  256. } else {
  257. $this->RecSet = $this->DataAlert('the \'num\' source is an array that has no value for the \'max\' key.');
  258. }
  259. if ($this->NumStep==0) $this->RecSet = $this->DataAlert('the \'num\' source is an array that has a step value set to zero.');
  260. } else {
  261. $this->NumMax = ceil($Query);
  262. }
  263. if ($this->RecSet) {
  264. if ($this->NumStep>0) {
  265. $this->NumVal = $this->NumMin;
  266. } else {
  267. $this->NumVal = $this->NumMax;
  268. }
  269. }
  270. break;
  271. case 2: // Text
  272. if (is_string($Query)) {
  273. $this->RecSet =& $Query;
  274. } else {
  275. $this->RecSet = ''.$Query;
  276. }
  277. break;
  278. case 3: // Custom function
  279. $FctOpen = $this->FctOpen;
  280. $this->RecSet = $FctOpen($this->SrcId,$Query);
  281. if ($this->RecSet===false) $this->DataAlert('function '.$FctOpen.'() has failed to open query {'.$Query.'}');
  282. break;
  283. case 4: // Custom method from ObjectRef
  284. $this->RecSet = call_user_func_array($this->FctOpen,array(&$this->SrcId,&$Query));
  285. if ($this->RecSet===false) $this->DataAlert('method '.get_class($this->FctOpen[0]).'::'.$this->FctOpen[1].'() has failed to open query {'.$Query.'}');
  286. break;
  287. case 5: // Custom method of object
  288. $this->RecSet = $this->SrcId->tbsdb_open($this->SrcId,$Query);
  289. if ($this->RecSet===false) $this->DataAlert('method '.get_class($this->SrcId).'::tbsdb_open() has failed to open query {'.$Query.'}');
  290. break;
  291. case 7: // PostgreSQL
  292. switch ($this->SubType) {
  293. case 0: $this->RecSet = @pg_query($this->SrcId,$Query); break;
  294. case 1: $this->RecSet = $this->SrcId; break;
  295. }
  296. if ($this->RecSet===false) $this->DataAlert('PostgreSQL error message when opening the query: '.pg_last_error($this->SrcId));
  297. break;
  298. case 8: // SQLite
  299. switch ($this->SubType) {
  300. case 0: $this->RecSet = @sqlite_query($this->SrcId,$Query); break;
  301. case 1: $this->RecSet = $this->SrcId; break;
  302. }
  303. if ($this->RecSet===false) $this->DataAlert('SQLite error message when opening the query:'.sqlite_error_string(sqlite_last_error($this->SrcId)));
  304. break;
  305. }
  306. if ($this->Type===0) {
  307. unset($this->RecKey); $this->RecKey = '';
  308. } else {
  309. if ($this->RecSaving) {
  310. unset($this->RecBuffer); $this->RecBuffer = array();
  311. }
  312. $this->RecKey =& $this->RecNum; // Not array: RecKey = RecNum
  313. }
  314. return ($this->RecSet!==false);
  315. }
  316. function DataFetch() {
  317. if ($this->RecSaved) {
  318. if ($this->RecNum<$this->RecNbr) {
  319. if ($this->FirstRec) {
  320. if ($this->SubType===2) { // From string
  321. reset($this->RecSet);
  322. $this->RecKey = key($this->RecSet);
  323. $this->CurrRec =& $this->RecSet[$this->RecKey];
  324. } else {
  325. $this->CurrRec = reset($this->RecSet);
  326. $this->RecKey = key($this->RecSet);
  327. }
  328. $this->FirstRec = false;
  329. } else {
  330. if ($this->SubType===2) { // From string
  331. next($this->RecSet);
  332. $this->RecKey = key($this->RecSet);
  333. $this->CurrRec =& $this->RecSet[$this->RecKey];
  334. } else {
  335. $this->CurrRec = next($this->RecSet);
  336. $this->RecKey = key($this->RecSet);
  337. }
  338. }
  339. if ((!is_array($this->CurrRec)) and (!is_object($this->CurrRec))) $this->CurrRec = array('key'=>$this->RecKey, 'val'=>$this->CurrRec);
  340. $this->RecNum++;
  341. if ($this->OnDataOk) {
  342. if ($this->OnDataPrm) call_user_func_array($this->OnDataPrmRef,$this->OnDataArgs);
  343. if ($this->OnDataPi) $this->TBS->meth_PlugIn_RunAll($this->OnDataPiRef,$this->OnDataArgs);
  344. if ($this->SubType!==2) $this->RecSet[$this->RecKey] = $this->CurrRec; // save modifications because array reading is done without reference :(
  345. }
  346. } else {
  347. unset($this->CurrRec); $this->CurrRec = false;
  348. }
  349. return;
  350. }
  351. switch ($this->Type) {
  352. case 6: // MySQL
  353. $this->CurrRec = mysql_fetch_assoc($this->RecSet);
  354. break;
  355. case 1: // Num
  356. if (($this->NumVal>=$this->NumMin) and ($this->NumVal<=$this->NumMax)) {
  357. $this->CurrRec = array('val'=>$this->NumVal);
  358. $this->NumVal += $this->NumStep;
  359. } else {
  360. $this->CurrRec = false;
  361. }
  362. break;
  363. case 2: // Text
  364. if ($this->RecNum===0) {
  365. if ($this->RecSet==='') {
  366. $this->CurrRec = false;
  367. } else {
  368. $this->CurrRec =& $this->RecSet;
  369. }
  370. } else {
  371. $this->CurrRec = false;
  372. }
  373. break;
  374. case 3: // Custom function
  375. $FctFetch = $this->FctFetch;
  376. $this->CurrRec = $FctFetch($this->RecSet,$this->RecNum+1);
  377. break;
  378. case 4: // Custom method from ObjectRef
  379. $this->FctPrm[0] =& $this->RecSet; $this->FctPrm[1] = $this->RecNum+1;
  380. $this->CurrRec = call_user_func_array($this->FctFetch,$this->FctPrm);
  381. break;
  382. case 5: // Custom method of object
  383. $this->CurrRec = $this->SrcId->tbsdb_fetch($this->RecSet,$this->RecNum+1);
  384. break;
  385. case 7: // PostgreSQL
  386. $this->CurrRec = pg_fetch_assoc($this->RecSet);
  387. break;
  388. case 8: // SQLite
  389. $this->CurrRec = sqlite_fetch_array($this->RecSet,SQLITE_ASSOC);
  390. break;
  391. }
  392. // Set the row count
  393. if ($this->CurrRec!==false) {
  394. $this->RecNum++;
  395. if ($this->OnDataOk) {
  396. $this->OnDataArgs[1] =& $this->CurrRec; // Reference has changed if ($this->SubType===2)
  397. if ($this->OnDataPrm) call_user_func_array($this->OnDataPrmRef,$this->OnDataArgs);
  398. if ($this->OnDataPi) $this->TBS->meth_PlugIn_RunAll($this->OnDataPiRef,$this->OnDataArgs);
  399. }
  400. if ($this->RecSaving) $this->RecBuffer[$this->RecKey] = $this->CurrRec;
  401. }
  402. }
  403. function DataClose() {
  404. $this->OnDataOk = false;
  405. $this->OnDataPrm = false;
  406. $this->OnDataPi = false;
  407. if ($this->RecSaved) return;
  408. switch ($this->Type) {
  409. case 6: mysql_free_result($this->RecSet); break;
  410. case 3: $FctClose=$this->FctClose; $FctClose($this->RecSet); break;
  411. case 4: call_user_func_array($this->FctClose,array(&$this->RecSet)); break;
  412. case 5: $this->SrcId->tbsdb_close($this->RecSet); break;
  413. case 7: pg_free_result($this->RecSet); break;
  414. }
  415. if ($this->RecSaving) {
  416. $this->RecSet =& $this->RecBuffer;
  417. $this->RecNbr = $this->RecNumInit + count($this->RecSet);
  418. $this->RecSaving = false;
  419. $this->RecSaved = true;
  420. }
  421. }
  422. }
  423. // *********************************************
  424. class clsTinyButStrong {
  425. // Public properties
  426. public $Source = '';
  427. public $Render = 3;
  428. public $TplVars = array();
  429. public $ObjectRef = false;
  430. public $NoErr = false;
  431. // Undocumented (can change at any version)
  432. public $Version = '3.4.0';
  433. public $HtmlCharSet = '';
  434. public $TurboBlock = true;
  435. public $VarPrefix = '';
  436. public $Protect = true;
  437. public $ErrCount = 0;
  438. // Private
  439. public $_LastFile = '';
  440. public $_HtmlCharFct = false;
  441. public $_Mode = 0;
  442. public $_CurrBlock = '';
  443. public $_ChrOpen = '[';
  444. public $_ChrClose = ']';
  445. public $_ChrVal = '[val]';
  446. public $_ChrProtect = '&#91;';
  447. public $_PlugIns = array();
  448. public $_PlugIns_Ok = false;
  449. public $_piOnFrm_Ok = false;
  450. function clsTinyButStrong($Chrs='',$VarPrefix='') {
  451. if ($Chrs!=='') {
  452. $Ok = false;
  453. $Len = strlen($Chrs);
  454. if ($Len===2) { // For compatibility
  455. $this->_ChrOpen = $Chrs[0];
  456. $this->_ChrClose = $Chrs[1];
  457. $Ok = true;
  458. } else {
  459. $Pos = strpos($Chrs,',');
  460. if (($Pos!==false) and ($Pos>0) and ($Pos<$Len-1)) {
  461. $this->_ChrOpen = substr($Chrs,0,$Pos);
  462. $this->_ChrClose = substr($Chrs,$Pos+1);
  463. $Ok = true;
  464. }
  465. }
  466. if ($Ok) {
  467. $this->_ChrVal = $this->_ChrOpen.'val'.$this->_ChrClose;
  468. $this->_ChrProtect = '&#'.ord($this->_ChrOpen[0]).';'.substr($this->_ChrOpen,1);
  469. } else {
  470. $this->meth_Misc_Alert('with clsTinyButStrong() function','value \''.$Chrs.'\' is a bad tag delimitor definition.');
  471. }
  472. }
  473. $this->VarPrefix = $VarPrefix;
  474. // Links to global variables
  475. global $_TBS_FormatLst, $_TBS_UserFctLst, $_TBS_AutoInstallPlugIns;
  476. if (!isset($_TBS_FormatLst)) $_TBS_FormatLst = array();
  477. if (!isset($_TBS_UserFctLst)) $_TBS_UserFctLst = array();
  478. $this->_FormatLst =& $_TBS_FormatLst;
  479. $this->_UserFctLst =& $_TBS_UserFctLst;
  480. // Auto-installing plug-ins
  481. if (isset($_TBS_AutoInstallPlugIns)) foreach ($_TBS_AutoInstallPlugIns as $pi) $this->PlugIn(TBS_INSTALL,$pi);
  482. }
  483. // Public methods
  484. function LoadTemplate($File,$HtmlCharSet='') {
  485. if ($File==='') {
  486. $this->meth_Misc_Charset($HtmlCharSet);
  487. return true;
  488. }
  489. $Ok = true;
  490. if ($this->_PlugIns_Ok) {
  491. if (isset($this->_piBeforeLoadTemplate) or isset($this->_piAfterLoadTemplate)) {
  492. // Plug-ins
  493. $ArgLst = func_get_args();
  494. $ArgLst[0] =& $File;
  495. $ArgLst[1] =& $HtmlCharSet;
  496. if (isset($this->_piBeforeLoadTemplate)) $Ok = $this->meth_PlugIn_RunAll($this->_piBeforeLoadTemplate,$ArgLst);
  497. }
  498. }
  499. // Load the file
  500. if ($Ok!==false) {
  501. if (!is_null($File)) {
  502. $x = '';
  503. if (!$this->f_Misc_GetFile($x,$File,$this->_LastFile)) return $this->meth_Misc_Alert('with LoadTemplate() method','file \''.$File.'\' is not found or not readable.');
  504. if ($HtmlCharSet==='+') {
  505. $this->Source .= $x;
  506. } else {
  507. $this->Source = $x;
  508. }
  509. }
  510. if ($this->_Mode==0) {
  511. if (!is_null($File)) $this->_LastFile = $File;
  512. $this->TplVars = array();
  513. $this->meth_Misc_Charset($HtmlCharSet);
  514. }
  515. // Automatic fields and blocks
  516. $this->meth_Merge_AutoOn($this->Source,'onload',true,true);
  517. }
  518. // Plug-ins
  519. if ($this->_PlugIns_Ok and isset($ArgLst) and isset($this->_piAfterLoadTemplate)) $Ok = $this->meth_PlugIn_RunAll($this->_piAfterLoadTemplate,$ArgLst);
  520. return $Ok;
  521. }
  522. function GetBlockSource($BlockName,$List=false,$KeepDefTags=true) {
  523. $RetVal = array();
  524. $Nbr = 0;
  525. $Pos = 0;
  526. $FieldOutside = false;
  527. $P1 = false;
  528. $Mode = ($KeepDefTags) ? 3 : 2;
  529. while ($Loc = $this->meth_Locator_FindBlockNext($this->Source,$BlockName,$Pos,'.',$Mode,$P1,$FieldOutside)) {
  530. $P1 = false;
  531. $Nbr++;
  532. $RetVal[$Nbr] = $Loc->BlockSrc;
  533. if (!$List) return $RetVal[$Nbr];
  534. $Pos = $Loc->PosEnd;
  535. }
  536. if ($List) {
  537. return $RetVal;
  538. } else {
  539. return false;
  540. }
  541. }
  542. function MergeBlock($BlockLst,$SrcId,$Query='') {
  543. if ($SrcId==='cond') {
  544. $Nbr = 0;
  545. $BlockLst = explode(',',$BlockLst);
  546. foreach ($BlockLst as $Block) {
  547. $Block = trim($Block);
  548. if ($Block!=='') $Nbr += $this->meth_Merge_AutoOn($this->Source,$Block,true,true);
  549. }
  550. return $Nbr;
  551. } else {
  552. return $this->meth_Merge_Block($this->Source,$BlockLst,$SrcId,$Query,false,0);
  553. }
  554. }
  555. function MergeField($NameLst,$Value=null,$IsUserFct=false) {
  556. $FctCheck = $IsUserFct;
  557. if ($PlugIn = isset($this->_piOnMergeField)) $ArgPi = array('','',&$Value,0,&$this->Source,0,0);
  558. $SubStart = 0;
  559. $Ok = true;
  560. $NameLst = explode(',',$NameLst);
  561. foreach ($NameLst as $Name) {
  562. $Name = trim($Name);
  563. $Cont = false;
  564. switch ($Name) {
  565. case '': $Cont=true;
  566. case 'onload': $this->meth_Merge_AutoOn($this->Source,'onload',true,true);$Cont=true;
  567. case 'onshow': $this->meth_Merge_AutoOn($this->Source,'onshow',true,true);$Cont=true;
  568. case 'var': $this->meth_Merge_AutoVar($this->Source,true);$Cont=true;
  569. }
  570. if ($Cont) continue;
  571. if ($PlugIn) $ArgPi[0] = $Name;
  572. $PosBeg = 0;
  573. // Initilize the user function (only once)
  574. if ($FctCheck) {
  575. $FctInfo = $Value;
  576. $ErrMsg = false;
  577. if (!$this->meth_Misc_UserFctCheck($FctInfo,'f',$ErrMsg,$ErrMsg)) return $this->meth_Misc_Alert('with MergeField() method',$ErrMsg);
  578. $FctArg = array('','');
  579. $SubStart = false;
  580. $FctCheck = false;
  581. }
  582. while ($Loc = $this->meth_Locator_FindTbs($this->Source,$Name,$PosBeg,'.')) {
  583. // Apply user function
  584. if ($IsUserFct) {
  585. $FctArg[0] =& $Loc->SubName; $FctArg[1] =& $Loc->PrmLst;
  586. $Value = call_user_func_array($FctInfo,$FctArg);
  587. }
  588. // Plug-ins
  589. if ($PlugIn) {
  590. $ArgPi[1] = $Loc->SubName; $ArgPi[3] =& $Loc->PrmLst; $ArgPi[5] =& $Loc->PosBeg; $ArgPi[6] =& $Loc->PosEnd;
  591. $Ok = $this->meth_PlugIn_RunAll($this->_piOnMergeField,$ArgPi);
  592. }
  593. // Merge the field
  594. if ($Ok) {
  595. $PosBeg = $this->meth_Locator_Replace($this->Source,$Loc,$Value,$SubStart);
  596. } else {
  597. $PosBeg = $Loc->PosEnd;
  598. }
  599. }
  600. }
  601. }
  602. function Show($Render=false) {
  603. $Ok = true;
  604. if ($Render===false) $Render = $this->Render;
  605. if ($this->_PlugIns_Ok) {
  606. if (isset($this->_piBeforeShow) or isset($this->_piAfterShow)) {
  607. // Plug-ins
  608. $ArgLst = func_get_args();
  609. $ArgLst[0] =& $Render;
  610. if (isset($this->_piBeforeShow)) $Ok = $this->meth_PlugIn_RunAll($this->_piBeforeShow,$ArgLst);
  611. }
  612. }
  613. if ($Ok!==false) {
  614. $this->meth_Merge_AutoOn($this->Source,'onshow',true,true);
  615. $this->meth_Merge_AutoVar($this->Source,true);
  616. }
  617. if ($this->_PlugIns_Ok and isset($ArgLst) and isset($this->_piAfterShow)) $this->meth_PlugIn_RunAll($this->_piAfterShow,$ArgLst);
  618. if (($Render & TBS_OUTPUT)==TBS_OUTPUT) echo $this->Source;
  619. if (($this->_Mode==0) and (($Render & TBS_EXIT)==TBS_EXIT)) exit;
  620. return $Ok;
  621. }
  622. function PlugIn($Prm1,$Prm2=0) {
  623. if (is_numeric($Prm1)) {
  624. switch ($Prm1) {
  625. case TBS_INSTALL:
  626. $PlugInId = $Prm2;
  627. // Try to install the plug-in
  628. if (isset($this->_PlugIns[$PlugInId])) {
  629. return $this->meth_Misc_Alert('with PlugIn() method','plug-in \''.$PlugInId.'\' is already installed.');
  630. } else {
  631. $ArgLst = func_get_args();
  632. array_shift($ArgLst); array_shift($ArgLst);
  633. return $this->meth_PlugIn_Install($PlugInId,$ArgLst,false);
  634. }
  635. case TBS_ISINSTALLED:
  636. // Check if the plug-in is installed
  637. return isset($this->_PlugIns[$Prm2]);
  638. case -4: // Deactivate special plug-ins
  639. $this->_PlugIns_Ok_save = $this->_PlugIns_Ok;
  640. $this->_PlugIns_Ok = false;
  641. return true;
  642. case -5: // Deactivate OnFormat
  643. $this->_piOnFrm_Ok_save = $this->_piOnFrm_Ok;
  644. $this->_piOnFrm_Ok = false;
  645. return true;
  646. case -10: // Restore
  647. $this->_PlugIns_Ok = $this->_PlugIns_Ok_save;
  648. $this->_piOnFrm_Ok = $this->_piOnFrm_Ok_save;
  649. return true;
  650. }
  651. } elseif (is_string($Prm1)) {
  652. // Plug-in's command
  653. $PlugInId = $Prm1;
  654. if (!isset($this->_PlugIns[$PlugInId])) {
  655. if (!$this->meth_PlugIn_Install($PlugInId,array(),true)) return false;
  656. }
  657. if (!isset($this->_piOnCommand[$PlugInId])) return $this->meth_Misc_Alert('with PlugIn() method','plug-in \''.$PlugInId.'\' can\'t run any command because the OnCommand event is not defined or activated.');
  658. $ArgLst = func_get_args();
  659. array_shift($ArgLst);
  660. $Ok = call_user_func_array($this->_piOnCommand[$PlugInId],$ArgLst);
  661. if (is_null($Ok)) $Ok = true;
  662. return $Ok;
  663. }
  664. return $this->meth_Misc_Alert('with PlugIn() method','\''.$Prm1.'\' is an invalid plug-in key, the type of the value is \''.gettype($Prm1).'\'.');
  665. }
  666. // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  667. function meth_Locator_FindTbs(&$Txt,$Name,$Pos,$ChrSub) {
  668. // Find a TBS Locator
  669. $PosEnd = false;
  670. $PosMax = strlen($Txt) -1;
  671. $Start = $this->_ChrOpen.$Name;
  672. do {
  673. // Search for the opening char
  674. if ($Pos>$PosMax) return false;
  675. $Pos = strpos($Txt,$Start,$Pos);
  676. // If found => next chars are analyzed
  677. if ($Pos===false) {
  678. return false;
  679. } else {
  680. $Loc = new clsTbsLocator;
  681. $ReadPrm = false;
  682. $PosX = $Pos + strlen($Start);
  683. $x = $Txt[$PosX];
  684. if ($x===$this->_ChrClose) {
  685. $PosEnd = $PosX;
  686. } elseif ($x===$ChrSub) {
  687. $Loc->SubOk = true; // it is no longer the false value
  688. $ReadPrm = true;
  689. $PosX++;
  690. } elseif (strpos(';',$x)!==false) {
  691. $ReadPrm = true;
  692. $PosX++;
  693. } else {
  694. $Pos++;
  695. }
  696. if ($ReadPrm) {
  697. $this->f_Loc_PrmRead($Txt,$PosX,false,'\'',$this->_ChrOpen,$this->_ChrClose,$Loc,$PosEnd);
  698. if ($PosEnd===false) {
  699. $this->meth_Misc_Alert('','can\'t found the end of the tag \''.substr($Txt,$Pos,$PosX-$Pos+10).'...\'.');
  700. $Pos++;
  701. }
  702. }
  703. }
  704. } while ($PosEnd===false);
  705. $Loc->PosBeg = $Pos;
  706. $Loc->PosEnd = $PosEnd;
  707. if ($Loc->SubOk) {
  708. $Loc->FullName = $Name.'.'.$Loc->SubName;
  709. $Loc->SubLst = explode('.',$Loc->SubName);
  710. $Loc->SubNbr = count($Loc->SubLst);
  711. } else {
  712. $Loc->FullName = $Name;
  713. }
  714. if ($ReadPrm and isset($Loc->PrmLst['comm'])) {
  715. $Loc->PosBeg0 = $Loc->PosBeg;
  716. $Loc->PosEnd0 = $Loc->PosEnd;
  717. $comm = $Loc->PrmLst['comm'];
  718. if (($comm===true) or ($comm==='')) {
  719. $Loc->Enlarged = $this->f_Loc_EnlargeToStr($Txt,$Loc,'<!--' ,'-->');
  720. } else {
  721. $Loc->Enlarged = $this->f_Loc_EnlargeToTag($Txt,$Loc,$comm,false);
  722. }
  723. }
  724. return $Loc;
  725. }
  726. function &meth_Locator_SectionNewBDef(&$LocR,$BlockName,$Txt,$PrmLst) {
  727. $Chk = true;
  728. $LocLst = array();
  729. $LocNbr = 0;
  730. // Cache TBS locators
  731. if ($this->TurboBlock) {
  732. $Chk = false;
  733. $Pos = 0;
  734. $PrevEnd = -1;
  735. while ($Loc = $this->meth_Locator_FindTbs($Txt,$BlockName,$Pos,'.')) {
  736. if (($Loc->SubName==='#') or ($Loc->SubName==='$')) {
  737. $Loc->IsRecInfo = true;
  738. $Loc->RecInfo = $Loc->SubName;
  739. $Loc->SubName = '';
  740. } else {
  741. $Loc->IsRecInfo = false;
  742. }
  743. if ($Loc->PosBeg>$PrevEnd) {
  744. // The previous tag is not embeding => increment
  745. $LocNbr++;
  746. } else {
  747. // The previous tag is embeding => no increment, then previous is over writed
  748. $Chk = true;
  749. }
  750. $PrevEnd = $Loc->PosEnd;
  751. if ($Loc->Enlarged) { // Parameter 'comm'
  752. $Pos = $Loc->PosBeg0+1;
  753. $Loc->Enlarged = false;
  754. } else {
  755. $Pos = $Loc->PosBeg+1;
  756. }
  757. $LocLst[$LocNbr] = $Loc;
  758. }
  759. }
  760. // Create the object
  761. $o = (object) null;
  762. $o->Prm = $PrmLst;
  763. $o->LocLst = $LocLst;
  764. $o->LocNbr = $LocNbr;
  765. $o->Name = $BlockName;
  766. $o->Src = $Txt;
  767. $o->Chk = $Chk;
  768. $o->IsSerial = false;
  769. $LocR->BDefLst[] =& $o; // Can be usefull for plug-in
  770. return $o;
  771. }
  772. function meth_Locator_SectionAddGrp(&$LocR,$BlockName,&$BDef,$Type,$Field,$Prm) {
  773. $BDef->PrevValue = false;
  774. $BDef->Type = $Type;
  775. // Save sub items in a structure near to Locator.
  776. $Field0 = $Field;
  777. if (strpos($Field,$this->_ChrOpen)===false) $Field = $this->_ChrOpen.$BlockName.'.'.$Field.$this->_ChrClose;
  778. $BDef->FDef =& $this->meth_Locator_SectionNewBDef($LocR,$BlockName,$Field,array());
  779. if ($BDef->FDef->LocNbr==0) $this->meth_Misc_Alert('Parameter '.$Prm,'The value \''.$Field0.'\' is unvalide for this parameter.');
  780. if ($Type==='H') {
  781. if ($LocR->HeaderFound===false) {
  782. $LocR->HeaderFound = true;
  783. $LocR->HeaderNbr = 0;
  784. $LocR->HeaderDef = array(); // 1 to HeaderNbr
  785. }
  786. $i = ++$LocR->HeaderNbr;
  787. $LocR->HeaderDef[$i] =& $BDef;
  788. } else {
  789. if ($LocR->FooterFound===false) {
  790. $LocR->FooterFound = true;
  791. $LocR->FooterNbr = 0;
  792. $LocR->FooterDef = array(); // 1 to FooterNbr
  793. }
  794. $BDef->AddLastGrp = ($Type==='F');
  795. $i = ++$LocR->FooterNbr;
  796. $LocR->FooterDef[$i] =& $BDef;
  797. }
  798. }
  799. function meth_Locator_Replace(&$Txt,&$Loc,&$Value,$SubStart) {
  800. // This function enables to merge a locator with a text and returns the position just after the replaced block
  801. // This position can be useful because we don't know in advance how $Value will be replaced.
  802. // Found the value if there is a subname
  803. if (($SubStart!==false) and $Loc->SubOk) {
  804. for ($i=$SubStart;$i<$Loc->SubNbr;$i++) {
  805. $x = $Loc->SubLst[$i]; // &$Loc... brings an error with Event Example, I don't know why.
  806. if (is_array($Value)) {
  807. if (isset($Value[$x])) {
  808. $Value =& $Value[$x];
  809. } elseif (array_key_exists($x,$Value)) {// can happens when value is NULL
  810. $Value =& $Value[$x];
  811. } else {
  812. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item \''.$x.'\' is not an existing key in the array.',true);
  813. unset($Value); $Value = ''; break;
  814. }
  815. } elseif (is_object($Value)) {
  816. $ArgLst = $this->f_Misc_CheckArgLst($x);
  817. if (method_exists($Value,$x)) {
  818. $x = call_user_func_array(array(&$Value,$x),$ArgLst);
  819. } elseif (property_exists($Value,$x)) {
  820. $x =& $Value->$x;
  821. } else {
  822. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item '.$x.'\' is neither a method nor a property in the class \''.get_class($Value).'\'.',true);
  823. unset($Value); $Value = ''; break;
  824. }
  825. $Value =& $x; unset($x); $x = '';
  826. } else {
  827. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'item before \''.$x.'\' is neither an object nor an array. Its type is '.gettype($Value).'.',true);
  828. unset($Value); $Value = ''; break;
  829. }
  830. }
  831. }
  832. $CurrVal = $Value; // Unlink
  833. if (isset($Loc->PrmLst['onformat'])) {
  834. if ($Loc->FirstMerge) {
  835. $Loc->OnFrmInfo = $Loc->PrmLst['onformat'];
  836. $Loc->OnFrmArg = array(&$Loc->FullName,'',&$Loc->PrmLst,&$this);
  837. $ErrMsg = false;
  838. if (!$this->meth_Misc_UserFctCheck($Loc->OnFrmInfo,'f',$ErrMsg,$ErrMsg)) {
  839. unset($Loc->PrmLst['onformat']);
  840. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'(parameter onformat) '.$ErrMsg);
  841. $Loc->OnFrmInfo = 'pi'; // Execute the function pi() just to avoid extra error messages
  842. }
  843. }
  844. $Loc->OnFrmArg[1] =& $CurrVal;
  845. if (isset($Loc->PrmLst['subtpl'])) {
  846. $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal);
  847. call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmArg);
  848. $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal);
  849. $Loc->ConvProtect = false;
  850. $Loc->ConvHtml = false;
  851. } else {
  852. call_user_func_array($Loc->OnFrmInfo,$Loc->OnFrmArg);
  853. }
  854. }
  855. if ($Loc->FirstMerge) {
  856. if (isset($Loc->PrmLst['frm'])) {
  857. $Loc->ConvMode = 0; // Frm
  858. $Loc->ConvProtect = false;
  859. } else {
  860. // Analyze parameter 'htmlconv'
  861. if (isset($Loc->PrmLst['htmlconv'])) {
  862. $x = strtolower($Loc->PrmLst['htmlconv']);
  863. $x = '+'.str_replace(' ','',$x).'+';
  864. if (strpos($x,'+esc+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvHtml = false; $Loc->ConvEsc = true; }
  865. if (strpos($x,'+wsp+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvWS = true; }
  866. if (strpos($x,'+js+')!==false) {$this->f_Misc_ConvSpe($Loc); $Loc->ConvHtml = false; $Loc->ConvJS = true; }
  867. if (strpos($x,'+no+')!==false) $Loc->ConvHtml = false;
  868. if (strpos($x,'+yes+')!==false) $Loc->ConvHtml = true;
  869. if (strpos($x,'+nobr+')!==false) {$Loc->ConvHtml = true; $Loc->ConvBr = false; }
  870. } else {
  871. if ($this->HtmlCharSet===false) $Loc->ConvHtml = false; // No HTML
  872. }
  873. // Analyze parameter 'protect'
  874. if (isset($Loc->PrmLst['protect'])) {
  875. $x = strtolower($Loc->PrmLst['protect']);
  876. if ($x==='no') {
  877. $Loc->ConvProtect = false;
  878. } elseif ($x==='yes') {
  879. $Loc->ConvProtect = true;
  880. }
  881. } elseif ($this->Protect===false) {
  882. $Loc->ConvProtect = false;
  883. }
  884. }
  885. if ($Loc->Ope = isset($Loc->PrmLst['ope'])) {
  886. $OpeLst = explode(',',$Loc->PrmLst['ope']);
  887. $Loc->OpeAct = array();
  888. $Loc->OpeArg = array();
  889. foreach ($OpeLst as $i=>$ope) {
  890. if ($ope==='list') {
  891. $Loc->OpeAct[$i] = 1;
  892. $Loc->OpePrm[$i] = (isset($Loc->PrmLst['valsep'])) ? $Loc->PrmLst['valsep'] : ',';
  893. } elseif ($ope==='minv') {
  894. $Loc->OpeAct[$i] = 8;
  895. $Loc->MInv = true;
  896. } else {
  897. $x = substr($ope,0,4);
  898. if ($x==='max:') {
  899. $Loc->OpeAct[$i] = (isset($Loc->PrmLst['maxhtml'])) ? 2 : 3;
  900. $Loc->OpePrm[$i] = intval(trim(substr($ope,4)));
  901. $Loc->OpeEnd = (isset($Loc->PrmLst['maxend'])) ? $Loc->PrmLst['maxend'] : '...';
  902. if ($Loc->OpePrm[$i]<=0) $Loc->Ope = false;
  903. } elseif ($x==='mod:') {$Loc->OpeAct[$i] = 4; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  904. } elseif ($x==='add:') {$Loc->OpeAct[$i] = 5; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  905. } elseif ($x==='mul:') {$Loc->OpeAct[$i] = 6; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  906. } elseif ($x==='div:') {$Loc->OpeAct[$i] = 7; $Loc->OpePrm[$i] = '0'+trim(substr($ope,4));
  907. } elseif ($x==='nif:') {$Loc->OpeAct[$i] = 9; $Loc->OpePrm[$i] = trim(substr($ope,4));
  908. } elseif (isset($this->_piOnOperation)) {
  909. $Loc->OpeAct[$i] = 0;
  910. $Loc->OpePrm[$i] = $ope;
  911. $Loc->OpeArg[$i] = array(&$Loc->FullName,&$CurrVal,&$Loc->PrmLst,&$Txt,$Loc->PosBeg,$Loc->PosEnd,&$Loc);
  912. $Loc->PrmLst['_ope'] = $Loc->PrmLst['ope'];
  913. } elseif (!isset($Loc->PrmLst['noerr'])) {
  914. $this->meth_Misc_Alert($Loc,'parameter ope doesn\'t support value \''.$ope.'\'.',true);
  915. }
  916. }
  917. }
  918. }
  919. $Loc->FirstMerge = false;
  920. }
  921. $ConvProtect = $Loc->ConvProtect;
  922. // Plug-in OnFormat
  923. if ($this->_piOnFrm_Ok) {
  924. if (isset($Loc->OnFrmArgPi)) {
  925. $Loc->OnFrmArgPi[1] =& $CurrVal;
  926. } else {
  927. $Loc->OnFrmArgPi = array(&$Loc->FullName,&$CurrVal,&$Loc->PrmLst,&$this);
  928. }
  929. $this->meth_PlugIn_RunAll($this->_piOnFormat,$Loc->OnFrmArgPi);
  930. }
  931. // Operation
  932. if ($Loc->Ope) {
  933. foreach ($Loc->OpeAct as $i=>$ope) {
  934. switch ($ope) {
  935. case 0:
  936. $Loc->PrmLst['ope'] = $Loc->OpePrm[$i]; // for compatibility
  937. $OpeArg =& $Loc->OpeArg[$i];
  938. $OpeArg[1] =& $CurrVal; $OpeArg[3] =& $Txt;
  939. if (!$this->meth_PlugIn_RunAll($this->_piOnOperation,$OpeArg)) return $Loc->PosBeg;
  940. break;
  941. case 1: if (is_array($CurrVal)) $CurrVal = implode($Loc->OpePrm[$i],$CurrVal); break;
  942. case 2: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $this->f_Xml_Max($CurrVal,$Loc->OpePrm[$i],$Loc->OpeEnd); break;
  943. case 3: if (strlen(''.$CurrVal)>$Loc->OpePrm[$i]) $CurrVal = substr(''.$CurrVal,0,$Loc->OpePrm[$i]).$Loc->OpeEnd; break;
  944. case 4: $CurrVal = ('0'+$CurrVal) % $Loc->OpePrm[$i]; break;
  945. case 5: $CurrVal = ('0'+$CurrVal) + $Loc->OpePrm[$i]; break;
  946. case 6: $CurrVal = ('0'+$CurrVal) * $Loc->OpePrm[$i]; break;
  947. case 7: $CurrVal = ('0'+$CurrVal) / $Loc->OpePrm[$i]; break;
  948. case 8: $Loc->MInvOk = ($CurrVal!==''); $CurrVal = ''; break;
  949. case 9: if ($CurrVal===$Loc->OpePrm[$i]) $CurrVal = ''; break;
  950. }
  951. }
  952. }
  953. // HTML conversion or format
  954. if ($Loc->ConvMode===1) { // Html simple
  955. if (!is_string($CurrVal)) $CurrVal = @strval($CurrVal);
  956. if ($Loc->ConvHtml) $this->meth_Conv_Html($CurrVal,$Loc->ConvBr);
  957. } elseif ($Loc->ConvMode===0) { // Format
  958. $CurrVal = $this->meth_Misc_Format($CurrVal,$Loc->PrmLst);
  959. } elseif ($Loc->ConvMode===2) { // Html special
  960. if (!is_string($CurrVal)) $CurrVal = @strval($CurrVal);
  961. if ($Loc->ConvHtml) $this->meth_Conv_Html($CurrVal,$Loc->ConvBr);
  962. if ($Loc->ConvEsc) $CurrVal = str_replace('\'','\'\'',$CurrVal);
  963. if ($Loc->ConvWS) {
  964. $check = ' ';
  965. $nbsp = '&nbsp;';
  966. do {
  967. $pos = strpos($CurrVal,$check);
  968. if ($pos!==false) $CurrVal = substr_replace($CurrVal,$nbsp,$pos,1);
  969. } while ($pos!==false);
  970. }
  971. if ($Loc->ConvJS) {
  972. $CurrVal = addslashes($CurrVal); // apply to ('), ("), (\) and (null)
  973. $CurrVal = str_replace("\n",'\n',$CurrVal);
  974. $CurrVal = str_replace("\r",'\r',$CurrVal);
  975. $CurrVal = str_replace("\t",'\t',$CurrVal);
  976. }
  977. }
  978. // if/then/else process, there may be several if/then
  979. if ($Loc->PrmIfNbr) {
  980. $z = false;
  981. $i = 1;
  982. while ($i!==false) {
  983. if ($Loc->PrmIfVar[$i]) $Loc->PrmIfVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmIf[$i],true);
  984. $x = str_replace($this->_ChrVal,$CurrVal,$Loc->PrmIf[$i]);
  985. if ($this->f_Misc_CheckCondition($x)) {
  986. if (isset($Loc->PrmThen[$i])) {
  987. if ($Loc->PrmThenVar[$i]) $Loc->PrmThenVar[$i] = $this->meth_Merge_AutoVar($Loc->PrmThen[$i],true);
  988. $z = $Loc->PrmThen[$i];
  989. }
  990. $i = false;
  991. } else {
  992. $i++;
  993. if ($i>$Loc->PrmIfNbr) {
  994. if (isset($Loc->PrmLst['else'])) {
  995. if ($Loc->PrmElseVar) $Loc->PrmElseVar = $this->meth_Merge_AutoVar($Loc->PrmLst['else'],true);
  996. $z =$Loc->PrmLst['else'];
  997. }
  998. $i = false;
  999. }
  1000. }
  1001. }
  1002. if ($z!==false) {
  1003. if ($ConvProtect) {
  1004. $CurrVal = str_replace($this->_ChrOpen,$this->_ChrProtect,$CurrVal); // TBS protection
  1005. $ConvProtect = false;
  1006. }
  1007. $CurrVal = str_replace($this->_ChrVal,$CurrVal,$z);
  1008. }
  1009. }
  1010. if (isset($Loc->PrmLst['file'])) {
  1011. $x = $Loc->PrmLst['file'];
  1012. if ($x===true) $x = $CurrVal;
  1013. $this->meth_Merge_AutoVar($x,false);
  1014. $x = trim(str_replace($this->_ChrVal,$CurrVal,$x));
  1015. $CurrVal = '';
  1016. if ($x!=='') {
  1017. if ($this->f_Misc_GetFile($CurrVal,$x,$this->_LastFile)) {
  1018. if (isset($Loc->PrmLst['getbody'])) $CurrVal = $this->f_Xml_GetPart($CurrVal,$Loc->PrmLst['getbody'],false,true);
  1019. } else {
  1020. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'the file \''.$x.'\' given by parameter file is not found or not readable.',true);
  1021. }
  1022. $ConvProtect = false;
  1023. }
  1024. }
  1025. if (isset($Loc->PrmLst['script'])) {// Include external PHP script
  1026. $x = $Loc->PrmLst['script'];
  1027. if ($x===true) $x = $CurrVal;
  1028. $this->meth_Merge_AutoVar($x,false);
  1029. $x = trim(str_replace($this->_ChrVal,$CurrVal,$x));
  1030. if ($x!=='') {
  1031. $this->_Subscript = $x;
  1032. $this->CurrPrm =& $Loc->PrmLst;
  1033. $sub = isset($Loc->PrmLst['subtpl']);
  1034. if ($sub) $this->meth_Misc_ChangeMode(true,$Loc,$CurrVal);
  1035. if ($this->meth_Misc_RunSubscript($CurrVal,$Loc->PrmLst)===false) {
  1036. if (!isset($Loc->PrmLst['noerr'])) $this->meth_Misc_Alert($Loc,'the file \''.$x.'\' given by parameter script is not found or not readable.',true);
  1037. }
  1038. if ($sub) $this->meth_Misc_ChangeMode(false,$Loc,$CurrVal);
  1039. if (isset($Loc->PrmLst['getbody'])) $CurrVal = $this->f_Xml_GetPart($CurrVal,$Loc->PrmLst['getbody'],false,true);
  1040. unset($this->CurrPrm);
  1041. $ConvProtect = false;
  1042. }
  1043. }
  1044. // Case when it's an empty string
  1045. if ($CurrVal==='') {
  1046. if ($Loc->MagnetId===false) {
  1047. if (isset($Loc->PrmLst['.'])) {
  1048. $Loc->MagnetId = -1;
  1049. } elseif (isset($Loc->PrmLst['ifempty'])) {
  1050. $Loc->MagnetId = -2;
  1051. } elseif (isset($Loc->PrmLst['magnet'])) {
  1052. $Loc->MagnetId = 1;
  1053. $Loc->PosBeg0 = $Loc->PosBeg;
  1054. $Loc->PosEnd0 = $Loc->PosEnd;
  1055. if (isset($Loc->PrmLst['mtype'])) {
  1056. switch ($Loc->PrmLst['mtype']) {
  1057. case 'm+m': $Loc->MagnetId = 2; break;
  1058. case 'm*': $Loc->MagnetId = 3; break;
  1059. case '*m': $Loc->MagnetId = 4; break;
  1060. }
  1061. }
  1062. } else {
  1063. $Loc->MagnetId = 0;
  1064. }
  1065. if (isset($Loc->MInv)) {
  1066. $Loc->MInv = $Loc->MagnetId;
  1067. $Loc->MagnetId = 5;
  1068. }
  1069. }
  1070. switch ($Loc->MagnetId) {
  1071. case 0: break;
  1072. case -1: $CurrVal = '&nbsp;'; break; // Enables to avoid blanks in HTML tables
  1073. case -2: $CurrVal = $Loc->PrmLst['ifempty']; break;
  1074. case 5: if ($Loc->MInvOk) break;
  1075. case 1:
  1076. $Loc->Enlarged = true;
  1077. $this->f_Loc_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],false);
  1078. break;
  1079. case 2:
  1080. $Loc->Enlarged = true;
  1081. $CurrVal = $this->f_Loc_EnlargeToTag($Txt,$Loc,$Loc->PrmLst['magnet'],true);
  1082. break;
  1083. case 3:
  1084. $Loc->Enlarged = true;
  1085. $Loc2 = $this->f_Xml_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,false,1,false);
  1086. if ($Loc2!==false) {
  1087. $Loc->PosBeg = $Loc2->PosBeg;
  1088. if ($Loc->PosEnd<$Loc2->PosEnd) $Loc->PosEnd = $Loc2->PosEnd;
  1089. }
  1090. break;
  1091. case 4:
  1092. $Loc->Enlarged = true;
  1093. $Loc2 = $this->f_Xml_FindTag($Txt,$Loc->PrmLst['magnet'],true,$Loc->PosBeg,true,1,false);
  1094. if ($Loc2!==false) $Loc->PosEnd = $Loc2->PosEnd;
  1095. break;
  1096. }
  1097. $NewEnd = $Loc->PosBeg; // Useful when mtype='m+m'
  1098. } else {
  1099. if ($ConvProtect) $CurrVal = str_replace($this->_ChrOpen,$this->_ChrProtect,$CurrVal); // TBS protection
  1100. $NewEnd = $Loc->PosBeg + strlen($CurrVal);
  1101. }
  1102. $Txt = substr_replace($Txt,$CurrVal,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);
  1103. return $NewEnd; // Return the new end position of the field
  1104. }
  1105. function meth_Locator_FindBlockNext(&$Txt,$BlockName,$PosBeg,$ChrSub,$Mode,&$P1,&$FieldBefore) {
  1106. // Return the first block locator just after the PosBeg position
  1107. // Mode = 1 : Merge_Auto => doesn't save $Loc->BlockSrc, save the bounds of TBS Def tags instead, return also fields
  1108. // Mode = 2 : FindBlockLst or GetBlockSource => save $Loc->BlockSrc without TBS Def tags
  1109. // Mode = 3 : GetBlockSource => save $Loc->BlockSrc with TBS Def tags
  1110. $SearchDef = true;
  1111. $FirstField = false;
  1112. // Search for the first tag with parameter "block"
  1113. while ($SearchDef and ($Loc = $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,$ChrSub))) {
  1114. if (isset($Loc->PrmLst['block'])) {
  1115. if ($P1) {
  1116. if (isset($Loc->PrmLst['p1'])) return false;
  1117. } else {
  1118. if (isset($Loc->PrmLst['p1'])) $P1 = true;
  1119. }
  1120. $Block = $Loc->PrmLst['block'];
  1121. $SearchDef = false;
  1122. } elseif ($Mode===1) {
  1123. return $Loc;
  1124. } elseif ($FirstField===false) {
  1125. $FirstField = $Loc;
  1126. }
  1127. $PosBeg = $Loc->PosEnd;
  1128. }
  1129. if ($SearchDef) {
  1130. if ($FirstField!==false) $FieldBefore = true;
  1131. return false;
  1132. }
  1133. $Loc->PosDefBeg = -1;
  1134. if ($Block==='begin') { // Block definied using begin/end
  1135. if (($FirstField!==false) and ($FirstField->PosEnd<$Loc->PosBeg)) $FieldBefore = true;
  1136. $Opened = 1;
  1137. while ($Loc2 = $this->meth_Locator_FindTbs($Txt,$BlockName,$PosBeg,$ChrSub)) {
  1138. if (isset($Loc2->PrmLst['block'])) {
  1139. switch ($Loc2->PrmLst['block']) {
  1140. case 'end': $Opened--; break;
  1141. case 'begin': $Opened++; break;
  1142. }
  1143. if ($Opened==0) {
  1144. if ($Mode===1) {
  1145. $Loc->PosBeg2 = $Loc2->PosBeg;
  1146. $Loc->PosEnd2 = $Loc2->PosEnd;
  1147. } else {
  1148. if ($Mode===2) {
  1149. $Loc->BlockSrc = substr($Txt,$Loc->PosEnd+1,$Loc2->PosBeg-$Loc->PosEnd-1);
  1150. } else {
  1151. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$Loc2->PosEnd-$Loc->PosBeg+1);
  1152. }
  1153. $Loc->PosEnd = $Loc2->PosEnd;
  1154. }
  1155. $Loc->BlockFound = true;
  1156. return $Loc;
  1157. }
  1158. }
  1159. $PosBeg = $Loc2->PosEnd;
  1160. }
  1161. return $this->meth_Misc_Alert($Loc,'a least one tag with parameter \'block=end\' is missing.',false,'in block\'s definition');
  1162. }
  1163. if ($Mode===1) {
  1164. $Loc->PosBeg2 = false;
  1165. } else {
  1166. $beg = $Loc->PosBeg;
  1167. $end = $Loc->PosEnd;
  1168. if ($this->f_Loc_EnlargeToTag($Txt,$Loc,$Block,false)===false) return $this->meth_Misc_Alert($Loc,'at least one tag corresponding to '.$Loc->PrmLst['block'].' is not found. Check opening tags, closing tags and embedding levels.',false,'in block\'s definition');
  1169. if ($Loc->SubOk or ($Mode===3)) {
  1170. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$Loc->PosEnd-$Loc->PosBeg+1);
  1171. $Loc->PosDefBeg = $beg - $Loc->PosBeg;
  1172. $Loc->PosDefEnd = $end - $Loc->PosBeg;
  1173. } else {
  1174. $Loc->BlockSrc = substr($Txt,$Loc->PosBeg,$beg-$Loc->PosBeg).substr($Txt,$end+1,$Loc->PosEnd-$end);
  1175. }
  1176. }
  1177. $Loc->BlockFound = true;
  1178. if (($FirstField!==false) and ($FirstField->PosEnd<$Loc->PosBeg)) $FieldBefore = true;
  1179. return $Loc; // methods return by ref by default
  1180. }
  1181. function meth_Locator_FindBlockLst(&$Txt,$BlockName,$Pos,$SpePrm) {
  1182. // Return a locator object covering all block definitions, even if there is no block definition found.
  1183. $LocR = new clsTbsLocator;
  1184. $LocR->P1 = false;
  1185. $LocR->FieldOutside = false;
  1186. $LocR->BDefLst = array();
  1187. $LocR->NoData = false;
  1188. $LocR->Special = false;
  1189. $LocR->HeaderFound = false;
  1190. $LocR->FooterFound = false;
  1191. $LocR->SerialEmpty = false;
  1192. $LocR->GrpBreak = false; // Only for plug-ins
  1193. $LocR->WhenFound = false;
  1194. $LocR->WhenDefault = false;
  1195. $LocR->SectionNbr = 0; // Normal sections
  1196. $LocR->SectionLst = array(); // 1 to SectionNbr
  1197. $BDef = false;
  1198. $ParentLst = array();
  1199. $Pid = 0;
  1200. do {
  1201. if ($BlockName==='') {
  1202. $Loc = false;
  1203. } else {
  1204. $Loc = $this->meth_Locator_FindBlockNext($Txt,$BlockName,$Pos,'.',2,$LocR->P1,$LocR->FieldOutside);
  1205. }
  1206. if ($Loc===false) {
  1207. if ($Pid>0) { // parentgrp mode => disconnect $Txt from the source
  1208. $Parent =& $ParentLst[$Pid];
  1209. $Src = $Txt;
  1210. $Txt =& $Parent->Txt;
  1211. if ($LocR->BlockFound) {
  1212. // Redefine the Header block
  1213. $Parent->Src = substr($Src,0,$LocR->PosBeg);
  1214. // Add a Footer block
  1215. $BDef =& $this->meth_Locator_SectionNewBDef($LocR,$BlockName,substr($Src,$LocR->PosEnd+1),$Parent->Prm);
  1216. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'F',$Parent->Fld,'parentgrp');
  1217. }
  1218. // Now go down to previous level
  1219. $Pos = $Parent->Pos;
  1220. $LocR->PosBeg = $Parent->Beg;
  1221. $LocR->PosEnd = $Parent->End;
  1222. $LocR->BlockFound = true;
  1223. unset($Parent);
  1224. unset($ParentLst[$Pid]);
  1225. $Pid--;
  1226. $Loc = true;
  1227. }
  1228. } else {
  1229. $Pos = $Loc->PosEnd;
  1230. // Define the block limits
  1231. if ($LocR->BlockFound) {
  1232. if ( $LocR->PosBeg > $Loc->PosBeg ) $LocR->PosBeg = $Loc->PosBeg;
  1233. if ( $LocR->PosEnd < $Loc->PosEnd ) $LocR->PosEnd = $Loc->PosEnd;
  1234. } else {
  1235. $LocR->BlockFound = true;
  1236. $LocR->PosBeg = $Loc->PosBeg;
  1237. $LocR->PosEnd = $Loc->PosEnd;
  1238. }
  1239. // Merge block parameters
  1240. if (count($Loc->PrmLst)>0) $LocR->PrmLst = array_merge($LocR->PrmLst,$Loc->PrmLst);
  1241. // Force dynamic parameter to be cachable
  1242. if ($Loc->PosDefBeg>=0) {
  1243. $dynprm = array('when','headergrp','footergrp','parentgrp');
  1244. foreach($dynprm as $dp) {
  1245. $n = 0;
  1246. if ((isset($Loc->PrmLst[$dp])) and (strpos($Loc->PrmLst[$dp],$this->_ChrOpen.$BlockName)!==false)) {
  1247. $n++;
  1248. if ($n==1) {
  1249. $len = $Loc->PosDefEnd - $Loc->PosDefBeg + 1;
  1250. $x = substr($Loc->BlockSrc,$Loc->PosDefBeg,$len);
  1251. }
  1252. $x = str_replace($Loc->PrmLst[$dp],'',$x);
  1253. }
  1254. if ($n>0) $Loc->BlockSrc = substr_replace($Loc->BlockSrc,$x,$Loc->PosDefBeg,$len);
  1255. }
  1256. }
  1257. // Save the block and cache its tags
  1258. $BDef =& $this->meth_Locator_SectionNewBDef($LocR,$BlockName,$Loc->BlockSrc,$Loc->PrmLst);
  1259. // Add the text in the list of blocks
  1260. if (isset($Loc->PrmLst['nodata'])) { // Nodata section
  1261. $LocR->NoData =& $BDef;
  1262. } elseif (($SpePrm!==false) and isset($Loc->PrmLst[$SpePrm])) { // Special section (used for navigation bar)
  1263. $LocR->Special =& $BDef;
  1264. } elseif (isset($Loc->PrmLst['when'])) {
  1265. if ($LocR->WhenFound===false) {
  1266. $LocR->WhenFound = true;
  1267. $LocR->WhenSeveral = false;
  1268. $LocR->WhenNbr = 0;
  1269. $LocR->WhenLst = array();
  1270. }
  1271. $this->meth_Merge_AutoVar($Loc->PrmLst['when'],false);
  1272. $BDef->WhenCond =& $this->meth_Locator_SectionNewBDef($LocR,$BlockName,$Loc->PrmLst['when'],array());
  1273. $BDef->WhenBeforeNS = ($LocR->SectionNbr===0);
  1274. $i = ++$LocR->WhenNbr;
  1275. $LocR->WhenLst[$i] =& $BDef;
  1276. if (isset($Loc->PrmLst['several'])) $LocR->WhenSeveral = true;
  1277. } elseif (isset($Loc->PrmLst['default'])) {
  1278. $LocR->WhenDefault =& $BDef;
  1279. $LocR->WhenDefaultBeforeNS = ($LocR->SectionNbr===0);
  1280. } elseif (isset($Loc->PrmLst['headergrp'])) {
  1281. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'H',$Loc->PrmLst['headergrp'],'headergrp');
  1282. } elseif (isset($Loc->PrmLst['footergrp'])) {
  1283. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'F',$Loc->PrmLst['footergrp'],'footergrp');
  1284. } elseif (isset($Loc->PrmLst['splittergrp'])) {
  1285. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'S',$Loc->PrmLst['splittergrp'],'splittergrp');
  1286. } elseif (isset($Loc->PrmLst['parentgrp'])) {
  1287. $this->meth_Locator_SectionAddGrp($LocR,$BlockName,$BDef,'H',$Loc->PrmLst['parentgrp'],'parentgrp');
  1288. $BDef->Fld = $Loc->PrmLst['parentgrp'];
  1289. $BDef->Txt =& $Txt;
  1290. $BDef->Pos = $Pos;
  1291. $BDef->Beg = $LocR->PosBeg;
  1292. $BDef->End = $LocR->PosEnd;
  1293. $Pid++;
  1294. $ParentLst[$Pid] =& $BDef;
  1295. $Txt =& $BDef->Src;
  1296. $Pos = $Loc->PosDefBeg + 1;
  1297. $LocR->BlockFound = false;
  1298. $LocR->PosBeg = false;
  1299. $LocR->PosEnd = false;
  1300. } elseif (isset($Loc->PrmLst['serial'])) {
  1301. // Section with serial subsections
  1302. $SrSrc =& $BDef->Src;
  1303. // Search the empty item
  1304. if ($LocR->SerialEmpty===false) {
  1305. $SrName = $BlockName.'_0';
  1306. $x = false;
  1307. $SrLoc = $this->meth_Locator_FindBlockNext($SrSrc,$SrName,0,'.',2,$x,$x);
  1308. if ($SrLoc!==false) {
  1309. $LocR->SerialEmpty = $SrLoc->BlockSrc;
  1310. $SrSrc = substr_replace($SrSrc,'',$SrLoc->PosBeg,$SrLoc->PosEnd-$SrLoc->PosBeg+1);
  1311. }
  1312. }
  1313. $SrName = $BlockName.'_1';
  1314. $x = false;
  1315. $SrLoc = $this->meth_Locator_FindBlockNext($SrSrc,$SrName,0,'.',2,$x,$x);
  1316. if ($SrLoc!==false) {
  1317. $SrId = 1;
  1318. do {
  1319. // Save previous subsection
  1320. $SrBDef =& $this->meth_Locator_SectionNewBDef($LocR,$SrName,$SrLoc->BlockSrc,$SrLoc->PrmLst);
  1321. $SrBDef->SrBeg = $SrLoc->PosBeg;
  1322. $SrBDef->SrLen = $SrLoc->PosEnd - $SrLoc->PosBeg + 1;
  1323. $SrBDef->SrTxt = false;
  1324. $BDef->SrBDefLst[$SrId] =& $SrBDef;
  1325. // Put in order
  1326. $BDef->SrBDefOrdered[$SrId] =& $SrBDef;
  1327. $i = $SrId;
  1328. while (($i>1) and ($SrBDef->SrBeg<$BDef->SrBDefOrdered[$SrId-1]->SrBeg)) {
  1329. $BDef->SrBDefOrdered[$i] =& $BDef->SrBDefOrdered[$i-1];
  1330. $BDef->SrBDefOrdered[$i-1] =& $SrBDef;
  1331. $i--;
  1332. }
  1333. // Search next subsection
  1334. $SrId++;
  1335. $SrName = $BlockName.'_'.$SrId;
  1336. $x = false;
  1337. $SrLoc = $this->meth_Locator_FindBlockNext($SrSrc,$SrName,0,'.',2,$x,$x);
  1338. } while ($SrLoc!==false);
  1339. $BDef->SrBDefNbr = $SrId-1;
  1340. $BDef->IsSerial = true;
  1341. $i = ++$LocR->SectionNbr;
  1342. $LocR->SectionLst[$i] =& $BDef;
  1343. }
  1344. } else {
  1345. // Normal section
  1346. $i = ++$LocR->SectionNbr;
  1347. $LocR->SectionLst[$i] =& $BDef;
  1348. }
  1349. }
  1350. } while ($Loc!==false);
  1351. if ($LocR->WhenFound and ($LocR->SectionNbr===0)) {
  1352. // Add a blank section if When is used without a normal section
  1353. $BDef =& $this->meth_Locator_SectionNewBDef($LocR,$BlockName,'',array());
  1354. $LocR->SectionNbr = 1;
  1355. $LocR->SectionLst[1] =& $BDef;
  1356. }
  1357. return $LocR; // methods return by ref by default
  1358. }
  1359. function meth_Merge_Block(&$Txt,&$BlockLst,&$SrcId,&$Query,$SpePrm,$SpeRecNum) {
  1360. $BlockSave = $this->_CurrBlock;
  1361. $this->_CurrBlock = $BlockLst;
  1362. // Get source type and info
  1363. $Src = new clsTbsDataSource;
  1364. if (!$Src->DataPrepare($SrcId,$this)) {
  1365. $this->_CurrBlock = $BlockSave;
  1366. return 0;
  1367. }
  1368. $BlockLst = explode(',',$BlockLst);
  1369. $BlockNbr = count($BlockLst);
  1370. $BlockId = 0;
  1371. $WasP1 = false;
  1372. $NbrRecTot = 0;
  1373. $QueryZ =& $Query;
  1374. $ReturnData = false;
  1375. while ($BlockId<$BlockNbr) {
  1376. $RecSpe = 0; // Row with a special block's definition (used for the navigation bar)
  1377. $QueryOk = true;
  1378. $this->_CurrBlock = trim($BlockLst[$BlockId]);
  1379. if ($this->_CurrBlock==='*') {
  1380. $ReturnData = true;
  1381. if ($Src->RecSaved===false) $Src->RecSaving = true;
  1382. $this->_CurrBlock = '';
  1383. }
  1384. // Search the block
  1385. $LocR = $this->meth_Locator_FindBlockLst($Txt,$this->_CurrBlock,0,$SpePrm);
  1386. if ($WasP1) $this->meth_Merge_FieldOutside($Txt,$Src,$LocR);
  1387. if ($LocR->BlockFound) {
  1388. if ($LocR->Special!==false) $RecSpe = $SpeRecNum;
  1389. // OnData
  1390. if ($Src->OnDataPrm = isset($LocR->PrmLst['ondata'])) {
  1391. $Src->OnDataPrmRef = $LocR->PrmLst['ondata'];
  1392. if (isset($Src->OnDataPrmDone[$Src->OnDataPrmRef])) {
  1393. $Src->OnDataPrm = false;
  1394. } else {
  1395. $ErrMsg = false;
  1396. if ($this->meth_Misc_UserFctCheck($Src->OnDataPrmRef,'f',$ErrMsg,$ErrMsg)) {
  1397. $Src->OnDataOk = true;
  1398. } else {
  1399. $LocR->FullName = $this->_CurrBlock;
  1400. $Src->OnDataPrm = $this->meth_Misc_Alert($LocR,'(parameter ondata) '.$ErrMsg,false,'block');
  1401. }
  1402. }
  1403. }
  1404. // Dynamic query
  1405. if ($LocR->P1) {
  1406. if (is_string($Query)) {
  1407. $Src->RecSaved = false;
  1408. unset($QueryZ); $QueryZ = ''.$Query;
  1409. $i = 1;
  1410. do {
  1411. $x = 'p'.$i;
  1412. if (isset($LocR->PrmLst[$x])) {
  1413. $QueryZ = str_replace('%p'.$i.'%',$LocR->PrmLst[$x],$QueryZ);
  1414. $i++;
  1415. } else {
  1416. $i = false;
  1417. }

Large files files are truncated, but you can click here to view the full file