CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
searchpage_dash.php217 linesDownload Raw Back to classes
1<?php2include_once(getabspath("classes/searchpage.php"));3class SearchPageDash extends SearchPage4{	5	public $tableSettings = array();6	7	function __construct(&$params)8	{9		parent::__construct($params);10		11		if ($this->mode == SEARCH_DASHBOARD)12		{13			$this->jsSettings['tableSettings'][ $this->tName ]['isDashSearchPage'] = true;14		}15	}16	17	protected function assignSessionPrefix() 18	{19		$this->sessionPrefix = $this->tName;20	}21	22	protected function getTableSettings( $table )23	{24		if( !isset( $this->tableSettings[ $table ]) )25		{26			$this->tableSettings[ $table ] = new ProjectSettings( $tableSettings[ $table ], PAGE_SEARCH );27		}28		return $this->tableSettings[ $table ];29	30	}31 32	protected function prepareFields()33	{	34		$pageFields = $this->pSet->getPageFields();35		foreach( $this->pSet->getDashboardSearchFields() as $f => $fdata )36		{37			if( array_search( $f, $pageFields ) === false ) {38				continue;39			}40			$field = $fdata[0]["field"];41			$table = $fdata[0]["table"];42			$fSet = $this->getTableSettings( $table );43			$lookupTable = $fSet->getLookupTable( $field );44			if( $lookupTable )45				$this->settingsMap["globalSettings"]['shortTNames'][ $lookupTable ] = GetTableURL( $lookupTable );46	47			$srchFields = $this->searchClauseObj->getSearchCtrlParams( $f );48			$firstFieldParams = array();49			if (count($srchFields))50			{51				$firstFieldParams = $srchFields[0];52			}53			else54			{55				$firstFieldParams['fName'] = $f;56				$firstFieldParams['eType'] = '';57				$firstFieldParams['value1'] = $this->pSet->getDefaultValue( $field, $table );58				$firstFieldParams['value2'] = '';59				$firstFieldParams['not'] = false;60				$firstFieldParams['opt'] = $this->pSet->getDefaultSearchOption( $f );61				$firstFieldParams['not'] = false;62				if ( substr($firstFieldParams['opt'], 0, 4) == 'NOT ' )63				{64					$firstFieldParams['opt'] = substr($firstFieldParams['opt'], 4);65					$firstFieldParams['not'] = true;66				}67			}68	// create control	69			$ctrlBlockArr = $this->searchControlBuilder->buildSearchCtrlBlockArr($this->id, $firstFieldParams['fName'], 0, $firstFieldParams['opt'], $firstFieldParams['not'], false, $firstFieldParams['value1'], $firstFieldParams['value2']);	70			if($firstFieldParams['opt'] == "")71			{72				$firstFieldParams['opt'] = $this->pSet->getDefaultSearchOption($firstFieldParams['fName']);73			}74			$srchTypeFull = $this->searchControlBuilder->getCtrlSearchType($firstFieldParams['fName'], $this->id, 0, $firstFieldParams['opt'], $firstFieldParams['not'], true, true);75			76			if(isEnableSection508())77				$this->xt->assign_section( $f . "_label","<label for=\"". $this->getInputElementId( $field, $fSet )."\">","</label>");78			else 79				$this->xt->assign( $f . "_label", true);80			81			$this->xt->assign( $f . "_fieldblock", true);82			$this->xt->assignbyref( $f . "_editcontrol", $ctrlBlockArr['searchcontrol']);83			$this->xt->assign( $f . "_notbox", $ctrlBlockArr['notbox']);84			// create second control, if need it85			$this->xt->assignbyref( $f . "_editcontrol1", $ctrlBlockArr['searchcontrol1']);86			// create search type select87			$this->xt->assign("searchtype_" . $f, $ctrlBlockArr['searchtype']);88			$this->xt->assign("searchtypefull_" . $f, $srchTypeFull);89			$isFieldNeedSecCtrl = $this->searchControlBuilder->isNeedSecondCtrl($f);90			$ctrlInd = 0;91			if ($isFieldNeedSecCtrl)92			{93				$this->controlsMap["search"]["searchBlocks"][] = array('fName'=> $f , 'recId'=>$this->id, 'ctrlsMap'=>array(0=>$ctrlInd, 1=>($ctrlInd+1)));94				$ctrlInd+=2;95			}96			else97			{98				$this->controlsMap["search"]["searchBlocks"][] = array('fName'=> $f , 'recId'=>$this->id, 'ctrlsMap'=>array(0=>$ctrlInd));			99				$ctrlInd++;100			}101		}102	}103	104	function fillFieldSettings()105	{		106		$arrFields = $this->pSet->getAllSearchFields();107		$this->addFieldsSettings($arrFields, null, $this->pageType);108	}109    110	function locateDashFieldByOriginal( $table, $field )111	{112		foreach($this->pSet->getDashboardSearchFields() as $fname => $data)113		{114			if( !$data )115				continue;116			if( $data[0]["table"] == $table && $data[0]["field"] == $field )117			{118				return $fname;119			}120		}121		return $fname;122	}123	124	125	function addFieldsSettings($arrFields, $pSet, $pageType)126	{127		$dashSearchFields = $this->pSet->getDashboardSearchFields();128		$tableSettingsFilled = array();129		foreach($arrFields as $fieldName)130		{131			$tableName = $dashSearchFields[$fieldName][0]["table"];132			$pSet = new ProjectSettings( $tableName, $pageType);133			$tableFieldName = $dashSearchFields[$fieldName][0]["field"];134			135			if( !$tableSettingsFilled[ $tableName ] )136			{137				$this->fillTableSettings( $tableName, $pSet );138				$tableSettingsFilled[ $tableName ] = true;139			}140			if( !array_key_exists($fieldName, $this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings']) )141				$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ] = array();142			143			if( !array_key_exists($pageType, $this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ]) )144				$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ] = array();145						146			foreach($this->settingsMap["fieldSettings"] as $key => $val)147			{148				$fData = $pSet->getFieldData($tableFieldName, $key);149				150				if( $key == "validateAs" )151				{152					if( $pageType == PAGE_ADD || $pageType == PAGE_EDIT || $pageType == PAGE_REGISTER ) 153						$this->fillValidation($fData, $val, $this->jsSettings['tableSettings'][ $this->tName]['fieldSettings'][ $fieldName ][ $pageType ]);154					continue;155				}156				157				if( $key == "RTEType" )158				{159					$fData = $pSet->getRTEType($tableFieldName);160					if($fData == "RTECK")161					{162						$this->isUseCK = true;163						$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ]['nWidth'] = $pSet->getNCols($tableFieldName);164						$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ]['nHeight'] = $pSet->getNRows($tableFieldName);165					}	166				}167				elseif( $key == "autoCompleteFields" )168				{169					$fData = $pSet->getAutoCompleteFields($tableFieldName);170				}171				elseif( $key == "parentFields" )172				{173					$fData = $pSet->getLookupParentFNames( $tableFieldName );174					foreach( $fData as $i => $parentField )175					{176						$fData[$i] = $this->locateDashFieldByOriginal( $tableName, $parentField );177					}178				}179				180				$isDefault = false;181				if( is_array($fData) )182				{183					$isDefault = !$fData;184				}185				else if( !is_array($val['default']) )186				{187					$isDefault = $fData === $val['default'];188				}189				190				if( !$isDefault )191				{192					$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ][ $val['jsName'] ] = $fData;193				}194			}195			196			//add Dash Search-specific settings197			$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ][ 'originalTable' ] = $tableName;198			$this->jsSettings['tableSettings'][ $this->tName ]['fieldSettings'][ $fieldName ][ $pageType ][ 'originalField' ] = $tableFieldName;199			200			$this->jsSettings['tableSettings'][ $this->tName ]['isUseCK'] = $this->isUseCK;201			202			if( $this->googleMapCfg && $this->googleMapCfg['isUseGoogleMap'] )203			{204				$this->jsSettings['tableSettings'][ $this->tName ]['isUseGoogleMap'] = true;205				$this->jsSettings['tableSettings'][ $this->tName ]['googleMapCfg'] = $this->googleMapCfg;	206			}207			208			$lookupTableName = $pSet->getLookupTable($tableFieldName);209			if( $lookupTableName )210				$this->jsSettings['global']['shortTNames'][ $lookupTableName ] = GetTableURL($lookupTableName);211				212			if( $pSet->getEditFormat($tableFieldName) == 'Time' )213				$this->fillTimePickSettings( $tableFieldName, "", $pSet, $pageType, $fieldName );214		}215	}216}217?>