CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
chartpage.php374 linesDownload Raw Back to classes
1<?php2class ChartPage extends RunnerPage3{4	/**5	 * show message block6	 */7	public $show_message_block = false;8 9	/**10	 * @constructor11	 */12	function __construct(&$params = "")13	{14		parent::__construct($params);15	16		$this->bodyForms = array( "grid" );17	18		$this->jsSettings['tableSettings'][ $this->tName ]['simpleSearchActive'] = $this->searchClauseObj->simpleSearchActive;19		20		if( $this->mode == CHART_DASHBOARD ) {21			$this->pageData['detailsMasterKeys'] = $this->getStartMasterKeys();22		}23		$this->pageData['singleChartPage'] = $this->pSet->getChartCount() == 1;24	}25 26	/**27	 * Set the page's session prefix28	 */29	protected function assignSessionPrefix()30	{31		if( $this->mode == CHART_DASHBOARD )32			$this->sessionPrefix = $this->dashTName."_".$this->tName;33		else34			$this->sessionPrefix = $this->tName;35	}	36	37	/**38	 * Process the page 39	 */40	public function process()41	{42		if( $this->mode == CHART_DASHDETAILS43			|| $this->mode == CHART_DETAILS && ( $this->masterPageType == PAGE_LIST || $this->masterPageType == PAGE_REPORT ))44			$this->updateDetailsTabTitles();45 46 47		//	Before Process event48		if( $this->eventsObject->exists("BeforeProcessChart") )49			$this->eventsObject->BeforeProcessChart( $this );50					51		52		// build tabs and set current53		$this->processGridTabs();54 55		$this->doCommonAssignments();56		$this->addButtonHandlers();57		$this->addCommonJs();58		$this->commonAssign();59 60		if( $this->mode != CHART_DASHBOARD ) {61			$this->buildSearchPanel();62			$this->assignSimpleSearch();63		}64		65		// to restore correctly within a chart class66		$_SESSION[ $this->sessionPrefix.'_advsearch' ] = serialize( $this->searchClauseObj );67		68		// display the 'Back to Master' link and master table info69		$this->displayMasterTableInfo();70 71		$this->showPage();		72	}73 74	function callBeforeQueryEvent( $dc ) {75		if( !$this->eventsObject->exists("BeforeQueryChart") ) {76			return;77		}78		$prep = $this->dataSource->prepareSQL( $dc );79		$where = $prep["where"];80		$order = $prep["order"];81		$sql = $prep["sql"];82		$this->eventsObject->BeforeQueryChart($sql, $where, $order );83 84		if( $sql != $prep["sql"] )85			$this->dataSource->overrideSQL( $dc, $sql );86		else {87			if( $where != $prep["where"] )88				$this->dataSource->overrideWhere( $dc, $where );89			if( $order != $prep["order"] ) 90				$this->dataSource->overrideOrder( $dc, $order );91		}92	} 93 94 95 96	function getMasterCondition() {97		if( $this->mode == CHART_DASHBOARD )98			return null;99		100		return parent::getMasterCondition();101	}102	103	/**104	 * Get started master keys105	 * @return Array106	 */107	public function getStartMasterKeys()108	{		109		$detailTablesData = $this->pSet->getDetailTablesArr();110		if( !$detailTablesData ) {111			return array();112		}113		114		$dc = $this->getSubsetDataCommand();	115		$dc->reccount = 1;116 117		$rs = $this->dataSource->getList( $dc );118		if( !$rs ) {119			showError( $this->dataSource->lastError() );120		}121 122		$data = $this->cipherer->DecryptFetchedArray( $rs->fetchAssoc() );123		124		$masterKeysArr = array();125		foreach ( $detailTablesData as $detailId => $detail ) {126			foreach( $detail['masterKeys'] as $idx => $mk ) {127				$masterKeysArr[ $detail['dDataSourceTable'] ] = array( 'masterkey'.($idx + 1) => $data[$mk] );128			}129		}130 131		return $masterKeysArr;132	}133	134	/**135	 *136	 */137	public function doCommonAssignments()138	{139		140		//set the Search panel141		$this->xt->assign("searchPanel", true);142 143		if( $this->isShowMenu() )144			$this->xt->assign("menu_block", true);		145 146		$this->setLangParams();147	148		$this->xt->assign("chart_block", true);149		$this->xt->assign("asearch_link", true);150		$this->xt->assign("exportpdflink_attrs", "onclick='chart.saveAsPDF();'");151		$this->xt->assign("advsearchlink_attrs", "id=\"advButton".$this->id."\"");152 153		if( !GetChartXML( $this->shortTableName ) )154			$this->xt->assign("chart_block", false);			155		156		$this->xt->assign("message_block", true);157		158		if( ($this->mode == CHART_SIMPLE || $this->mode == CHART_DASHBOARD) && $this->pSet->noRecordsOnFirstPage() && !$this->searchClauseObj->isSearchFunctionalityActivated() )159		{160			$this->show_message_block = true;161			$this->hideElement("chart");162			$this->xt->assign("chart_block", false);163 164			$this->xt->assign("message", $this->noRecordsMessage());165			$this->xt->assign( "message_class", "alert-warning");166		}		167 168		if( !$this->show_message_block )169			$this->hideElement("message");170 171		if( $this->mobileTemplateMode() )172			$this->xt->assign('tableinfomobile_block', true);173 174		175		$this->assignChartElement();176		177		$this->body['begin'].= GetBaseScriptsForPage( $this->isDisplayLoading );178		if( !$this->isDashboardElement() && !$this->mobileTemplateMode() )179			$this->body['begin'].= "<div id=\"search_suggest\" class=\"search_suggest\"></div>";180 181		// assign body end182		$this->body['end'] = XTempl::create_method_assignment( "assignBodyEnd", $this);183 184		$this->xt->assignbyref('body', $this->body);	185	}	186	187	/**188	 * Set the chart xt variable189	 */190	public function assignChartElement()191	{192	}193	194	/**195	 *196	 */197	public function prepareDetailsForEditViewPage()198	{199		$this->addButtonHandlers();200		201		$this->xt->assign("body", $this->body);202		$this->xt->assign("chart_block", true);203		$this->xt->assign("message_block", true);		204	}205	206	protected function getExtraAjaxPageParams()207	{208		$returnJSON = array();209		if( $this->mode == REPORT_DETAILS )210		{		211			$returnJSON['headerCont'] = $this->getProceedLink()	. $returnJSON['headerCont'];212		}		213		214		return $returnJSON;215	}216	217	public function beforeShowChart()218	{219		if( $this->eventsObject->exists("BeforeShowChart") )220			$this->eventsObject->BeforeShowChart($this->xt, $this->templatefile, $this);	221	}222	223	public function showPage()224	{225		$this->beforeShowChart();226	227		if( $this->mode == CHART_DETAILS || $this->mode == CHART_DASHBOARD || $this->mode == CHART_DASHDETAILS )228		{229			$this->addControlsJSAndCSS();230			$this->fillSetCntrlMaps();231			232			$this->xt->assign("header", false);233			$this->xt->assign("footer", false);234			235			$this->body["begin"] = "";236			$this->body["end"] = "";237			$this->xt->assign("body", $this->body);	238 239			$this->displayAJAX($this->templatefile, $this->id + 1);240			exit();241		}242 243		if( $this->mode == CHART_POPUPDETAILS ) //currently unused244		{245			$this->xt->assign("header", false);246			$this->xt->assign("footer", false);247			$this->body["begin"] = '';248			$this->body["end"] = '';249			250			$this->xt->prepare_template($this->templatefile);251			$respArr = array();252			$respArr['success'] = true;	253			$respArr['body'] = $this->xt->fetch_loaded("body");254			$respArr['counter'] = postvalue('counter');255			$this->xt->assign("container_master", false);256			257			echo printJSON($respArr);258			exit();259		}260			261		$this->display( $this->templatefile );			262	}263	264	/**265	 *266	 */267	function processGridTabs() 268	{	269		$ctChanged = parent::processGridTabs();270		$_SESSION[ $this->sessionPrefix . "_chartTabWhere" ] = $this->getCurrentTabWhere();271		272		return $ctChanged;273	}274 275	function gridTabsAvailable() {276		return true;277	}278	279	function displayTabsInPage() 280	{281		return $this->simpleMode() 282			|| ( $this->mode == CHART_DETAILS && ($this->masterPageType == PAGE_VIEW || $this->masterPageType == PAGE_EDIT))283			|| $this->mode == CHART_DASHBOARD && $this->dashElementData["tabLocation"] == "body";284	}285	286	protected function getBodyMarkup( $templatefile )287	{288		if( $this->mode == CHART_DASHBOARD && $this->dashElementData["tabLocation"] == "body" )289			return $this->fetchBlocksList( array( "above-grid_block", "grid_tabs", "grid_block" ) );290		291		return parent::getBodyMarkup( $templatefile );292	}	293	294	function element2Item( $name ) {295		if( $name == "message" ) {296			return array( "grid_message" );297		}298		if( $name == "chart" ) {299			return array( "chart" );300		}301		return parent::element2Item( $name );302	}303 304	public function prepareDisplayDetails() 305	{306		$resizeChart = true;307		if( $this->mode == CHART_SIMPLE || 308			$this->mode == CHART_DASHBOARD || 309			$this->mode == CHART_DETAILS && ( $this->masterPageType == PAGE_VIEW || $this->masterPageType == PAGE_EDIT ) )310			$resizeChart = false;311			312		//set params for the 'xt_showchart' method showing the chart313		$chartXtParams = array(314			"id" => $this->id,315			"table" => $this->tName, 316			"ctype" => $this->pSet->getChartType(), 317			"resize" => $resizeChart,318			"chartName" => $this->shortTableName,319			"chartPreview" => $this->mode !== CHART_SIMPLE && $this->mode != CHART_DASHBOARD320		);321 322		if( $this->mode == CHART_DASHBOARD || $this->mode == CHART_DASHDETAILS )323		{324				$chartXtParams["refreshTime"] = $this->dashElementData["reload"];325		}326		327		$this->prepareCharts();328		$forms = array( "grid" );329		$bodyContents = $this->fetchForms($forms);		330		$this->renderedBody = '<div id="detailPreview'.$this->id.'">'.$bodyContents.'</div>';	331		return;332	}333 334	public function showGridOnly() 335	{			336		echo $this->renderedBody;337	}338	339	function prepareCharts() 340	{341		$chartXtParams =  array( 342			"id" => $this->id,343			// it shows if chart show details344			"chartPreview" => $this->mode !== CHART_SIMPLE && $this->mode != CHART_DASHBOARD,345			"stateLink" => $this->getStateUrlParams()346		);347		348		if( $this->dashTName && $this->mode == CHART_DASHBOARD )349		{350			$chartXtParams["dash"] = true;351			$chartXtParams["dashTName"] = $this->dashTName;352			$chartXtParams["dashElementName"] = $this->dashElementName;353			$chartXtParams["dashPage"] = $this->dashPage;354		}355		356		$this->xt->assign_function("chart", "xt_showpdchart", $chartXtParams);357	}358 359	public static function readChartModeFromRequest()360	{361		$mode = postvalue("mode");362		if( $mode == "listdetails" )363			return CHART_DETAILS;364		elseif( $mode == "listdetailspopup" )365			return CHART_POPUPDETAILS;366		elseif( $mode == "dashchart" )367			return CHART_DASHBOARD;368		elseif( $mode == "dashdetails" )369			return CHART_DASHDETAILS;370		else371			return CHART_SIMPLE;372	}373}374?>