Пример #1
0
 function meth_Merge_Block(&$Txt, $BlockLst, &$SrcId, &$Query, $SpePrm, $SpeRecNum, $QryPrms = false)
 {
     $BlockSave = $this->_CurrBlock;
     $this->_CurrBlock = $BlockLst;
     // Get source type and info
     $Src = new clsTbsDataSource();
     if (!$Src->DataPrepare($SrcId, $this)) {
         $this->_CurrBlock = $BlockSave;
         return 0;
     }
     if (is_string($BlockLst)) {
         $BlockLst = explode(',', $BlockLst);
     }
     $BlockNbr = count($BlockLst);
     $BlockId = 0;
     $WasP1 = false;
     $NbrRecTot = 0;
     $QueryZ =& $Query;
     $ReturnData = false;
     while ($BlockId < $BlockNbr) {
         $RecSpe = 0;
         // Row with a special block's definition (used for the navigation bar)
         $QueryOk = true;
         $this->_CurrBlock = trim($BlockLst[$BlockId]);
         if ($this->_CurrBlock === '*') {
             $ReturnData = true;
             if ($Src->RecSaved === false) {
                 $Src->RecSaving = true;
             }
             $this->_CurrBlock = '';
         }
         // Search the block
         $LocR = $this->meth_Locator_FindBlockLst($Txt, $this->_CurrBlock, 0, $SpePrm);
         if ($LocR->BlockFound) {
             if ($LocR->Special !== false) {
                 $RecSpe = $SpeRecNum;
             }
             // OnData
             if ($Src->OnDataPrm = isset($LocR->PrmLst['ondata'])) {
                 $Src->OnDataPrmRef = $LocR->PrmLst['ondata'];
                 if (isset($Src->OnDataPrmDone[$Src->OnDataPrmRef])) {
                     $Src->OnDataPrm = false;
                 } else {
                     $ErrMsg = false;
                     if ($this->meth_Misc_UserFctCheck($Src->OnDataPrmRef, 'f', $ErrMsg, $ErrMsg, true)) {
                         $Src->OnDataOk = true;
                     } else {
                         $LocR->FullName = $this->_CurrBlock;
                         $Src->OnDataPrm = $this->meth_Misc_Alert($LocR, '(parameter ondata) ' . $ErrMsg, false, 'block');
                     }
                 }
             }
             // Dynamic query
             if ($LocR->P1) {
                 if ($LocR->PrmLst['p1'] === true && (!is_string($Query) || strpos($Query, '%p1%') === false)) {
                     // p1 with no value is a trick to perform new block with same name
                     if ($Src->RecSaved === false) {
                         $Src->RecSaving = true;
                     }
                 } elseif (is_string($Query)) {
                     $Src->RecSaved = false;
                     unset($QueryZ);
                     $QueryZ = '' . $Query;
                     $i = 1;
                     do {
                         $x = 'p' . $i;
                         if (isset($LocR->PrmLst[$x])) {
                             $QueryZ = str_replace('%p' . $i . '%', $LocR->PrmLst[$x], $QueryZ);
                             $i++;
                         } else {
                             $i = false;
                         }
                     } while ($i !== false);
                 }
                 $WasP1 = true;
             } elseif ($Src->RecSaved === false and $BlockNbr - $BlockId > 1) {
                 $Src->RecSaving = true;
             }
         } elseif ($WasP1) {
             $QueryOk = false;
             $WasP1 = false;
         }
         // Open the recordset
         if ($QueryOk) {
             if (!$LocR->BlockFound and !$LocR->FieldOutside) {
                 // Special case: return data without any block to merge
                 $QueryOk = false;
                 if ($ReturnData and !$Src->RecSaved) {
                     if ($Src->DataOpen($QueryZ, $QryPrms)) {
                         do {
                             $Src->DataFetch();
                         } while ($Src->CurrRec !== false);
                         $Src->DataClose();
                     }
                 }
             } else {
                 $QueryOk = $Src->DataOpen($QueryZ, $QryPrms);
                 if (!$QueryOk) {
                     if ($WasP1) {
                         $WasP1 = false;
                     } else {
                         $LocR->FieldOutside = false;
                     }
                     // prevent from infinit loop
                 }
             }
         }
         // Merge sections
         if ($QueryOk) {
             if ($Src->Type === 2) {
                 // Special for Text merge
                 if ($LocR->BlockFound) {
                     $Txt = substr_replace($Txt, $Src->RecSet, $LocR->PosBeg, $LocR->PosEnd - $LocR->PosBeg + 1);
                     $Src->DataFetch();
                     // store data, may be needed for multiple blocks
                     $Src->RecNum = 1;
                     $Src->CurrRec = false;
                 } else {
                     $Src->DataAlert('can\'t merge the block with a text value because the block definition is not found.');
                 }
             } elseif ($LocR->BlockFound === false) {
                 $Src->DataFetch();
                 // Merge first record only
             } else {
                 $this->meth_Merge_BlockSections($Txt, $LocR, $Src, $RecSpe);
             }
             $Src->DataClose();
             // Close the resource
         }
         if (!$WasP1) {
             $NbrRecTot += $Src->RecNum;
             $BlockId++;
         }
         if ($LocR->FieldOutside) {
             $this->meth_Merge_FieldOutside($Txt, $Src->CurrRec, $Src->RecNum, $LocR->FOStop);
         }
     }
     // End of the merge
     unset($LocR);
     $this->_CurrBlock = $BlockSave;
     if ($ReturnData) {
         return $Src->RecSet;
     } else {
         unset($Src);
         return $NbrRecTot;
     }
 }
