CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
searchpage.php330 linesDownload Raw Back to classes
1<?php2class SearchPage extends RunnerPage3{	4	public $searchControllerId;5	public $searchControlBuilder;6	public $tableSettings = array();7	8	public $reportName;9	public $chartName;10	public $layoutVersion;11	12	public $needSettings = false;13	14	/**15	 * The field that is to be loaded in the SEARCH_LOAD_CONTROL mode16	 */17	public $ctrlField;18 19	public $extraPageParams;20	21	22	/**23	 * @constructor24	 */25	function __construct(&$params)26	{27		parent::__construct($params);28		29		if( $this->getLayoutVersion() === PD_BS_LAYOUT ) 30		{31			$this->headerForms = array( "top" );32			$this->footerForms = array( "below-grid" );33			$this->bodyForms = array( "grid" );34		} 35		else 36		{		37			$this->formBricks["header"] = "searchheader";38			$this->formBricks["footer"] = "searchbuttons";39		}40		41		if( count( $this->extraPageParams ) )42			$this->jsSettings["tableSettings"][ $this->tName ]["extraSearchPageParams"] = $this->extraPageParams;43		44		$this->jsSettings["tableSettings"][ $this->tName ]["searchPageFields"] = $this->pSet->getAdvSearchFields();45	}46		47	public function init() 48	{49		parent::init(); 50 51		$this->searchControlBuilder = new AdvancedSearchControl($this->searchControllerId, $this->tName, $this->searchClauseObj, $this);52	}53	54	/**55	 * Assign seesion prefix56	 */57	protected function assignSessionPrefix() 58	{59		if( $this->mode == SEARCH_DASHBOARD )60			$this->sessionPrefix = $this->dashTName."_".$this->tName;61		else62			$this->sessionPrefix = $this->tName;63	}	64	65	public function displaySearchControl() 66	{67		$this->searchControlBuilder = new PanelSearchControl($this->searchControllerId, $this->tName, $this->searchClauseObj, $this);68		$defaultValue = $this->pSet->getDefaultValue( $this->ctrlField );69		$ctrlBlockArr = $this->searchControlBuilder->buildSearchCtrlBlockArr($this->id, $this->ctrlField, 0, '', false, true, $defaultValue, '');	70		71		// build array for encode72		$resArr = array();73		$resArr['control1'] = trim($this->xt->call_func($ctrlBlockArr['searchcontrol']));74		$resArr['control2'] = trim($this->xt->call_func($ctrlBlockArr['searchcontrol1']));75		$resArr['comboHtml'] = trim($ctrlBlockArr['searchtype']);76		$resArr['delButt'] = trim($ctrlBlockArr['delCtrlButt']);77		$resArr['delButtId'] = trim( $this->searchControlBuilder->getDelButtonId( $this->ctrlField, $this->id ) );78		$resArr['divInd'] = trim($this->id);	79		$resArr['fLabel'] = GetFieldLabel( GoodFieldName($this->tName), GoodFieldName( $this->ctrlField ) );80		$resArr['ctrlMap'] = $this->controlsMap['controls'];81		82		if( $this->needSettings == 'true' )83		{84			$this->fillSettings();85			$resArr['settings'] = $this->jsSettings;86		}87		88		// return JSON89		echo printJSON($resArr);90		exit();	91	}92	93	public function process() 94	{95		if( $this->eventsObject->exists("BeforeProcessSearch") )96			$this->eventsObject->BeforeProcessSearch( $this );		97		98		$this->prepareSearchRadio();99		$this->prepareFields();100		101		$this->addButtonHandlers();102		103		$this->addCommonJs();104		$this->doCommonAssignments();105		$this->prepareCollapseButton();106 107		$this->fillSetCntrlMaps();108		109		$this->displaySearchPage();110	}111	112	protected function prepareSearchRadio()113	{114		$searchRadio = $this->searchControlBuilder->getSearchRadio();115		$this->xt->assign_section("all_checkbox_label", $searchRadio['all_checkbox_label'][0], $searchRadio['all_checkbox_label'][1]);116		$this->xt->assign_section("any_checkbox_label", $searchRadio['any_checkbox_label'][0], $searchRadio['any_checkbox_label'][1]);117		$this->xt->assignbyref("all_checkbox", $searchRadio['all_checkbox']);118		$this->xt->assignbyref("any_checkbox", $searchRadio['any_checkbox']);119	}	120 121	protected function prepareFields()122	{123		foreach( $this->pSet->getAdvSearchFields() as $field )124		{125			$gfield = GoodFieldName( $field );126			$lookupTable = $this->pSet->getLookupTable( $field );127			if( $lookupTable )128				$this->settingsMap["globalSettings"]['shortTNames'][ $lookupTable ] = GetTableURL( $lookupTable );129	130			$srchFields = $this->searchClauseObj->getSearchCtrlParams( $field );131			$firstFieldParams = array();132			if( count( $srchFields ) )133			{134				$firstFieldParams = $srchFields[0];135			}136			else137			{138				$firstFieldParams['fName'] = $field;139				$firstFieldParams['eType'] = '';140				$firstFieldParams['value1'] = $this->pSet->getDefaultValue( $field );141				$firstFieldParams['value2'] = '';142				$firstFieldParams['not'] = false;143				$firstFieldParams['opt'] = $this->pSet->getDefaultSearchOption( $field );144				$firstFieldParams['not'] = false;145				if ( substr($firstFieldParams['opt'], 0, 4) == 'NOT ' )146				{147					$firstFieldParams['opt'] = substr($firstFieldParams['opt'], 4);148					$firstFieldParams['not'] = true;149				}150			}151	// create control	152			$ctrlBlockArr = $this->searchControlBuilder->buildSearchCtrlBlockArr($this->id, $firstFieldParams['fName'], 0, $firstFieldParams['opt'], $firstFieldParams['not'], false, $firstFieldParams['value1'], $firstFieldParams['value2']);	153			if($firstFieldParams['opt'] == "")154			{155				$firstFieldParams['opt'] = $this->pSet->getDefaultSearchOption($firstFieldParams['fName']);156			}157			$srchTypeFull = $this->searchControlBuilder->getCtrlSearchType($firstFieldParams['fName'], $this->id, 0, $firstFieldParams['opt'], $firstFieldParams['not'], true, true);158			159			if( $this->is508 )160				$this->xt->assign_section( $gfield . "_label", "<label for=\"". $this->getInputElementId( $field, $this->pSet )."\">", "</label>");161			else 162				$this->xt->assign( $gfield . "_label", true);163 164			if ( $this->isBootstrap() )165			{			166				$firstElementId = $this->getControl($field, $this->id)->getFirstElementId();167				if ( $firstElementId )168				{169					$this->xt->assign("labelfor_" . $gfield, $firstElementId);170				}171			}172			173			$this->xt->assign( $gfield . "_fieldblock", true);174			$this->xt->assignbyref( $gfield . "_editcontrol", $ctrlBlockArr['searchcontrol']);175			$this->xt->assign( $gfield . "_notbox", $ctrlBlockArr['notbox']);176			// create second control, if need it177			$this->xt->assignbyref( $gfield . "_editcontrol1", $ctrlBlockArr['searchcontrol1']);178			// create search type select179			$this->xt->assign("searchtype_" . $gfield, $ctrlBlockArr['searchtype']);180			$this->xt->assign("searchtypefull_" . $gfield, $srchTypeFull);181			182			$isFieldNeedSecCtrl = $this->searchControlBuilder->isNeedSecondCtrl( $field );183			$ctrlInd = 0;184			if( $isFieldNeedSecCtrl )185			{186				$this->controlsMap["search"]["searchBlocks"][] = array( 'fName'=> $field , 'recId'=> $this->id, 'ctrlsMap'=> array(0=> $ctrlInd, 1=> ($ctrlInd + 1)) );187				$ctrlInd+=2;188			}189			else190			{191				$this->controlsMap["search"]["searchBlocks"][] = array( 'fName'=> $field , 'recId'=> $this->id, 'ctrlsMap'=> array(0=> $ctrlInd) );			192				$ctrlInd++;193			}	194		}195	}196 197	198	protected function doCommonAssignments()199	{200 201		if ( $this->isBootstrap() )202		{203			if ( $this->mode === SEARCH_SIMPLE )204			{205				$this->headerCommonAssign();206			}207			else208			{209				$this->xt->assign("menu_chiddenattr", "data-hidden" );210			}211		}212		213		$this->setLangParams();214		215		if( $this->mode !== SEARCH_DASHBOARD ) 216			$this->assignBody();217		218		$this->xt->assign("contents_block", true);219		$this->xt->assign("conditions_block", true);220		$this->xt->assign("search_button", true);221		$this->xt->assign("reset_button", true);222		223	224		$this->xt->assign("searchbutton_attrs", "id=\"searchButton".$this->id."\"");225		$this->xt->assign("resetbutton_attrs", "id=\"resetButton".$this->id."\"");226		227		$this->xt->assign( "searchheader", true );228		$this->xt->assign( "searchbuttons", true );229		230		if( $this->mode !== SEARCH_DASHBOARD ) 231		{ 232			$this->xt->assign("back_button", true);233			$this->xt->assign("backbutton_attrs", "id=\"backButton".$this->id."\"");234		}235		236		//	webreports assignments237		if( $this->reportName )238		{239			$this->xt->assign( "dynamic", "true" );240			$this->xt->assign( "rname", $this->reportName );241		}242		243		if( $this->chartName )244		{245			$this->xt->assign( "dynamic", "true" );246			$this->xt->assign( "cname", $this->chartName );247		}248		249		if( $this->isPD() )250		{251			$this->xt->assign( "cancel_button", $this->mode == SEARCH_POPUP );252			$this->xt->assign( "back_button", $this->mode != SEARCH_POPUP );253		}254	}255	256	protected function displaySearchPage()257	{258		$templateFile = $this->templatefile;259		if( $this->eventsObject->exists("BeforeShowSearch") )260			$this->eventsObject->BeforeShowSearch( $this->xt, $templateFile, $this );261		262		if( $this->mode == SEARCH_SIMPLE )263		{264			$this->display( $templateFile );265			return;266		}267		268		$this->xt->assign("header", false);269		$this->xt->assign("footer", false);270		$this->xt->assign("body", $this->body);271		272		$this->displayAJAX( $templateFile, $this->flyId + 1 );273		exit();274	}275	276	function getLayoutVersion() 277	{278		if( $this->layoutVersion )279			return $this->layoutVersion;280			281		return parent::getLayoutVersion();282	}283	284	/**285	 * @return Array286	 */287	public static function getExtraPageParams()288	{289		$prms = array();290		291		//crosstable params292		$prms["x"] = postvalue("x");293		$prms["y"] = postvalue("y");294		$prms["data"] = postvalue("data");295		296		if( !strlen( $prms["x"] ) &&  !strlen( $prms["y"] ) && !strlen( $prms["data"] ) )297			return array();298			299		$prms["op"] = postvalue("op");300		$prms["xtype"] = postvalue("xtype");301		$prms["ytype"] = postvalue("ytype");	302	303		return $prms;304	}305	306	protected function checkShowBreadcrumbs() 307	{308		return $this->mode == SEARCH_SIMPLE;309	}310 311	public static function readSearchModeFromRequest()312	{313		$mode = postvalue("mode"); 314		315		if( $mode == "dashsearch" )316			return SEARCH_DASHBOARD;317		318		if( $mode == "inlineLoadCtrl" )319		{320			// load search panel control321			return SEARCH_LOAD_CONTROL;322		}323 324		if( postvalue("onFly") )325			return SEARCH_POPUP;326		327		return SEARCH_SIMPLE;328	}329}330?>