CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
dashboardpage.php558 linesDownload Raw Back to classes
1<?php2class DashboardPage extends RunnerPage3{4	protected $elementsPermissions = array();5 6	/**7	 * @constructor8	 * @param &Array params9	 */10	function __construct(&$params)11	{12		parent::__construct($params);13 14		if ( $params["mode"] == "dashsearch" ) {15			$showShowAllButton = $this->searchClauseObj->searchStarted();16			17			// set the first page for elements with pages18			foreach( $this->pSet->getDashboardElements() as $elem ) {19				if( $elem['type'] == DASHBOARD_LIST || $elem['type'] == DASHBOARD_REPORT ) {20					$elSessionPrefix = $elem['type'] == DASHBOARD_LIST 21						? $this->tName."_".$elem["elementName"]22						: $this->tName."_".$elem["table"] ;23					24					$_SESSION[ $elSessionPrefix."_pagenumber" ] = 1;25				}26			}27			28			$returnJSON = array("success" => true, 'show_all' => $showShowAllButton);29			echo printJSON( $returnJSON );30			exit();31		}32 33		// Set language params, if have more than one language34		$this->setLangParams();35 36		$this->jsSettings['tableSettings'][ $this->tName ]['dashElements'] = array();37 38		$majorElements = $this->getMajorElements();39 40		//	calculate additional element settings41		foreach( $this->pSet->getDashboardElements() as $key => $elem )42		{43			$this->createElementLinks( $elem );44			$permissions = false;45			$newElem = $elem;46 47			if( $elem['type'] == DASHBOARD_RECORD)48			{49				// check tables (add, view, edit) permissinons befor add to js50				$newElem['tabsPageTypes'] = array();51				foreach( $elem['tabsPageTypes'] as $idx => $pageType )52				{53					if( $this->CheckPermissions( $elem['table'], $pageType ) )54					{55						$permissions = true;56						$newElem['tabsPageTypes'][] = $pageType;57					}58				}59 60				$gridElem = $this->getGridElement( $elem['table'] );61				if( $gridElem ) {62					$eset = new ProjectSettings( $elem['table'], PAGE_LIST, $gridElem['pageName'] );63					$newElem['spreadsheetGrid'] = $eset->spreadsheetGrid();64					$newElem['hostListPage'] = $gridElem['pageName'];65				}66			}67			elseif( $elem['type'] == DASHBOARD_DETAILS)68			{69				$eset = new ProjectSettings( $elem['table'] );70				$details = $eset->getDetailTablesArr();71 72				// add details shortTableNames73				$newElem['details'] = array();74				foreach( $details as $idx => $d )75				{76					if( in_array( $d['dDataSourceTable'], $elem['notUsedDetailTables'] ) )77						continue;78 79					if( $this->CheckPermissions( $d['dDataSourceTable'], $d['dType'] ) )80					{81						$permissions = true;82						$d['pageName'] = $elem['details'][ $d['dDataSourceTable'] ]['pageName'];83						$newElem['details'][] = $d;84						$this->jsSettings['tableSettings'][ $d['dDataSourceTable'] ]['shortTName'] = $d[ 'dShortTable' ];85					}86				}87			}88			elseif( $elem['type'] == DASHBOARD_CHART || $elem['type'] == DASHBOARD_REPORT || $elem['type'] == DASHBOARD_SEARCH)89				$permissions = $this->CheckPermissions($elem['table'], "Search" );90			elseif( $elem['type'] == DASHBOARD_LIST )91				$permissions = $this->CheckPermissions( $elem['table'], "list" );92			elseif( $elem['type'] == DASHBOARD_MAP )93			{94				$permissions = $this->CheckPermissions( $elem['table'], "list" );95				if( !$elem["updateMoved"] )96					$newElem["updateMoved"] = !$this->hasGridElement( $elem['table'] );97			}98			elseif( $elem['type'] == DASHBOARD_SNIPPET )99			{100				$permissions = true;101			}102 103 104			$this->elementsPermissions[$key] = $permissions;105			if ( !$permissions )106				continue;107 108			if( isset( $majorElements[ $newElem["elementName"]] ) )109				$newElem["major"] = true;110 111			// add shortTableNames and element112			$this->jsSettings['tableSettings'][ $elem['table'] ]['shortTName'] = GetTableURL( $elem['table'] );113			$this->jsSettings['tableSettings'][ $this->tName ]['dashElements'][$key] = $newElem;114		}115	}116 117	function CheckPermissions( $table, $permis )118	{119		foreach( $this->getPermissionType( $permis ) as $val )120		{121			if( CheckTablePermissions( $table, $val ) )122				return true;123		}124 125		return false;126	}127 128	/**129	 * @param String $pageType130	 * @return Array permission types131	 */132	function getPermissionType($pageType)133	{134		$result = array();135		$type = parent::getPermisType($pageType);136 137		if ($pageType == "view" || $pageType == "chart" || $pageType == "report" || $pageType == "list")138			$type = "S";139		elseif ($pageType == "add")140			$type = "A";141		elseif ($pageType == "edit")142			$type = "E";143		/*elseif ($pageType == "list")144			$result = array("E", "S", "A");*/145 146		return $type ? array($type) : $result;147	}148 149	function init()150	{151		parent::init();152 153		$this->createElementContainers();154	}155 156	/**157	 *158	 */159	function createElementContainers()160	{161		foreach( $this->pSet->getDashboardElements() as $key => $elem )162		{163			if ( !$this->elementsPermissions[$key] )164				continue;165			$style = "";166 167				if( $elem["width"] )168					$selectors = array();169					//$selectors []= str_repeat( "[data-dbelement=\"".$elem["elementName"]."\"]", 5 );170					// $selectors []= "#dashelement_" . $elem["elementName"] . $this->id . " > .panel > .panel-body";171					$selectors []= "#dashelement_" . $elem["elementName"] . $this->id . " > * > .tab-content > * > * > * > .panel > .panel-body";172					$selectors []= "#dashelement_" . $elem["elementName"] . $this->id . " > * > .tab-content > * > * > .panel > .panel-body";173					$selectors []= "#dashelement_" . $elem["elementName"] . $this->id . " > .panel > .panel-body";174					$selectors []= "#dashelement_" . $elem["elementName"] . $this->id . " > .bs-containedpage > .panel > .panel-body";175 176 177					$style.= join(",\n", $selectors ) . " {178						width: " . $elem["width"] . "px;179						overflow-x: auto;180					}";181				if( $elem["height"] )182					$style .= "#dashelement_" . $elem["elementName"] . $this->id . " > .panel > .panel-body,183						#dashelement_" . $elem["elementName"] . $this->id . " > * > .tab-content > * > * > * > .panel > .panel-body,184						#dashelement_" . $elem["elementName"] . $this->id . " > * > .tab-content > * > * > .panel > .panel-body,185						#dashelement_" . $elem["elementName"] . $this->id . " > .bs-containedpage > .panel > .panel-body {186						height: " . $elem["height"] . "px;187						overflow-y: auto;188					}";189				if( $style != "" )190				{191					$style = "<style> @media (min-width: 768px){ " . $style . " } </style>";192				}193 194 195 196			$contentHtml = "";197			if ( $elem['type'] == DASHBOARD_SNIPPET ) {198				$snippetData = callDashboardSnippet( $this->tName, $elem );199				$contentHtml = $this->getSnippetHtml( $elem, $snippetData );200			}201 202			$dbElementAttrs = "";203			if( $elem["width"] ) {204				$dbElementAttrs .= " data-fixed-width";205			}206			if( $elem["height"] ) {207				$dbElementAttrs .= " data-fixed-height";208			}209			$dbElementAttrs .= ' data-dashtype="' . $elem['type'] . '"';210 211			$this->xt->assign( "db_".$elem["elementName"] , $contentHtml );212/*213			$this->xt->assign(214				"db_".$elem["elementName"] ,215				$style."<div ".$dbElementAttrs." id=\"dashelement_" . $elem["elementName"] . $this->id . "\">".$contentHtml."</div>"216			);217*/218 		}219	}220 221	/**222	 * Formation html code snippet panel223	 * @param String $headerCont224	 * @param String $bodyCont225	 * @param Integer $width226	 * @param Integer $height227	 * @return String html228	 */229	function getSnippetHtml( $elem, $snippetData )230	{231		$iconHtml = getIconHTML( $snippetData["icon"] );232		$style = $elem["item"]["snippetStyle"];233		if( !$style ) {234			$style = "classic";235		}236		if( $style == 'classic' ) {237			$headerCont = '<div class="panel-heading">' . $iconHtml . $snippetData["header"] . '</div>';238			$bodyCont = '<div class="panel-body">' . $snippetData["body"] . '</div>';239			$html = '<div class="panel panel-'.$elem["panelStyle"].'">' . $headerCont . $bodyCont . '</div>';240		} else if( $style == 'left' ) {241			$iconHtml = '<div class="r-box-icon">' . $iconHtml . '</div>';242			$html = '<div class="r-box-left">'243					. $iconHtml244					.'<div class="r-box-text">'245						.'<div class="r-box-header">'246							.$snippetData["header"]247						.'</div>'248						.'<div class="r-box-body">'249							.$snippetData["body"]250						.'</div>'251					.'</div>'252				.'</div>';253		} else if( $style == 'right' ) {254			$iconHtml = '<div class="r-box-icon">' . $iconHtml . '</div>';255			$footer = $snippetData["footer"]256				? '<div class="r-box-footer">' . $snippetData["footer"] . '</div>'257				: '';258			$html = '<div class="r-box-right">'259					.'<div class="r-box-main">'260						.'<div class="r-box-text">'261							.'<div class="r-box-header">'262								.$snippetData["header"]263							.'</div>'264							.'<div class="r-box-body">'265								.$snippetData["body"]266							.'</div>'267						.'</div>'268						. $iconHtml269					.'</div>'270					. $footer271				.'</div>';272		}273 274		return $html;275	}276 277	/**278	 * Clear the page's and elements pages' session keys279	 * if the page is loaded with "empty" params280	 */281	function clearSessionKeys()282	{283		if ( count($_POST) && $_POST["mode"] == "dashsearch" )284		{285			return;286		}287 288		parent::clearSessionKeys();289 290		if( IsEmptyRequest() )291		{292			$this->unsetAllPageSessionKeys();293		}294 295		foreach( $this->pSet->getDashboardElements() as $elem )296		{297			if( $elem['type'] != DASHBOARD_SEARCH ) {298				if( $elem['type'] == DASHBOARD_LIST ) {299					$this->unsetAllPageSessionKeys( $this->tName."_".$elem["elementName"] );300				} else {301					$this->unsetAllPageSessionKeys( $this->tName."_".$elem["table"] );302				}303			}304		}305	}306 307	/**308	 * Set session variables309	 */310	function setSessionVariables()311	{312		parent::setSessionVariables();313 314		$_SESSION[$this->sessionPrefix.'_advsearch'] = serialize($this->searchClauseObj);315	}316 317	/**318	 * Add extra JS and CSS files319	 */320	public function addDashElementsJSAndCSS()321	{322	}323 324	/**325	 * Check if the dashboard has any 'single record' or 'details' element326	 * @return Boolean327	 */328	protected function hasSingleRecordOrDetailsElement()329	{330		foreach( $this->pSet->getDashboardElements() as $key => $elem )331		{332			if ( !$this->elementsPermissions[$key] )333				continue;334 335			if( $elem["type"] == DASHBOARD_RECORD || $elem["type"] == DASHBOARD_DETAILS )336				return true;337		}338 339		return false;340	}341 342	/**343	 * @param String table344	 * @return Boolean345	 */346	protected function hasGridElement( $table )347	{348		if( $this->getGridElement( $table ) )349			return true;350 351		return false;352	}353 354	protected function getGridElement( $table ) {355		foreach( $this->pSet->getDashboardElements() as $elem ) {356			if( $elem["table"] == $table && $elem["type"] == DASHBOARD_LIST )357				return $elem;358		}359		return null;360	}361 362	/**363	 * Assign 'body' element364	 */365	public function addCommonHtml()366	{367		$this->body['begin'] = GetBaseScriptsForPage(false);368		if( !$this->mobileTemplateMode() )369			$this->body['begin'].= "<div id=\"search_suggest\" class=\"search_suggest\"></div>";370 371		// assign body end372		$this->body['end'] = XTempl::create_method_assignment( 'assignBodyEnd', $this );373 374		$this->xt->assignbyref('body', $this->body);375	}376 377	/**378	 * Common xt assignments379	 */380	protected function doCommonAssignments()381	{382		$this->xt->assign("asearch_link", true);383 384		$this->xt->assign("advsearchlink_attrs", "id=\"advButton".$this->id."\"");385 386		if( $this->mobileTemplateMode() )387			$this->xt->assign('tableinfomobile_block', true);388	}389 390	/**391	 * Add common assign392	 */393	function commonAssign()394	{395		parent::commonAssign();396 397		if( $this->mobileTemplateMode() )398		{399			$this->hideElement("search_dashboard_m");400		}401	}402 403	/**404	 * Process the page405	 */406	public function process()407	{408		if( $this->eventsObject->exists("BeforeProcessDashboard") )409			$this->eventsObject->BeforeProcessDashboard( $this );410 411		// add button events if exist412		$this->addButtonHandlers();413		$this->addDashElementsJSAndCSS();414		$this->addCommonJs();415		$this->commonAssign();416		$this->doCommonAssignments();417		$this->addCommonHtml();418 419		$this->assignSimpleSearch();420 421		if( $this->eventsObject->exists("BeforeShowDashboard") ) {422			$this->eventsObject->BeforeShowDashboard( $this->xt, $this->templatefile, $this );423		}424		$this->display( $this->templatefile );425	}426 427	/**428	 * Fill in element children and parents lists429	 * Children can be updated by this element, parents can update this element430	 * There can be peer elements that are both child and parent to each other.431	 * @param &Array elem432	 */433	function createElementLinks( &$elem )434	{435		$elem["parents"] = array();436		$elem["children"] = array();437 438		foreach( $this->pSet->getDashboardElements() as $key => $e )439		{440			if( $e["elementName"] == $elem["elementName"] )441				continue;442			if( $e["table"] == $elem["masterTable"] && DashboardPage::canUpdateDetails( $e ) )443			{444				$elem["parents"][ $e["elementName"] ] = true;445			}446			if( $elem["table"] == $e["masterTable"] && DashboardPage::canUpdateDetails( $elem ) )447			{448				$elem["children"][ $e["elementName"] ] = true;449			}450			if( $elem["table"] == $e["table"] )451			{452				if( DashboardPage::canUpdatePeers( $e ) )453					$elem["parents"][ $e["elementName"] ] = true;454				if( DashboardPage::canUpdatePeers( $elem ) )455					$elem["children"][ $e["elementName"] ] = true;456			}457		}458	}459 460	/**461	 * @return Array462	 */463	function getMajorElements()464	{465		$majorElements = array();466		$dashboardTables = array();467		$elements = $this->pSet->getDashboardElements();468		//	distribute elements by tables469		foreach( $elements as $key => $e )470		{471			if( !isset( $dashboardTables[ $e["table"] ] ) )472			{473				$dashboardTables[ $e["table"] ] = array();474			}475			$dashboardTables[ $e["table"] ][] = $key;476		}477		//	locate major element in each table478		foreach( $dashboardTables as $t )479		{480			$major = "";481			//	locate main map first482			foreach( $t as $i )483			{484				if( $elements[$i]["type"] == DASHBOARD_MAP && $elements[$i]["updateMoved"] )485				{486					$major = $elements[$i]["elementName"];487					break;488				}489			}490			//	locate grid491			if( $major == "" )492			{493				foreach( $t as $i )494				{495					if( $elements[$i]["type"] == DASHBOARD_LIST || $elements[$i]["type"] == DASHBOARD_CHART || $elements[$i]["type"] == DASHBOARD_REPORT )496					{497						$major = $elements[$i]["elementName"];498						break;499					}500				}501			}502			//	locate any map503			if( $major == "" )504			{505				foreach( $t as $i )506				{507					if( $elements[$i]["type"] == DASHBOARD_MAP )508					{509						$major = $elements[$i]["elementName"];510						break;511					}512				}513			}514			//	locate single record with edit or view enabled515			if( $major == "" )516			{517				foreach( $t as $i )518				{519					if( $elements[$i]["type"] != DASHBOARD_RECORD )520						continue;521					if( in_array( PAGE_EDIT, $elements[$i]["tabsPageTypes"] ) || in_array( PAGE_VIEW, $elements[$i]["tabsPageTypes"] ) )522					{523						$major = $elements[$i]["elementName"];524						break;525					}526				}527			}528			if( $major != "" )529				$majorElements[ $major ] = true;530 531		}532 533		return $majorElements;534	}535 536	/**537	 * @param &Array elem538	 * @return Boolean539	 */540	static function canUpdateDetails( &$elem )541	{542		return DashboardPage::canUpdatePeers( $elem );543	}544 545	/**546	 * @param &Array elem547	 * @return Boolean548	 */549	static function canUpdatePeers( &$elem )550	{551		return $elem["type"] == DASHBOARD_LIST552				|| $elem["type"] == DASHBOARD_CHART553				|| $elem["type"] == DASHBOARD_REPORT554				|| $elem["type"] == DASHBOARD_RECORD555				|| $elem["type"] == DASHBOARD_MAP;556	}557}558?>