Пример #2
0
function meth_Merge_Block(&$Txt,&$BlockName,&$SrcId,&$Query,$PageSize,$PageNum,$RecKnown) {

	// Get source type and info
	$Src = new clsTbsDataSource;
	$Src->BlockName = $BlockName;
	if (!$Src->DataPrepare($SrcId,$this)) return 0;

	$BlockId = 0;
	$BlockLst = explode(',',$BlockName);
	$BlockNbr = count($BlockLst);
	$WasP1 = false;
	$NbrRecTot = 0;
	$QueryZ =& $Query;

	while ($BlockId<$BlockNbr) {

		$RecStop = 0; // Stop the merge after this row
		$RecSpe = 0;  // Row with a special block's definition (used for the navigation bar)
		$QueryOk = true;
		$NoFct = true;
		$Src->BlockName = trim($BlockLst[$BlockId]);

		// Search the block
		$LocR = $this->meth_Locator_FindBlockLst($Txt,$Src->BlockName,0);

		if ($LocR->BlockFound) {
			if ($LocR->SpecialBid!==false) $RecSpe = $RecKnown;
			// OnSection
			if (isset($LocR->PrmLst['onsection'])) {
				$LocR->OnSecInfo = $LocR->PrmLst['onsection'];
				$ErrMsg = false;
				if ($this->meth_Misc_UserFctCheck($LocR->OnSecInfo,$ErrMsg)) {
					$LocR->OnSecPrm = array($BlockName,'','','');
					$NoFct = false;
				} else {
					$this->meth_Misc_Alert('Block definition \''.$BlockName.'\'',$ErrMsg);
				}
			}
			// OnData
			if (isset($LocR->PrmLst['ondata'])) {
				if ($LocR->PrmLst['ondata']!==$Src->OnDataSave) {
					$Src->OnDataSave = $LocR->PrmLst['ondata'];
					$Src->OnDataInfo = $Src->OnDataSave;
					$ErrMsg = false;
					if ($this->meth_Misc_UserFctCheck($Src->OnDataInfo,$ErrMsg)) {
						$Src->OnDataPrm = array($BlockName,'','');
					} else {
						$Src->OnDataInfo = false;
						$this->meth_Misc_Alert('Block definition \''.$BlockName.'\'',$ErrMsg);
					}
				}
			}
			// Dynamic query
			if ($LocR->P1) {
				if (is_string($Query)) {
					$Src->RecSaved = false;
					unset($QueryZ); $QueryZ = ''.$Query;
					$i = 1;
					do {
						$x = 'p'.$i;
						if (isset($LocR->PrmLst[$x])) {
							$QueryZ = str_replace('%p'.$i.'%',$LocR->PrmLst[$x],$QueryZ);
							$i++;
						} else {
							$i = false;
						}
					} while ($i!==false);
				}
				$WasP1 = true;
			} elseif (($Src->RecSaved===false) and ($BlockNbr-$BlockId>1)) {
				$Src->RecSaving = true;
			}
		} else {
			if ($WasP1) {
				$QueryOk = false;
				$WasP1 = false;
			} else {
				$RecStop = 1;
			}
		}

		// Open the recordset
		if ($QueryOk) {
			if ((!$LocR->BlockFound) and (!$LocR->FieldOutside)) {
				$QueryOk = false;
			}	else {
				$QueryOk = $Src->DataOpen($QueryZ,$PageSize,$PageNum,$RecStop);
			}
		}

		// Merge sections
		if ($QueryOk) {
			if ($Src->Type===4) { // Special for Text merge
				if ($LocR->BlockFound) {
					$Src->RecNum = 1;
					$Src->CurrRec = false;
					if ($NoFct===false) {
						$LocR->OnSecPrm[1] =& $Src->CurrRec ; $LocR->OnSecPrm[2] =& $Src->RecSet; $LocR->OnSecPrm[3] =& $Src->RecNum;
						call_user_func_array($LocR->OnSecInfo,$LocR->OnSecPrm);
					}
					$Txt = substr_replace($Txt,$Src->RecSet,$LocR->PosBeg,$LocR->PosEnd-$LocR->PosBeg+1);
				} else {
					$Src->DataAlert('Can\'t merge the block with a text value because the block definition is not found.');
				}
			} else { // Other data source type
				$Src->DataFetch();
				if ($LocR->BlockFound!==false) $this->meth_Merge_BlockSections($Txt,$LocR,$Src,$NoFct,$RecSpe,$RecStop);
				// Mode Page: Calculate the value to return
				if (($PageSize>0) and ($Src->RecNum>=$RecStop)) {
					if ($RecKnown<0) { // Pass pages in order to count all records
						do {
							$Src->DataFetch();
						} while ($Src->CurrRec!==false);
					} else { // We know that there is more records
						if ($RecKnown>$Src->RecNum) $Src->RecNum = $RecKnown;
					}
				}
			}
			$Src->DataClose(); // Close the resource
		}

		if (!$WasP1) {
			$NbrRecTot += $Src->RecNum;
			if ($LocR->FieldOutside and $QueryOk) {
				// Merge last record on the entire template
				$Pos = 0;
				$ChkSub = ($Src->CurrRec!==false);
				while ($Loc = $this->meth_Locator_FindTbs($Txt,$Src->BlockName,$Pos,'.')) {
					if ($Loc->SubName==='#') {
						$Pos = $this->meth_Locator_Replace($Txt,$Loc,$Src->RecNum,false);
					} else {
						$Pos = $this->meth_Locator_Replace($Txt,$Loc,$Src->CurrRec,$ChkSub);
					}
				}
			}
			$BlockId++;
		}

	} // -> while ($BlockId<$BlockNbr) {...

	// End of the merge
	unset($Src); unset($LocR); return $NbrRecTot;

}