CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
button.php208 linesDownload Raw Back to classes
1<?php2class Button3{4	var $keys = array();5	6	var $currentKeys = array();7	8	var $selectedKeys = array();9	10	var $isManyKeys = false;11	12	var $location = "";13	14	var $nextInd;15 16	var $table;17 18	var $page;19 20	var $tempFileNames = array();21	22	public $masterTable;23	public $masterKeys;24	25	function __construct(&$params)26	{27		RunnerApply($this, $params);28		29		$this->nextInd = 0;30		$this->modifyKeys();31		$this->separateKeys();32	}33	/**34	 * Separate modified post keys to current and selected  35	 */36	function separateKeys()37	{38		if($this->location == 'grid')39		{40			if($this->isManyKeys) 41			{42				$this->currentKeys = $this->keys[0];43				for($i=1; $i<count($this->keys); $i++)44					$this->selectedKeys[$i-1] = $this->keys[$i]; 45			}46			else47				$this->currentKeys = $this->keys;48		}49		if($this->location == PAGE_LIST) {50			$this->selectedKeys = $this->keys;51			$this->currentKeys = $this->keys;52		}53		54		if($this->location == PAGE_EDIT || $this->location == PAGE_VIEW)55			$this->currentKeys = $this->keys;56	}57	/**58	 * Modify post keys array to associative 59	 */60	function modifyKeys()61	{62		$pSet = new ProjectSettings( $this->table, "", $this->page );63		64		$keys = array();65		66		// if array of keys exists67		if( $this->keys )68		{69			$tKeysNamesArr = $pSet->getTableKeys();70			if($this->isManyKeys)71			{72				foreach ($this->keys as $ind => $value)73				{74					$keys[$ind] = array();75					$recKeyArr = explode('&', $value);76					for($j=0;$j<count($tKeysNamesArr);$j++)77					{78						if (isset($recKeyArr[$j])){79							$keys[$ind][$tKeysNamesArr[$j]] = urldecode($recKeyArr[$j]);80						}81					}82				}83			}84			else85			{86				$keysReady = true;87				foreach( $tKeysNamesArr as $kf ) {88					if( !isset( $this->keys[ $kf ] ) ) {89						$keysReady = false;90						break;91					}92				}93				94				if( $keysReady )95					return;				96				97				for($j=0;$j<count($tKeysNamesArr);$j++)98				{99					$keys[$tKeysNamesArr[$j]] = urldecode(@$this->keys[$j]);100				}101			}102		}103		$this->keys = $keys;104	}105	/**106	 * Get keys107	 * @return {array} 108	 */109	function getKeys() {110		return $this->keys;111	}112	113	/**114	 * Get current record data115	 * @return {mixed} array of next record data or false116	 */117	function getCurrentRecord() {118		return $this->getRecordData();119	}120	121	/**122	 * Get next selected record123	 * @return {mixed} array of next record data or false124	 */	125	function getNextSelectedRecord() {126		if( $this->nextInd < count( $this->selectedKeys ) ) {127			$data =  $this->getRecordData( $this->selectedKeys[ $this->nextInd ] );128			$this->nextInd += 1;129			return $data;130		}131		132		return false;133	}	134	135	/**136	 * Read values from the database by keys137	 * @return {mixed} array of current record data or false138	 */	139	public function getRecordData( $keys = null ) {140		global $cipherer;141		142		if( !$keys )143			$keys = $this->currentKeys;144		145		$pSet = new ProjectSettings( $this->table, "", $this->page );146		147		$dc = new DsCommand();148		$dc->filter = Security::SelectCondition( "S", $pSet );149		$dc->keys = $keys;150		151		$dataSource = getDataSource( $this->table, $pSet );152		$fetchedArray = $dataSource->getSingle( $dc )->fetchAssoc();153		$data = $cipherer->DecryptFetchedArray( $fetchedArray );154 155		return $data;156	}157	158	159	function getMasterData( $masterTable )160	{161		if ( isset($_SESSION[ $masterTable . "_masterRecordData" ]) )162		{163			return $_SESSION[ $masterTable . "_masterRecordData" ];164		}165		166		return false;167	}168 169	function saveTempFile( $contents ) {170		$filename = tempnam("", "");171		runner_save_file($filename, $contents);172		$this->tempFileNames[] = $filename;173		return $filename;174	}175 176	function deleteTempFiles() {177		foreach( $this->tempFileNames as $f ) {178			@unlink( $f );179		}180	}181	182	public function getMasterRecord() {183		if( !$this->masterTable )184			return null;185		186		$pSet = new ProjectSettings( $this->table, "", $this->page );187		$mpSet = new ProjectSettings( $this->masterTable, PAGE_LIST );188		$masterDs = getDataSource( $this->masterTable, $mpSet );189		190		$filters = array();191		foreach( $pSet->getMasterTablesArr() as $i => $masterTableInfo ) {192			if( $this->masterTable != $masterTableInfo['mDataSourceTable'] )193				continue;194			195			foreach( $masterTableInfo['masterKeys'] as $j => $mKeyField ) {196				$filters[] = DataCondition::FieldEquals( $mKeyField, $this->masterKeys[ $j + 1 ] );197			}				198		}199		$filters[] = Security::SelectCondition( "S", $mpSet );200		201		$dc = new DsCommand;202		$dc->filter = DataCondition::_And( $filters );203		$dc->reccount = 1;204		205		return $masterDs->getList( $dc )->fetchAssoc();206	}		207}208?>