CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
listpage_lookup.php526 linesDownload Raw Back to classes
1<?php2 3require_once( getabspath('classes/controls/Control.php') );4require_once( getabspath('classes/controls/LookupField.php') );5 6 7class ListPage_Lookup extends ListPage_Embed8{9	/**10      * Field of link11      *12      * @var string13      */14	var $linkField = "";15 16 17	/**18      * Select field of lookup19      *20      * @var string21      */22	var $lookupSelectField = "";23 24	/**25      * Field customed26      *27      * @var string28      */29	var $customField = "";30 31	/**32      * Field displayed33      *34      * @var string35      */36	var $dispField = "";37 38	var $dispFieldAlias = "";39 40	var $lookupValuesArr = array();41 42	/**43     * @type Array44     */45	public $parentCtrlsData;46 47	/**48	 * The name of a table containing a lookup-field49	 * @type String50	 */51	public $mainTable;52 53	/**54	 * The type of a page containing a lookup-field55	 * @type String56	 */57	public $mainPageType;58 59	/**60	 * The lookup-field's61	 * @type String62	 */63	public $mainField = "";64 65	/**66	 * A  settings object for the table67	 * containing the lookup field68	 * @type ProjectSettings69	 */70	protected $mainPSet;71 72	public $mainRecordData;73	public $mainRecordMasterTable;74 75	public $mainContext;76 77	public $showSearchPanel;78	79	80	/**81      * Constructor, set initial params82      *83      * @param array $params84      */85	function __construct(&$params)86	{87		// call parent constructor. always at the first line!!!88		parent::__construct($params);89		// init params90		$this->initLookupParams();91 92		//always show add in popup93		$this->showAddInPopup = true;94		95		$this->permis[ $this->tName ]["search"] = 1;96		$this->jsSettings['tableSettings'][$this->tName]['permissions'] = $this->permis[$this->tName];97		98		$this->showSearchPanel = false;99		100		/* // turn off ajax suggest101		$this->jsSettings["tableSettings"][ $this->tName ]["ajaxSuggest"] = false;102		$this->isUseAjaxSuggest = false;*/103	}104 105	/**106	 * Set the correct session prefix107	 */108	protected function assignSessionPrefix()109	{110		$this->sessionPrefix = $this->tName."_lookup_".$this->mainTable.'_'.$this->mainField;111	}112 113	/**114	 *115	 */116	function initLookupParams()117	{118		if( $this->mainPageType != PAGE_ADD && $this->mainPageType != PAGE_EDIT && $this->mainPageType != PAGE_REGISTER)119			$this->mainPageType = PAGE_SEARCH;120 121		$this->mainPSet = new ProjectSettings($this->mainTable, $this->mainPageType);122 123		$this->linkField = $this->mainPSet->getLinkField( $this->mainField );124		$this->dispField = $this->mainPSet->getDisplayField( $this->mainField );125 126		if( $this->mainPSet->getCustomDisplay( $this->mainField ) )127		{128			$this->dispFieldAlias = generateAlias(); /*GetGlobalData("dispFieldAlias", "rrdf1")*/;129 130			$this->customField = $this->linkField;131		}132 133		$this->outputFieldValue($this->linkField, 2);134		$this->outputFieldValue($this->dispField, 2);135 136		if( $this->dispFieldAlias && $this->pSet->appearOnListPage( $this->dispField ) )137			$this->lookupSelectField = $this->dispField;138		elseif( $this->pSet->appearOnListPage( $this->dispField ) )139			$this->lookupSelectField = $this->dispField;140		else141			$this->lookupSelectField = $this->listFields[0]['fName'];142 143		$this->mainContext = $this->getMainContext();144	}145 146	/**147	 * The stub - ListPage Lookup no supported MasterTable148	 */149	function displayMasterTableInfo()150	{151	}152 153	/**154	 * The stub - ListPage Lookup no supported master-details mode155	 */156	function processMasterKeyValue() {157	}158 159	/**160	 * @return Array161	 */162	protected function getMainContext()163	{164		$contextParams = array();165 166		$contextParams["data"] = $this->mainRecordData;167 168		if ( $this->mainRecordMasterTable && isset($_SESSION[ $this->mainRecordMasterTable . "_masterRecordData" ]) )169			$contextParams["masterData"] = $_SESSION[ $this->mainRecordMasterTable . "_masterRecordData" ];170 171		return $contextParams;172	}173 174	/**175	 * clear lookup session data, while loading at first time176	 */177	function clearSessionKeys() {178		parent::clearSessionKeys();179		if( $this->firstTime ) {180			$this->unsetAllPageSessionKeys();181		}182	}183 184	function addCommonJs() {185		$this->controlsMap['dispFieldAlias'] = $this->dispFieldAlias;186 187		$this->addControlsJSAndCSS();188		$this->addButtonHandlers();189	190	}191 192	/**193	 *194	 */195	function addSpanVal($fName, &$data)196	{197		if ($this->dispFieldAlias && @$this->arrFieldSpanVal[$fName] == 2)198			return "val=\"".runner_htmlspecialchars($data[$this->dispFieldAlias])."\" ";199		else200			return parent::addSpanVal($fName, $data);201	}202 203	public function getOrderByClause()204	{205		$userStartingSort = false;206		if ( isset($_SESSION[ $this->sessionPrefix . "_orderby" ]) )207		{208			$userStartingSort = true;209		}210 211		$orderByField = $this->mainPSet->getLookupOrderBy( $this->mainField );212		if( !$userStartingSort && strlen($orderByField) )213		{214			$strOrder = " ORDER BY ".$this->getFieldSQL( $orderByField );215			if( $this->mainPSet->isLookupDesc( $this->mainField ) )216				$strOrder .= ' DESC';217		}218		else219			$strOrder = parent::getOrderByClause();220 221		return $strOrder;222	}223 224	protected function getCategoryFilter()225	{226		if( !$this->mainPSet->useCategory( $this->mainField ) )227			return null;228 229		// add 1=0 if parent control contain empty value and no search used230		if( $this->mainPageType != PAGE_SEARCH && !$this->parentCtrlsData )231		{232			return DataCondition::_False();233		}234 235		$conditions = array();236		foreach( $this->mainPSet->getParentFieldsData( $this->mainField ) as $cData )237		{238			if( !isset( $this->parentCtrlsData[ $cData["main"] ] ) )239				continue;240 241			$conditions[] = LookupField::categoryCondition( $this->mainPSet, $cData["main"], $cData["lookup"], $this->parentCtrlsData[ $cData["main"] ] );242		}243		return DataCondition::_And( $conditions );244	}245 246	public function getSubsetDataCommand( $ignoreFilterField = "" ) {247 248		$dc = parent::getSubsetDataCommand();249		if ($this->dispFieldAlias)250			$dc->extraColumns[] = new DsFieldData( $this->dispField, $this->dispFieldAlias, "" );251		$filters = array();252		$filters[] = DataCondition::SQLCondition( $this->getLookupWizardWhere() );253		$filters[] = $this->getCategoryFilter();254		$filters[] = $dc->filter;255		$dc->filter = DataCondition::_And( $filters );256 257		return $dc;258	}259 260	/**261	 * @return String262	 */263	protected function getLookupWizardWhere()264	{265		RunnerContext::push( new RunnerContextItem( CONTEXT_ROW, $this->mainContext ) );266		$where = prepareLookupWhere( $this->mainField, $this->mainPSet );267		RunnerContext::pop();268 269		return $where;270	}271 272	/**273	 * Build a lookup's search panel274	 */275	function buildSearchPanel() {276		if( $this->showSearchPanel ) {277			parent::buildSearchPanel();278		}279	}280	281	/**282	 * build simple search control283	 */284	protected function assignSearchControl() {285		$searchforAttrs = 'placeholder="'. "search".'"';286		287		$params = $this->searchClauseObj->getSearchGlobalParams();288		if( $this->searchClauseObj->searchStarted() ) {289			$valSrchFor = $params["simpleSrch"];290			$searchforAttrs.= " value=\"".runner_htmlspecialchars( $valSrchFor )."\"";291		}292 293		$searchforAttrs.= " size=\"15\" name=\"ctlSearchFor".$this->id."\" id=\"ctlSearchFor".$this->id."\"";294		$this->xt->assign( "searchfor_attrs", $searchforAttrs );295	}296 297	/**298	 *299	 */300	function addLookupVals()301	{302		$this->controlsMap['lookupVals'] = $this->lookupValuesArr;303	}304 305	function fillGridData()306	{307		parent::fillGridData();308 309		$this->addLookupVals();310 311	}312 313 314	function fillCheckAttr(&$record,$data,$keyblock)315	{316		$checkbox_attrs="name=\"selection[]\" value=\"".runner_htmlspecialchars(@$data[$this->linkField])."\" id=\"check".$this->recId."\"";317		$record["checkbox"]=array("begin"=>"<input type='checkbox' ".$checkbox_attrs.">", "data"=>array());318	}319 320	/**321	 * Name of function came from listpage class, but on listpage_lookup it used for collection link and display field data322	 *323	 * @param String type324	 * @param Array &record325	 * @param Array data (optional)326	 */327	function addSpansForGridCells($type, &$record, $data = null)328	{329		if($type == 'add')330		{331			parent::addSpansForGridCells($type, $record, $data);332			return;333		}334 335		if(!is_null($data))336		{337			if ($this->dispFieldAlias)338				$dispVal = $data[$this->dispFieldAlias];339			else340				$dispVal = $data[$this->dispField];341 342			if ( in_array( $this->mainPSet->getViewFormat( $this->mainField ), array(FORMAT_DATE_SHORT, FORMAT_DATE_LONG, FORMAT_DATE_TIME) ) )343			{344				$viewContainer = new ViewControlsContainer( $this->mainPSet, PAGE_LIST, null );345				$ctrlData = array();346				$ctrlData[ $this->mainField ] = $data[ $this->linkField ];347 348				$dispVal = $viewContainer->getControl( $this->mainField )->getTextValue( $ctrlData );349			}350 351			$this->lookupValuesArr[] = array('linkVal' => $data[$this->linkField], 'dispVal' => $dispVal);352		}353	}354 355	/**356	 *357	 */358	function proccessRecordValue( &$data, &$keylink, $listFieldInfo, $isEditable = true ) {359		$value = parent::proccessRecordValue( $data, $keylink, $listFieldInfo, $isEditable );360 361		if ( $this->lookupSelectField == $listFieldInfo['fName'] )362			$value = '<a href="#" data-ind="'.count( $this->lookupValuesArr ).'" type="lookupSelect'.$this->id.'">'.$value."</a>";363 364		return $value;365	}366 367	/**368	 *369	 */370	function showPage() {371		$this->BeforeShowList();372 373		$this->hideAllFormItems( 'supertop' );374		$this->showItemType( 'simple_search' );375		$this->showItemType( 'simple_search_field' );376		$this->showItemType( 'simple_search_option' );377 378		$this->hideItemType('columns_control');379		380		if( $this->showSearchPanel ) {381			$this->showItemType( 'search_panel' );382			383			$this->hideItemType( 'logo' );384			$this->hideItemType( 'menu' );385			$this->hideItemType( 'breadcrumb' );386			$this->hideItemType( 'filter_panel' );387		}388 389		$this->xt->prepare_template($this->templatefile);390		$this->showPageAjax();391	}392 393 394	/**395	 * Display blocks after loaded template of page396	 */397	function showPageAjax()398	{399		$lookupSearchControls = $this->xt->fetch_loaded('searchform_text').$this->xt->fetch_loaded('searchform_search')400			.$this->xt->fetch_loaded('searchform_showall');401		$this->xt->assign("lookupSearchControls", $lookupSearchControls);402 403		$this->addControlsJSAndCSS();404		$this->fillSetCntrlMaps();405 406		$returnJSON = array();407		global $pagesData;408		$returnJSON["pagesData"] = $pagesData;409		$returnJSON['controlsMap'] = $this->controlsHTMLMap;410		$returnJSON['viewControlsMap'] = $this->viewControlsHTMLMap;411		$returnJSON['settings'] = $this->jsSettings;412		$this->xt->assign("header",false);413		$this->xt->assign("footer",false);414		// popup header shows PD items only415		416		$returnJSON["headerCont"] = '<h3 data-itemtype="lookupheader" data-itemid="lookupheader">' . $this->getPageTitle( $this->pageType, GoodFieldName($this->tName) ) . "</h3>";417		418		$superTopHtml = $this->xt->fetch_loaded("supertop_block");419		$footerHtml = $this->xt->fetch_loaded("below-grid_block");420		if( $this->showSearchPanel ) {421			$this->xt->assign("supertop_block", false);422			$this->xt->assign("below-grid_block", false);423			424			$bodyHtml = $this->xt->fetch_loaded("body");425		} else {426			$bodyHtml = $this->fetchBlocksList( array( "above-grid_block", "grid_tabs", "grid_block" ) );427		}428		429		430		$returnJSON["html"] = $superTopHtml431			. '<div class="r-popup-block">'432				. '<div class="r-popup-data">'433					. $bodyHtml434				. "</div>"435			."</div>";436 437		$returnJSON["footerCont"] = $footerHtml;438		439		$returnJSON['idStartFrom'] = $this->flyId;440		$returnJSON['success'] = true;441 442		$returnJSON["additionalJS"] = $this->grabAllJsFiles();443		$returnJSON["CSSFiles"] = $this->grabAllCSSFiles();444 445		echo printJSON($returnJSON);446	}447 448 449	function displayTabsInPage()450	{451		return true;452	}453 454	/**455	 * A stub456	 */457	function buildTotals(&$totals)458	{459	}460 461	/**462	 * Returns where clause for active master-detail relationship463	 * @return string464	 */465	function getMasterTableSQLClause()466	{467		return "";468	}469 470	function deleteAvailable() {471		return false;472	}473	function importAvailable() {474		return false;475	}476	function editAvailable() {477		return false;478	}479	function addAvailable() {480		return parent::addAvailable() && $this->mainPSet->isAllowToAdd( $this->mainField );481	}482	function copyAvailable() {483		return false;484	}485	function inlineAddAvailable() {486		return parent::inlineAddAvailable() && $this->mainPSet->isAllowToAdd( $this->mainField );487	}488	function inlineEditAvailable() {489		return false;490	}491	function viewAvailable() {492		return false;493	}494	function exportAvailable() {495		return false;496	}497	function printAvailable() {498		return false;499	}500	function advSearchAvailable() {501		return false;502	}503 504	function detailsInGridAvailable()505	{506		return false;507	}508 509	function updateSelectedAvailable()510	{511		return false;512	}513 514	function getSecurityCondition() {515		$loginTable = Security::loginTable();516 517		if( $this->mainPageType == PAGE_REGISTER && $this->mainTable == $loginTable ) {518			$registerPset = new ProjectSettings( $loginTable, PAGE_REGISTER, "", GLOBAL_PAGES);519			if ( $registerPset->appearOnPage( $this->mainField ) )520				return null;521		}522 523		return parent::getSecurityCondition();524	}525}526?>