class_DataFromDBHelper.inc.php 19.5 KB
<?php
/**
 * @file	DataFromDBHelper.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
class DataFromDBHelper extends RegExpHelper {

	protected $countRowsArray;
	protected $allDBTables;
	protected $varProfileID =null;

	/**
	 *	@since 20.03.2010
	 * 
	 * @param <type> $param_RequestProfileID  wird hier einfach mal auch als Account ID angenommen, das es bei den ersten 5 Testaccounts auch wirklich der FAll ist ... ist natürlich nur übergangsweise ;) 
	 */
	private static $Cache_AccountArray = array();
	private function Help_getAccount($param_RequestProfileID) {
		if(!array_key_exists($param_RequestProfileID, self::$Cache_AccountArray)) {
			self::$Cache_AccountArray[$param_RequestProfileID] = BasisElement::createNewInstance($this->DB, 'Account', 0);
			self::$Cache_AccountArray[$param_RequestProfileID]->setObjVar('ID', $param_RequestProfileID);
			self::$Cache_AccountArray[$param_RequestProfileID]->loadObject(self::$Cache_AccountArray[$param_RequestProfileID], $this->DB);
			self::$Cache_AccountArray[$param_RequestProfileID]->setObjVar('LoginState', true);
			self::$Cache_AccountArray[$param_RequestProfileID]->loadMainProfile($this->DB);
			Account::setActiveProfile(self::$Cache_AccountArray[$param_RequestProfileID], $this->DB, $param_RequestProfileID);
		}


		return self::$Cache_AccountArray[$param_RequestProfileID];
	}

	public function getDataFromDB($param_ary) {
		$testArray=$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']];
		if(is_array($testArray['Formular_Tags'])) {
			$param_ConditionArray = array();
			if(array_search('Subject',$testArray['Formular_Tags']) !== false ) {
				$param_ConditionArray['column'] = 'Subject';
				$param_ConditionArray['from'] = $testArray['Check']['Subject'];
			}else if(array_search('Url',$testArray['Formular_Tags']) !== false ) {
				$param_ConditionArray['column'] = 'Url';
				$param_ConditionArray['from'] = $testArray['Check']['url'];
			}
			$param_ConditionArray['operator'] = '=';
			$param_ConditionArray['limit'] = '1';
			if($testArray['cur']['BC'] !='FriendList') {
				if($testArray['cur']['BC'] == 'PostOffice' ) {
					if($this->varProfileID != null) {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$testArray['TestArray']['PO'] = $this->DB->getMultimediaTextData($this->varProfileID,$testArray['cur']['BC']['MT'], null, $param_ConditionArray);
						$testArray['TestArray']['PO'] = $this->DB->getMultimediaTextData($this->Help_getAccount($this->varProfileID),$testArray['cur']['BC']['MT'], null, $param_ConditionArray);
					}else {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$testArray['TestArray']['PO'] = $this->DB->getMultimediaTextData($testArray['UserID'],$testArray['cur']['MT'], null, $param_ConditionArray);
						$testArray['TestArray']['PO'] = $this->DB->getMultimediaTextData($this->Help_getAccount($testArray['UserID']),$testArray['cur']['MT'], null, $param_ConditionArray);
					}
					$param_testInput['MTextID'] = $param_testInput['TestArray']['PO'][0]['ID'];
					if($this->varProfileID != null) {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$testarrayfromclipboard =$this->DB->getFromClipboard($this->varProfileID, $testArray['Listener_NickName'], 'InBox', $param_KindOfObj=null,null, $param_ConditionArray);
						$testarrayfromclipboard =$this->DB->getFromClipboard($this->Help_getAccount($this->varProfileID), $testArray['Listener_NickName'], 'InBox', $param_KindOfObj=null,null, $param_ConditionArray);
					}else {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$testarrayfromclipboard =$this->DB->getFromClipboard($testArray['UserID'],  $testArray['Listener_NickName'], 'InBox', $param_KindOfObj=null,null, $param_ConditionArray);
						$testarrayfromclipboard =$this->DB->getFromClipboard($this->Help_getAccount($testArray['UserID']),  $testArray['Listener_NickName'], 'InBox', $param_KindOfObj=null,null, $param_ConditionArray);
					}
					$j= count($testarrayfromclipboard);
					for($i = '0'; $i < $j; $i++ ) {
						$param_testInput['TestArray']['C']['0'] = $testarrayfromclipboard[$i];
					}
				}
				if($testArray['cur']['MT'] == 'Profile'  ) {
					if($this->varProfileID != null) {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$testArray['TestArray']['C'] = $this->DB->getMultimediaTextData($this->varProfileID,$testArray['cur']['BC'], null, $param_ConditionArray);
						$testArray['TestArray']['C'] = $this->DB->getMultimediaTextData($this->Help_getAccount($this->varProfileID),$testArray['cur']['BC'], null, $param_ConditionArray);
					}else {
						if($this->ary_testPar['0']['getfromDB'] == 'TRUE') {
							echo '<br>--------------'.$testArray['UserID'].'-'.$testArray['cur']['MT'].'-'.$testArray['cur']['MCase'].'-'.$testArray['cur']['BC'].'-----------------------<br>';
							D::li('AUSGABE: 6',1,1);
							D::ulli('AUSGABE: 6 getMultimediaTextData:'.'$param_RequestProfileID '.$testArray['UserID'] .' $param_classname: '.$testArray['cur']['MT'] .' $param_MTextClipboard: '. null .' $param_ConditionArray: '. $param_ConditionArray ,1,1);
							D::show($param_ConditionArray,'$param_ConditionArray; go to:. <a name="A'.STTree::$var_ctOut.'">A'.STTree::$var_ctOut.'</a>'.'<a href="#A'.(STTree::$var_ctOut-1).'"> back</a>'.' | <a href="#A'.(STTree::$var_ctOut+1).'"> next</a> | <a href="#anfang">Anfang</a> | <a href="#allTests">allTests</a> | <a href="#Succesfull">Succesfull</a> | <a href="#Failedassert">Failedassert</a> | <a href="#FailedID"></a> ',1,1);
							STTree::$var_ctOut++;
							echo '<br> ENDE ------------------------------------------------------------ENDE<br>';
						}
						if($testArray['PartOfID_ST']['0']) {
							$num=count($testArray['PartOfID_ST']);
							for($i=0;$i<$num;$i++) {
								/**
								 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
								 */
//								$param_testInput['TestArray']['C_ST'][$i] = $this->DB->getMultimediaTextData($testArray['UserID'],$testArray['cur']['MT'], null, $param_ConditionArray);
								$param_testInput['TestArray']['C_ST'][$i] = $this->DB->getMultimediaTextData($this->Help_getAccount($testArray['UserID']),$testArray['cur']['MT'], null, $param_ConditionArray);
							}
						}
					}
				}else if ($testArray['cur']['BC'] != 'PostOffice') {
					if($this->varProfileID != null) {
						/**
						 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
						 */
//						$param_testInput['TestArray']['C'] = $this->DB->getFromClipboard($this->varProfileID, $testArray['PartOfID'],$testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
						$param_testInput['TestArray']['C'] = $this->DB->getFromClipboard($this->Help_getAccount($this->varProfileID), $testArray['PartOfID'],$testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
						if($testArray['PartOfID_2']) {
							/**
							 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
							 */
//							$param_testInput['TestArray']['C_2'] = $this->DB->getFromClipboard($this->varProfileID, $testArray['PartOfID_2'],$testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
							$param_testInput['TestArray']['C_2'] = $this->DB->getFromClipboard($this->Help_getAccount($this->varProfileID), $testArray['PartOfID_2'],$testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
						}
					}else {
						if(isset($this->ary_testPar['0']['getfromDB'])&&$this->ary_testPar['0']['getfromDB'] == 'TRUE') {
							echo '<br>--------------'.$testArray['UserID'].'-'.$testArray['cur']['MT'].'-'.$testArray['cur']['MCase'].'-'.$testArray['cur']['BC'].'-----------------------<br>';
							D::li('AUSGABE: 8',1,1);
							D::ulli('AUSGABE: 8 getFromClipboard:'.' $param_RequestProfileID: '.$testArray['UserID'] .'  $param_PartOfID: '. $testArray['PartOfID'] .' $param_PartOfObjVar: '. $testArray['cur']['BC'].' $param_KindOfObj: '.null .' $param_State: '.null.' $param_ConditionArray: '. $param_ConditionArray .'$param_checkWrite: '.null,1,1);
							D::show($param_ConditionArray,'$param_ConditionArray;  go to:. <a name="A'.STTree::$var_ctOut.'">A'.STTree::$var_ctOut.'</a>'.'<a href="#A'.(STTree::$var_ctOut-1).'"> back</a>'.' | <a href="#A'.(STTree::$var_ctOut+1).'"> next</a> | <a href="#anfang">Anfang</a> | <a href="#allTests">allTests</a> | <a href="#Succesfull">Succesfull</a> | <a href="#Failedassert">Failedassert</a> | <a href="#FailedID"></a> ',1,1);
							STTree::$var_ctOut++;
							echo '<br>ENDE------------------------------------------------------------ENDE<br>';
						}
						if($testArray['PartOfID_ST']['0']) {
							$num=count($testArray['PartOfID_ST']);
							for($i=0;$i<$num;$i++) {
								/**
								 * @todo TestSystem: Anpassung an die $param_HostAccount-iStorable Revolution ... sollte noch einmal überdacht werden 100320 @f
								 */
//								$param_testInput['TestArray']['C_ST'][$i] = $this->DB->getFromClipboard($testArray['UserID'], $testArray['PartOfID_ST'][$i], $testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
								$param_testInput['TestArray']['C_ST'][$i] = $this->DB->getFromClipboard($this->Help_getAccount($testArray['UserID']), $testArray['PartOfID_ST'][$i], $testArray['cur']['BC'], $param_KindOfObj=null,null, $param_ConditionArray);
							}
						}
					}
				}
				if(isset($param_testInput['TestCase']) && $param_testInput['TestCase'] != 'remove') {
				}
			}else if($param_testInput['CaseArray']['BC'] =='FriendList') {
			}
			if($param_testInput['TestArray']['C_ST'][0][0]['AttachID']) {
				$param_testInput['TestArray']['C_ST'][0][0]['MTextID'] = $param_testInput['TestArray']['C_ST'][0][0]['AttachID'];
			}else if (isset($param_testInput[$num]['TestArray']['C_ST'][0][0]['MTextID'])) {
				$param_testInput['TestArray']['C_ST']['0']['MTextID'] = $param_testInput['TestArray']['C_ST'][0][0]['MTextID'];
			}else if (isset($param_testInput['TestArray']['C_ST'][0][0]['MTextID'])) {
				$param_testInput['TestArray']['C_ST']['0'][0]['MTextID'] = $param_testInput['TestArray']['C_ST'][0][0]['MTextID'];
			}else if(isset($param_testInput['TestArray']['C_ST'][0][0]['AttachID'])) {
				$param_testInput['TestArray']['C_ST']['0'][0]['MTextID'] = $param_testInput['TestArray']['C_ST'][0][0]['AttachID'];
			}
			if(isset($param_testInput['TestArray']['PO'][0]['ID'])  ) {
				$param_testInput['TestArray']['C_ST']['0'][0]['MTextID'] = $param_testInput['TestArray']['PO'][0]['ID'];
			}
			$param_testInput['MTextID']=$param_testInput['TestArray']['C_ST']['0']['0']['MTextID'];
			$var_num_elements =count(STTree::$ary_walkFnc)-1;
			if(!is_numeric(STTree::$ary_walkFnc[$var_num_elements][count(STTree::$ary_walkFnc[$var_num_elements])-1])) {
				STTree::$ary_walkFnc[count(STTree::$ary_walkFnc)-1][]=$param_testInput['MTextID'];
			}
			if($param_testInput['TestArray']['C_ST']['0']['0']['AuthWriteListID']) {
				$param_testInput['TestArray']['C_ST']['0']['0']['WriteProfiles'] = $this->get_dbrowinfo('losp_BasisElement_writeauthorisation','ProfileID','where ListID="'.$param_testInput['TestArray']['C_ST']['0']['0']['AuthWriteListID'].'"');
			}
			if($param_testInput['TestArray']['C_ST']['0']['0']['AuthReadListID']) {
				$param_testInput['TestArray']['C_ST']['0']['0']['ReadProfiles'] = $this->get_dbrowinfo('losp_BasisElement_readauthorisation','ProfileID','where ListID="'.$param_testInput['TestArray']['C_ST']['0']['0']['AuthReadListID'].'"');
			}
			if(isset($param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['TestDesign'])&& $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['TestDesign'] == TRUE) {
				$param_testInput['TestArray']['C_ST']['0']['0']['Design'] = $this->getDesignFromDB($param_testInput,$i);
			}
			return $param_testInput;
		}
	}

	public function returnTagCategoryItem($param_name=null,$param_number=null,$param_wich = 'TagID',$param_where='TagName',$param_table='losp_BasisElement_tagnamelist') {
		if($param_name !== null) {
			$ary_num = $this->get_dbrowinfo($param_table,$param_wich, 'where '.$param_where.'=\''.$param_name.'\'' );
			$param_number = $ary_num[$param_wich]['0'];
		} else if($param_number !== null) {
			$ary_num = $this->get_dbrowinfo($param_table,$param_where, 'where '.$param_wich.'=\''.$param_number.'\'' );
			$param_number = $ary_num[$param_where]['0'];
		}
		if($param_name !== null && $param_number !== null) {
			$ary_taglist= array(
                'Ident'=>array(
                'ID'=>$param_number,
                'Name'=>$param_name
			)
			);
			return $ary_taglist;
		}
	}

	protected function getDesignFromDB($param_testInput,$param_num) {
		$var_ID = $param_testInput['TestArray']['C_ST']['0']['0']['BasisElementDesignID'];
		$var_cfgSTStd = STMANAGEData::getGenCfgSTStd();
		$var_cfgSTStd = $var_cfgSTStd['0'];
		$var_Design = $var_cfgSTStd['Design']['use'];
		$var_wichDesign = $param_testInput['TestArray']['C_ST']['0']['0']['losp_classname'] ;
		$ary_confValueKey['VKey'] = $var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element']['key']  ;
		$var_temp['VValue'] = $this->get_dbrowinfo('losp_BasisElementDesign_values','VValue', 'where ID = \''.$var_ID.'\' AND VKey = \''.$ary_confValueKey['VKey'].'\'' );
		$ary_out['VValue']['DB'] = $var_temp['VValue']['VValue']['0'];
		$ary_out['VValue']['Conf'] =$var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element']['value'] ;
		$ary_confValueKey['VKey1'] = $var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_1']['key']  ;
		$var_temp['VValue1'] = $this->get_dbrowinfo('losp_BasisElementDesign_values','VValue', 'where ID = \''.$var_ID.'\' AND VKey = \''.$ary_confValueKey['VKey1'].'\'' );
		$ary_out['VValue1']['DB'] = $var_temp['VValue1']['VValue']['0'];
		$ary_out['VValue1']['Conf'] =$var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_1']['value'] ;
		$ary_confValueKey['VKey2'] = $var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_2']['key']  ;
		$var_temp['VValue2'] = $this->get_dbrowinfo('losp_BasisElementDesign_values','VValue', 'where ID = \''.$var_ID.'\' AND VKey = \''.$ary_confValueKey['VKey2'].'\'' );
		$ary_out['VValue2']['DB'] = $var_temp['VValue2']['VValue']['0'];
		$ary_out['VValue2']['Conf'] =$var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_2']['value'] ;
		$ary_confValueKey['VKey3'] = $var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_3']['key']  ;
		$var_temp['VValue3'] = $this->get_dbrowinfo('losp_BasisElementDesign_values','VValue', 'where ID = \''.$var_ID.'\' AND VKey = \''.$ary_confValueKey['VKey3'].'\'' );
		$ary_out['VValue3']['DB'] = $var_temp['VValue3']['VValue']['0'];
		$ary_out['VValue3']['Conf'] =$var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['Element_3']['value'] ;
		$var_temp['CSS'] = $this->get_dbrowinfo('losp_BasisElementDesign','CSS', 'where ID = \''.$var_ID.'\'' );
		$ary_out['CSS']['DB'] = $var_temp['CSS']['CSS']['0'];
		$ary_out['CSS']['Conf']=$var_cfgSTStd['Design'][$var_wichDesign.$var_Design]['CSS'] ;
		$var_temp['Author_ProfileID'] = $this->get_dbrowinfo('losp_BasisElementDesign','Author_ProfileID', 'where ID = \''.$var_ID.'\'' );
		$ary_out['Author_ProfileID']['DB']=$var_temp['Author_ProfileID']['Author_ProfileID']['0'];
		$ary_out['Author_ProfileID']['Conf']=$param_testInput['TestArray']['C_ST']['0']['0']['Author_ProfileID'];
		$var_temp['BEClassName'] = $this->get_dbrowinfo('losp_BasisElementDesign','BEClassName', 'where ID = \''.$var_ID.'\'' );
		$ary_out['BEClassName']['DB'] = $var_temp['BEClassName']['BEClassName']['0'];
		$ary_out['BEClassName']['Conf']= $param_testInput['TestArray']['C_ST']['0']['0']['losp_classname'];
		return $ary_out;
	}

	protected function getAllDBTables() {
		$query = "show tables;";
		$stmt = $this->DB->PDO_query($query);
		$this->allDBTables = $this->DB->PDO_fetchAll($stmt);
	}

	protected function nextRow($param_resource=null) {
		BasicMySql::$count_nextRow++;
		return mysql_fetch_array($param_resource);
	}


	protected function get_dbrowinfo($param_table='losp_BasisElement_writeauthorisation',$param_wich='ProfileID', $param_where=null ) {
		$query = "SELECT ".$param_wich."  FROM ".$param_table." ".$param_where." ;";
		$stmt = $this->DB->PDO_query($query);
		$out = array($param_wich => array());
		foreach($this->DB->PDO_fetchAll($stmt) as $spalten) {
			$out[$param_wich][] = $spalten[$param_wich];
		}
		return $out;
	}


	protected function count_mysqlrows($param_table='losp_BasisElement_writeauthorisation', $param_tag='start') {
		$query = "SELECT COUNT(*) FROM ".$param_table." ;";
		$stmt = $this->DB->PDO_query($query);
		$i = 0;
		$out = array();
		foreach($this->DB->PDO_fetchAll($stmt) as $spalten) {
			$ary_keys= array_keys($spalten);
			$out[$param_tag] = $spalten[$ary_keys[$i]];
			$i++;
		}
//                D::show($out[$param_tag],'$out[$param_tag]',1,1);
  //              D::li('<br> a: '.$out[$param_tag].' b<br>',1,1);

                if(key_exists($param_tag, $out)&&$out[$param_tag]){
                    $this->countRowsArray[$param_table][$param_tag]=$out[$param_tag];
                }
		
	}

	protected function check_countRowsArray() {
		$testArray = $this->countRowsArray;
		$keys = array_keys($testArray);
		foreach ($keys  as $key) {
			if($testArray[$key]['start'] != $testArray[$key]['end']) {
				echo "[<font style=\"color:red\"><b>X</b></font style>]===> DB:</font style><font style=\"color:purple\"> <b> ".$key ."</b></font style> :  Datenbank hat mehr Eintr&auml;ge am Ende: <font style=\"color:red\">".$testArray[$key]['end'] ."</font style>, als zu Beginn des Tests: <font style=\"color:red\">". $testArray[$key]['start']."  </font> </b><br>" ;
			}else {
                              //  D::show($this->ary_testPar,'$this->ary_testPar',1,1);
				if($key=='losp_BasisElement' || $key=='losp_BasisClipboard') {
					echo "[<font style=\"color:green\"><b>OK</b></font style>]==> DB: <font style=\"color:purple\">".$key.'</font style> Start: '.$testArray[$key]['start'].' End: '.$testArray[$key]['end'].'<br>';
				}else if($this->ary_testPar['0']['showotheroutput']=='TRUE') {
					echo "[<font style=\"color:green\"><b>OK</b></font style>]==> DB: <font style=\"color:purple\">".$key.'</font style> Start: '.$testArray[$key]['start'].' End: '.$testArray[$key]['end'].'<br>';
				}
			}
		}
	}
}



?>