CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
listpage_dpinline.php666 linesDownload Raw Back to classes
1<?php2 3class ListPage_DPInline extends ListPage_Embed4{5	/**6	 * DP params7	 * @var string8	 */9	var $dpParams = "";10 11	/**12	 * Array of details preview master key13	 * @var integer14	 */15	var $dpMasterKey = array ();16 17	/**18	 * Short name of master table19	 * @var string20	 */21	var $masterShortTable = "";22 23	/**24	 * Master's form name25	 * @var string26	 */	27	var $masterFormName = "";28 29	/**30	 * Master's id use only for dpInline on list page31	 * (don't confuse with dpInline on add edit pages)32	 * @var string33	 */34	var $masterId = "";35 36	/**37	 * Which type of master page was called detail table38	 *39	 * @var string40	 */41	var $masterPageType = "";42 43	/**44	 * View PDF on view page or not45	 *46	 * @var integer47	 */48	49	/**50	 * Constructor, set initial params51	 * @param array $params52	 */53	function __construct(&$params)54	{55		// copy properties to object56		//RunnerApply($this, $params);57		// call parent constructor58		parent::__construct($params);59 60		$this->showAddInPopup = true;61		$this->showEditInPopup = true;62		$this->showViewInPopup = true;63		64	65		$this->initDPInlineParams();66		if( $this->firstTime ) {67			$this->searchClauseObj->resetSearch();68			unset( $_SESSION[$this->sessionPrefix.'_advsearch'] );69		}70		71		$this->jsSettings['tableSettings'][$this->tName]['masterPageType'] = $this->masterPageType;72		$this->jsSettings['tableSettings'][$this->tName]['masterTable'] = $this->masterTable;73		$this->jsSettings['tableSettings'][$this->tName]['firstTime'] = $this->firstTime;74		$this->jsSettings['tableSettings'][$this->tName]['strKey'] = $this->getStrMasterKey();75		$this->addRawFieldValues = true;76		77		if( $this->masterPageType == PAGE_ADD && parent::spreadsheetGridApplicable() ) {78			$this->pageData['spreadsheetOnList'] = true;79			$this->jsSettings['tableSettings'][ $this->tName ]['autoAddNewRecord'] = $this->pSet->addNewRecordAutomatically();80		}81	}82	83	/**84	 * Assigne Import Links or not85	 */86	function importLinksAttrs() 87	{88	}89	90	/**91	 * The stub preventing the detail page from showing a master info block92	 */93	function displayMasterTableInfo() 94	{95	}96	97	/**98	 * Process master key value99	 * Set master key for create DPInline params100	 */101	function processMasterKeyValue() 102	{103		parent::processMasterKeyValue();104		for($i = 1; $i <= count($this->masterKeysReq); $i++) {105			$this->dpMasterKey[] = $this->masterKeysReq[$i];106		}107	}108	109	/**110	 * Initialization DPInline params 111	 */112	function initDPInlineParams()113	{114		$strkey = "";115		for($i = 0; $i < count($this->dpMasterKey); $i++)116		{117			$strkey.="&masterkey".($i+1)."=".rawurlencode($this->dpMasterKey[$i]);118		}119		120		$this->dpParams = "mode=listdetails&id=".$this->id."&mastertable=".rawurlencode($this->masterTable).$strkey.121							($this->masterId ? "&masterid=".$this->masterId : "").122							(($this->masterPageType==PAGE_EDIT || $this->masterPageType==PAGE_VIEW) ? "&masterpagetype=".$this->masterPageType : "");123 124	}125	/**126	 * Get string of master keys for dpInline on Edit page127	 */128	function getStrMasterKey()129	{130		$strkey = array();131		for($i = 0; $i < count($this->dpMasterKey); $i++)132		{133			$strkey[$i] = $this->dpMasterKey[$i];134		}135		return $strkey;	136	}137 138	/**139	 * @return Boolean140	 */141	public function isReoderByHeaderClickingEnabled()142	{143		return $this->masterPageType != PAGE_ADD;144	}145 146		147	/**148	 * show inline add link149	 * Add inline add attributes150	 */151	function inlineAddLinksAttrs()152	{	153		//inline add link and attr154		if( $this->masterPageType != PAGE_VIEW )155			parent::inlineAddLinksAttrs();156	}157	158	/**159	 * Add common assign for current mode160	 */161	function commonAssign()162	{163		parent::commonAssign();164		165		$this->xt->assign("left_block", false);166		167		//select all link and attr	168		if( $this->masterPageType == PAGE_ADD || $this->masterPageType == PAGE_VIEW  169			|| $this->mode == LIST_DASHDETAILS )170		{171			$this->xt->assign("selectall_link",false);172			$this->xt->assign("checkbox_column",false);173			$this->xt->assign("checkbox_header",false);174			$this->xt->assign("editselected_link",false);175			$this->xt->assign("delete_link",false);176			$this->xt->assign("saveall_link",false);177			$this->xt->assign("withSelectedClass", "rnr-hiddenelem");178			if($this->masterPageType == PAGE_VIEW )179				$this->xt->assign("record_controls_block",false);180		}181		else182		{183			//selectall link attrs184			$this->selectAllLinkAttrs();185			186			//checkbox column187			if(!$this->mobileTemplateMode())188				$this->checkboxColumnAttrs();189			190			//edit selected link and attr191			$this->editSelectedLinkAttrs();	192			193			//save all link, attr, span194			$this->saveAllLinkAttrs();195			196			//delete link and attr197			$this->deleteSelectedLink();198			199			if($this->masterPageType != PAGE_EDIT)200			{201				$searchPermis = $this->permis[$this->tName]['search'];202				$this->xt->assign("record_controls_block", $this->permis[$this->tName]['edit'] && $this->pSet->hasInlineEdit() || $this->permis[$this->tName]['delete'] && $this->pSet->hasDelete());203				$this->xt->assign("details_block", $searchPermis && $this->recordsOnPage );204				$this->xt->assign("details_attrs","id=\"detFound".$this->id."\" name=\"detFound".$this->id."\"");205				$this->xt->assign("pages_block", $searchPermis && $this->recordsOnPage );206			}207		}208 209 210		211		$this->xt->assign("withSelected", $this->permis[$this->tName]['export'] || $this->permis[$this->tName]['edit'] || $this->permis[$this->tName]['delete']);212				213		if( $this->numRowsFromSQL == 0 ) 214			$this->hideElement("recordcontrol");		215		216		if( $this->masterPageType != PAGE_VIEW  )217		{218			//inline edit column219			$this->xt->assign("inlineedit_column", 220				$this->inlineEditAvailable() && $this->permis[ $this->tName ]['edit'] && !$this->spreadsheetGridApplicable() );221			222			//for list icons instead of list links223			$this->assignListIconsColumn();224					225			//cancel all link, attr, span226			$this->cancelAllLinkAttrs();227		}228		229		for($i=0;$i<count($this->allDetailsTablesArr);$i++)230		{231			$permis = ( Security::permissionsAvailable() && 232					($this->permis[$this->allDetailsTablesArr[$i]['dDataSourceTable']]['add'] 233					|| $this->permis[$this->allDetailsTablesArr[$i]['dDataSourceTable']]['search'])) 234				|| (!Security::permissionsAvailable());	235			if($permis)236			{237				$this->xt->assign(GoodFieldName($this->tName)."_dtable_column", $permis);238				break;239			}240		}241	}242	243	244	/**245	 * Hide all excessive bricks and elements in the template.246	 * Prepare the page's template247	 */248	protected function prepareTemplate()249	{250		251		// if we use details inline. We don't need show the header/footer.252		$this->xt->assign("header", false);253		$this->xt->assign("footer", false);254		255		$this->xt->prepare_template($this->templatefile);	256	}257	258	/**259	 * @return String260	 */261	protected function getBSButtonsClass()262	{263		return "btn btn-xs btn-info";264	}265	266	/**267	 * @return String268	 */269	protected function getHeaderControlsBlocks()270	{271		$controlsBlocks = "";272		$buttons = "";273		$bs_button_class = $this->getBSButtonsClass();;274		275		if( $this->inlineAddAvailable() && $this->xt->getVar("inlineadd_link") )276		{277			$inlineaddlink_attrs = $this->xt->getVar("inlineaddlink_attrs");278			279			if( $this->addAvailable() )280				$caption = "Inline Add";281			else	282				$caption = "Add";283				284			if( !$this->isBootstrap() ) 285			{286				$controlsBlocks = '<span class="rnr-dbebrick ">'287					.'<div class="style1 rnr-bl rnr-b-recordcontrols_new">'288						.'<a class="rnr-button" href="#" '.$inlineaddlink_attrs.'>'.$caption.'</a> '289					.'</div>'290				.'</span>';		291			}292			else293			{294				$buttons.= '<a class="'. $bs_button_class.'" href="#" '.$inlineaddlink_attrs.'>'.$caption.'</a> ';		295			}296		}297		298		if( $this->addAvailable() && $this->xt->getVar("add_link") )299		{300			$addlink_attrs = $this->xt->getVar("addlink_attrs");301			302			if( $this->inlineAddAvailable() )303				$caption = "Add new";304			else	305				$caption = "Add";306				307			if( !$this->isBootstrap() ) 308			{309				$controlsBlocks = '<span class="rnr-dbebrick ">'310					.'<div class="style1 rnr-bl rnr-b-recordcontrols_new">'311						.'<a class="rnr-button" href="#" '.$addlink_attrs.'>'.$caption.'</a> '312					.'</div>'313				.'</span>';		314			}315			else316			{317				$buttons.= '<a class="'. $bs_button_class.'" href="#" '.$addlink_attrs.'>'.$caption.'</a> ';		318			}			319		}320 321		if( $this->inlineEditAvailable() && $this->xt->getVar("editselected_link") )322		{323			$editselectedlink_attrs = $this->xt->getVar("editselectedlink_attrs");324			$editselectedlink_span = $this->xt->getVar("editselectedlink_span");325			326			// "bs-invisible-button" class need for init hidden in bootstrap327			if( !$this->isBootstrap()) 328				$buttons.= '<a class="rnr-button" href="#" '.$editselectedlink_attrs.' '.$editselectedlink_span.'>'."Edit".'</a> ';329			else330				$buttons.= '<a class="' . $bs_button_class . ' " disabled href="#" '.$editselectedlink_attrs.' '.$editselectedlink_span.'>'."Edit".'</a> ';331		};	332 333		if( $this->updateSelectedAvailable() && $this->xt->getVar("updateselected_link") && $this->isBootstrap() )334		{335			$updateselectedlink_attrs = $this->xt->getVar("updateselectedlink_attrs");   336			if( $this->isPD() )337				$buttons.= '<a class="' . $bs_button_class . '" disabled '.$updateselectedlink_attrs.'>'."Update selected".'</a> ';338			else	339				$buttons.= '<a class="' . $bs_button_class . '" disabled href="#" '.$updateselectedlink_attrs.'>'."Update selected".'</a> ';		  		340		}341		342		if( $this->xt->getVar("saveall_link") )343		{344			$savealllink_attrs = $this->xt->getVar("savealllink_attrs");	345			$savealllink_span = $this->xt->getVar("savealllink_span");	346	347			if( !$this->isBootstrap()) 348				$buttons.= '<a class="rnr-button" href="#" '.$savealllink_attrs.' '.$savealllink_span.'>'."Save all".'</a> ';					  349			else350				$buttons.= '<a class="' . $bs_button_class . '" href="#" '.$savealllink_attrs.' '.$savealllink_span.'>'."Save all".'</a> ';					  351		}352		353		if( $this->xt->getVar("cancelall_link") )354		{355			$cancelalllink_attrs = $this->xt->getVar("cancelalllink_attrs");	356			$cancelalllink_span = $this->xt->getVar("cancelalllink_span");357 358			if( !$this->isBootstrap()) 359				$buttons.= '<a class="rnr-button" href="#" '.$cancelalllink_attrs.' '.$cancelalllink_span.'>'."Cancel".'</a> ';					  360			else361				$buttons.= '<a class="' . $bs_button_class . '" href="#" '.$cancelalllink_attrs.' '.$cancelalllink_span.'>'."Cancel".'</a> ';					  362		}363		364		if( $this->deleteAvailable() && $this->xt->getVar("deleteselected_link") )365		{366			$deleteselectedlink_attrs = $this->xt->getVar("deleteselectedlink_attrs");	367			$deleteselectedlink_span = $this->xt->getVar("deleteselectedlink_span");            368 369			// "bs-invisible-button" class need for init hidden in bootstrap370			if( !$this->isBootstrap()) 371				$buttons.= '<a class="rnr-button " href="#" '.$deleteselectedlink_attrs.' '.$deleteselectedlink_span.'>'."Delete".'</a> ';		  372			else373				$buttons.= '<a class="' . $bs_button_class . '" disabled href="#" '.$deleteselectedlink_attrs.' '.$deleteselectedlink_span.'>'."Delete".'</a> ';		  374		}		375		if( $buttons ) 376		{377			if( !$this->isBootstrap()) 378			{379				$controlsBlocks.= '<span class="rnr-dbebrick ">'380					.'<div class="style1 rnr-bl rnr-b-recordcontrol ">'381					.$buttons382					.'</div>'383				.'</span>';				384			} else {385				$controlsBlocks.= '<span class="rnr-dbebrick ">'386					.$buttons387				.'</span>';				388			}389		}390		391		return $controlsBlocks.'<div class="rnr-dbefiller"></div>';392	}	393	394	395	/**396	 * Show the page.397	 * It's supposed to be displayed in resonce on an ajax-like request398	 */399	public function showPage()400	{				401		$this->BeforeShowList();402		403		$response = array();404		405		if( !$this->isDispGrid() && 0 == $this->getGridTabsCount() )406		{407			$response["noData"] = true;408			echo printJSON( $response );409			return; 410		}411		412		$this->prepareTemplate();413		414		//$contents = $this->fetchForms( array( "grid", "below-grid" ) );415		$contents = $this->fetchBlocksList( array( "grid_tabs", "grid_block", "below-grid_block" ) );416 417		$this->addControlsJSAndCSS();418		$this->fillSetCntrlMaps();419		420		global $pagesData;421		$response["pagesData"] = $pagesData;422		$response['settings'] = $this->jsSettings;423		$response['controlsMap'] = $this->controlsHTMLMap;424		$response['viewControlsMap'] = $this->viewControlsHTMLMap;425	426		if( $this->masterPageType == PAGE_EDIT && $this->dashTName && $this->dashElementName )427			$response['headerButtonsBlock'] = $this->getHeaderControlsBlocks();428	429		$response['html'] = $contents;430		$response['success'] = true;431		$response['id'] = $this->id;432		$response['idStartFrom'] = $this->flyId;433		434		$response['delRecs'] = $this->recordsDeleted;435		if( $this->deleteMessage != '' )436			$response['delMess'] = true;437		438		$response["additionalJS"] = $this->grabAllJsFiles();439		$response["additionalCSS"] = $this->grabAllCSSFiles();440		441		echo printJSON($response);442	}443 444	445	446	/**447	 * Show a detail preview page448     * @param Array params - asp compatibility issue449	 */450	public function showPageDp($params = "")451	{	452		return $this->showGridOnly();453	}	454 455	public function prepareDisplayDetails() {456		$this->prepareDisplayDetailsPD();	457	}458 459	public function prepareDisplayDetailsPD() {460		$this->prepareTemplate();461 462		if( $this->pdfJsonMode() ) {463			$this->xt->assign("embedded_grid", true );464			$this->xt->assign("embedded_page_title", true );465			$this->xt->load_templateJSON( $this->templatefile);466			$this->renderedBody = $this->xt->fetch_loadedJSON("body");467			return;468		}469		470		$forms = array( "grid_block" );471		if( $this->masterPageType != PAGE_ADD ) {472			$forms = array( "grid_tabs", "grid_block", "below-grid_block" );	473		}474		475		476		$this->renderedButtons = $this->fetchBlocksList( array("firstAboveGridCell") );		477		$this->renderedButtons = str_replace("btn-primary", "btn-xs btn-info", $this->renderedButtons);478		$this->renderedButtons = str_replace("btn-default", "btn-xs btn-info", $this->renderedButtons);479 480		$bodyContents = $this->fetchBlocksList($forms);		481		$this->renderedBody = '<div id="detailPreview'.$this->id.'">'.$bodyContents.'</div>';	482	}483 484 485	public function showGridOnly() 486	{			487		echo $this->renderedBody;488	}489	490	public function showButtonsDp($params = "") {491		echo $this->renderedButtons;492	}493 494 495 496	public function isPageSortable()497	{498		return $this->masterPageType != PAGE_ADD;499	}	500	501	/**502	 * A stub503	 */504	function rulePRG()505	{506	}507	508	function getMasterTableSQLClause() 509	{510		if($this->masterPageType==PAGE_ADD)511			return "1=0";512		return parent::getMasterTableSQLClause();513	}514	515	/**516	 * only for bootstrap layers in add/edit page517	 */ 518	function assignButtonsOnMasterEdit( $masterXt )519	{520		if( $this->inlineAddAvailable() )521		{522			$masterXt->assign( "details_inlineadd_" . $this->shortTableName . "_link", true );523			$masterXt->assign( "details_inlineadd_" . $this->shortTableName . "_attrs", $this->getInlineAddLinksAttrs() );			524		}525 526		if( $this->addAvailable() )527		{528			$masterXt->assign( "details_add_" . $this->shortTableName . "_link", true );529			$masterXt->assign( "details_add_" . $this->shortTableName . "_attrs", $this->getAddLinksAttrs() );		530		}531		532		if( $this->deleteAvailable() )533		{534			$masterXt->assign( "details_delete_" . $this->shortTableName . "_link", true );535			$masterXt->assign( "details_delete_" . $this->shortTableName . "_attrs", $this->getDeleteLinksAttrs() );536		}537		538		if( $this->inlineEditAvailable() )539		{540			$masterXt->assign( "details_edit_" . $this->shortTableName . "_link", true );541			$masterXt->assign( "details_edit_" . $this->shortTableName . "_attrs", $this->getEditLinksAttrs() );542		}543 544		if( $this->updateSelectedAvailable() )545		{546			$masterXt->assign( "details_updateselected_" . $this->shortTableName . "_link", true );547			$masterXt->assign( "details_updateselected_" . $this->shortTableName . "_attrs", $this->getUpdateSelectedAttrs() );		548		}549		550		if ( $this->inlineAddAvailable() || $this->inlineEditAvailable() )551		{552			$masterXt->assign("cancelall_" . $this->shortTableName . "_link", true);553			$masterXt->assign("cancelalllink_" . $this->shortTableName . "_span",$this->buttonShowHideStyle('cancelall'));554			$masterXt->assign("cancelalllink_" . $this->shortTableName . "_attrs","name=\"revertall_edited".$this->id."\" id=\"revertall_edited".$this->id."\"");555		}556 557		// Do not show save all button on add, view, dashdetail list pages 558		if ( $this->masterPageType == PAGE_EDIT && ( $this->inlineAddAvailable() || $this->inlineEditAvailable() ) )559		{560			$masterXt->assign("saveall_" . $this->shortTableName . "_link", true);561			$masterXt->assign("savealllink_" . $this->shortTableName . "_span",$this->buttonShowHideStyle('saveall'));	562			$masterXt->assign("savealllink_" . $this->shortTableName . "_attrs","name=\"saveall_edited".$this->id."\" id=\"saveall_edited".$this->id."\"");563		}564		565	}566	567	protected function fillTableSettings( $table = "", $pSet = null )568	{569		parent::fillTableSettings( $table, $pSet );570		571		if( $this->addAvailable() )572			$this->jsSettings["tableSettings"][ $this->tName ]["showAddInPopup"] = true;573 574		if( $this->editAvailable() || $this->updateSelectedAvailable() )575			$this->jsSettings["tableSettings"][ $this->tName ]["showEditInPopup"] = true;576			577		if( $this->viewAvailable() )578			$this->jsSettings["tableSettings"][ $this->tName ]["showViewInPopup"] = true;			579	}		580	581	function deleteAvailable() {582		return $this->masterPageType != PAGE_VIEW && $this->masterPageType != PAGE_ADD && parent::deleteAvailable();583	}584	585	function importAvailable() {586		return false;587	}588	589	function editAvailable() {590		return $this->masterPageType != PAGE_VIEW && $this->masterPageType != PAGE_ADD && parent::editAvailable();591	}592	593	function addAvailable() {594		595		//	add in popup is not possible on master Add page. Only Inline Add is available there596		return $this->masterPageType != PAGE_VIEW  && $this->masterPageType != PAGE_ADD && parent::addAvailable();597	} 598	599	function copyAvailable() {600		return $this->masterPageType != PAGE_VIEW && $this->masterPageType != PAGE_ADD && parent::copyAvailable();601	}602	603	function inlineEditAvailable() {604		return $this->masterPageType != PAGE_VIEW && $this->masterPageType != PAGE_ADD && parent::inlineEditAvailable();605	}606 607	608	function inlineAddAvailable() {609		610		//	don't show inlineAdd on View page611		//	Always change Add to Inline Add on master Add page612		return $this->masterPageType != PAGE_VIEW && parent::inlineAddAvailable() 613			|| $this->masterPageType == PAGE_ADD && parent::addAvailable();614	}615	616	protected function displayViewLink() {617		return $this->masterPageType != PAGE_ADD && $this->viewAvailable();618	}619	620	621	function updateSelectedAvailable()622	{623		return $this->masterPageType != PAGE_VIEW && $this->masterPageType != PAGE_ADD && parent::updateSelectedAvailable();624	}625 626	/**627	 * Checks if need to display grid628	 */629	function isDispGrid() 630	{631		//	can add data to grid632		if ( $this->inlineAddAvailable() || $this->addAvailable() )633			return true;634		635		return parent::isDispGrid();636	}637 638	function shouldDisplayDetailsPage()639	{640		//	always display the page if there are visible grid tabs641		return $this->isDispGrid() || 0 != $this->getGridTabsCount();642	}643 644	function pdfJsonMode() 645	{646		return $this->mode == LIST_PDFJSON;647	}648	649	protected function spreadsheetGridApplicable() {650		return $this->masterPageType != PAGE_ADD && $this->masterPageType != PAGE_VIEW651			&& parent::spreadsheetGridApplicable();652	}653 654	protected function assignSessionPrefix() 655	{656		$masterKeys = md5( implode( '-', $this->masterKeysReq ) );657		$this->sessionPrefix = $this->tName."_preview" . $masterKeys;	658	}659	660	/**661	 * skip search panel building for details662	 */663	function buildSearchPanel() {664	}665}666?>