class_CreateHelper.inc.php 15.3 KB
<?php
/**
 * @file	CreateHelper.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 CreateHelper extends STRunRecursive {
	/**
	 * @access private
	 */

	protected $var_partOfID;
	public $obj_curl;

	public function getSubTreeInfoForPost($param_BasisClipboard) {
		/**
		 *  ACHTUNG PROFILE 1,1 muss dynam werden
		 */

		/**
		 * @todo TESTSYSTEM achtung evt. muss hier modifierziert werden z.B. $obj_hostAcc->setMainProfileID oder so 100319 @f "$param_HostAccount, iStorable" Revolution
		 */
//		$obj_hostAcc = BasisElement::createNewInstance($this->DB, 'Account', 0, $param_PartOf);
//		$var_ActiveProfile = BasisElement::loadElement($this->DB, 'Profile', '1','1');
                if(!isset($param_PartOf)){
                    $param_PartOf=TRUE;
                }
		$obj_hostAcc = BasisElement::createNewInstance($this->DB, 'Account', 0, $param_PartOf);
		$var_ActiveProfile = BasisElement::loadElement($obj_hostAcc, $this->DB, 'Profile', '1');
		
		$var_return = array('BasisClipboard' => $param_BasisClipboard);
		$var_config= CONFIG::getConfig();
		$var_Treepart = $var_config['TreePart'];
		$var_PartKeys=array_keys($var_Treepart);
		$var_Parts = array();
		/** for each Treepart like Culture, Social Movement*/
		foreach($var_PartKeys as $key ) {
			/**
			 * @todo TESTSYSTEM achtung evt. muss hier modifierziert werden z.B. $obj_hostAcc->setMainProfileID oder so 100319 @f "$param_HostAccount, iStorable" Revolution
			 */
//			$var_Parts[] = BasisElement::loadElement($this->DB,$var_Treepart[$key], $param_ID=$key, $this->var_userID);
			$var_Parts[] = BasisElement::loadElement($obj_hostAcc, $this->DB,$var_Treepart[$key], $param_ID=$key);
		}
		$ary_Tree = array (
            'HostAccount' => $obj_hostAcc,
            'ActiveProfile' => $var_ActiveProfile,
            'Parts' => $var_Parts,
		);
		/**
		 * @todo TESTSYSTEM achtung evt. muss hier modifierziert werden z.B. $obj_hostAcc->setMainProfileID oder so 100319 @f "$param_HostAccount, iStorable" Revolution
		 */
//		TreeManipulator::runTree('start',$var_ActiveProfile, Profile::loadElement($this->DB, 'Profile', '1','1'),0,null,$param_callback="runTreeCallback_getBasisClipboard",&$var_return);
		TreeManipulator::runTree('start',$var_ActiveProfile, Profile::loadElement($obj_hostAcc, $this->DB, 'Profile', '1'),0,null,$param_callback="runTreeCallback_getBasisClipboard",&$var_return);
		
		foreach($ary_Tree['Parts'] as $var_OtherTreePart) {
			if(is_object($var_OtherTreePart)) {
				TreeManipulator::runTree('start', $var_ActiveProfile, $var_OtherTreePart ,$param_GET_index= 0,$param_url=null,$param_callback='runTreeCallback_getBasisClipboard', &$var_return);
			}
		}
		$i= '0';
		/**
		 * @todo TestSystem: muss überprüft werden ... ich hab jetzt mal das if vorgesetzt weil es dann hoffentlich nicht mehr WArnugen produziert 100324 @f
		 *
		 * Exception: test_initRunStaticTree -> Unexpected PHP error [Invalid argument supplied for foreach()] severity [E_WARNING] in [/home/frederick/git/losp/include/System/php/DevTools/ST/Helpers/class_CreateHelper.inc.php line 60]
		 */
		if(isset($var_return['result'])&&is_array($var_return['result'])) {
			foreach($var_return['result'] as $var_value) {
				$var_KeyArray = array ();
				$var_KeyArray[0] = get_class($var_value['HostObject']);
				$var_KeyArray[1] = $var_value['HostObject']->getObjVar('ID');
				$var_KeyArray[2] = $var_value['BasisClipboardname'];
				$var_array[$i]= $var_KeyArray;
				$i++;
				$var_Language2 =Language::getClassLinks($var_value['CurrentObjectName'], $var_value['BasisClipboardname']);
			}
		}
                if(!isset($var_array)){
                    $var_array = array ();
                }
		$num_a = count($var_array);
		$num_a = count($var_array);

		for($i=0;$i<$num_a;$i++) {
			$num_b = count($var_array[$i]);
			if($var_array[$i] == $var_array[$i+1]) {
				unset($var_array[$i]);
			}
		}
		return	$var_array;
	}

	protected function makeEdithelper($param_ary) {
		$num = count($param_ary['url']) -2;
		$var_CASE['MCase']=$param_ary['return']['cur']['MCase'];
		if($var_CASE['MCase']=='makeNew' || $var_CASE['MCase']=='newMessage' ) {
			$varBCClass = $param_ary['url'][$num];
		}else {
			$varBCClass = $param_ary['url'][$num-1];
		}
		if($num<'4'&& ( $var_CASE['MCase']=='makeNew' ||  $var_CASE['MCase']=='newMessage') ) {
			$varBCClassCO= CONFIG::getBC_MultimediaText($param_ary['url'][$num]);

		}else if( $var_CASE['MCase']=='makeNew' ||  $var_CASE['MCase']=='newMessage') {
			$varBCClassCO= CONFIG::getBC_MultimediaText($param_ary['url'][$num-4]);//CONFIG::getBC_MultimediaText($param_url['1']);
		}if($num<'4'&& ( $var_CASE['MCase']!='makeNew' | $var_CASE['MCase'] != 'newMessage'  )) {
			$varBCClassCO= CONFIG::getBC_MultimediaText($param_ary['url'][$num-1]);
		}else if($var_CASE['MCase']!='makeNew' | $var_CASE['MCase'] != 'newMessage' ) {
			$varBCClassCO= CONFIG::getBC_MultimediaText($param_ary['url'][$num-5]);//CONFIG::getBC_MultimediaText($param_url['1']);
		}
//                D::show($varBCClass,'$varBCClass',1,1);
		$varMTextClass = CONFIG::getBC_MultimediaText($varBCClass);
//                D::show($varMTextClass,'$varMTextClass',1,1);
		$var_CASE['BC'] = $varBCClass;
		$var_CASE['MT'] = $varMTextClass;
		$param_ary['BC'] = $varBCClass;
		$param_ary['MT'] = $varMTextClass;
		$var_Class = $param_ary['current'];
		$param_ary['return']['cur']['MCase'] = $var_CASE['MCase'];
		$param_ary['return']['cur']['BC']= $var_CASE['BC'];
		$param_ary['return']['cur']['MT'] = $var_CASE['MT'];
		$param_ary['return']['cur']['CO'] = $varBCClassCO;
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['UserID']= $this->var_userID;
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['PartOfID']= $this->var_userID;
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['Listener_NickName']= $this->Listener_NickName;
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['cur']=$param_ary['return']['cur'];
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['CO']=$param_ary['return']['cur']['CO'];
		/** $_GET */ {
		if($var_CASE['MCase'] == 'remove') {
			$var_last1 = array_pop($param_ary['url']);
			$var_last2= array_pop($param_ary['url']);
			array_push($param_ary['url'], 'showSingle');
			array_push($param_ary['url'], 'ID');
			array_push($param_ary['url'], $var_last1);
		}
		$param_ary['return'] = SendReceiveTools::createGET($param_ary['url'], $param_ary['return']);
		}
		/** Random Input */ {
		$param_ary['return'] = SendReceiveTools::genInput('12',$param_ary['return']);
		}
		/** cURL LOGIN */ {
		$obj_curl = new cURLTools();
		$var_httphost= STMANAGEData::getGenCfgSTStd('0');
		$var_httphost = 'http://'.$var_httphost['HTTP_HOST'].'/index.php';
		$param_ary['return']=$obj_curl->curllogin($this->var_userID,$this->var_userPW,$this->var_userID,null,$var_httphost,$param_ary['return']);
		}
		/** $_POST */ { {
		$obj_curl = new cURLTools();
		$var_httphost= STMANAGEData::getGenCfgSTStd('0');
		$var_httphost = 'http://'.$var_httphost['HTTP_HOST'].'/index.php';
		$param_ary['return']=$obj_curl->curllogin($this->var_userID,$this->var_userPW,$this->var_userID,null,$var_httphost,$param_ary['return']);
		}
		$var_num_url=count($param_ary['url'])-1;
		if($var_num_url<'4') {
			$this->var_partOfID =';';
		}
		if($var_num_url>'3'&& is_numeric($param_ary['url'][$var_num_url-2])&&$var_CASE['MCase']=='makeNew') {
			$this->var_partOfID = $param_ary['url'][$var_num_url-2];
		}
		if($var_num_url>'4'&& is_numeric($param_ary['url'][$var_num_url-3])&&$var_CASE['MCase']!='makeNew') {
			$this->var_partOfID = $param_ary['url'][$var_num_url-3];
		}

		if(!is_numeric($this->var_partOfID)) {
			$count = count($param_ary['url'])-2;
			$var_min = $count -3;
			for($i=$count;$i>'1';$i--) {
				$var_tmp = $param_ary['url'][$i];
				if(!is_numeric($var_tmp)) {
					$this->var_partOfID =$var_tmp;
				}
				//$count--;
			}
			if(!isset($var_tmp) | !is_numeric($var_tmp)) {
				$this->var_partOfID = $this->var_userID;
;
			}
		}
		$var_CrossPosting = $this->getSubTreeInfoForPost($varBCClassCO);
		$param_ary['return'] = SendReceiveTools::createPOST($this->var_userID,$this->var_userID,$this->var_attachID,$var_CrossPosting,$this->DB,$param_ary['return']);
		}
		$this->var_partOfID = $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['PartOfID'] ;
		$_GET = $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['GET'] ;
		$numGet = count($_GET['p'])-1;
		if($var_CASE['MCase'] != 'remove') {
			unset($_GET['p'][$numGet]);
		}

		$_POST = $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['POST'];
		if($this->ary_testPar['0']['ShowGET']=='TRUE') {
			$string = "<?php echo '### GET: <pre>'; print_r(" . var_export($_GET, true) . "); echo '</pre>';?>" ;
			$var_filename = STTree::$var_numCurWalkAry.'_'.$param_ary['return']['cur']['MCase'].'_Output.php';
			$this->obj_FileTools->fileputs($var_filename,$string,1);
		}
		if($this->ary_testPar['0']['ShowPOST']=='TRUE') {
			$string = "<?php echo '### POST: <pre>'; print_r(" . var_export($_POST, true) . "); echo '</pre>';?>" ;
			$var_filename = STTree::$var_numCurWalkAry.'_'.$param_ary['return']['cur']['MCase'].'_Output.php';
			$this->obj_FileTools->fileputs($var_filename,$string,1);
		}
		/** cURL send generated Data */ {
		$curlout = $obj_curl->curlSendData($param_ary['return']);
		$param_ary['return']['curl'] = $curlout;
		}
//                D::show($param_ary,'param_ary',1,1);
		return $param_ary['return'];
	}

	protected function dbhelper($param_ary) {
		$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['testAry']= $this->getDataFromDB($param_ary);
		$param_ary['return']['cur']['MTextID']=$param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['testAry']['MTextID'];
		$var_num_elements =count(STTree::$ary_walkFnc)-1;
		if($param_ary['return']['cur']['MTextID']&& $param_ary['return']['cur']['MTextID']!=null && !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_ary['return']['cur']['MTextID'];
		}


		return $param_ary['return'];
	}


	protected function showSingle($param_ary) {
		/**
		 * curl login
		 */
                 {
                    $obj_curl = new cURLTools();
                    $var_httphost= STMANAGEData::getGenCfgSTStd('0');
                    $var_httphost = 'http://'.$var_httphost['HTTP_HOST'].'/index.php';
                    $param_ary['return']=$obj_curl->curllogin($this->var_userID,$this->var_userPW,$this->var_userID,null,$var_httphost,$param_ary['return']);
                 }
                /**
		  * curl showSingle
		  */ 
                {
                     $var_MTextID = $param_ary['return']['cur']['MTextID'];
                     unset($_POST);
                   //  D::show($param_rtn['cur']['MT']);
                     /** Postoffice*/

                     if($param_ary['return']['cur']['MT'] == 'PostMessageBE'){
                        /** Teste sender*/
                        $_GET = array('p'=> array(
                        '0' => 'PostOffice', //PostOffice&p[1]=InBox&p[]=showBoth&p[]=ID&p[]=1374&lang=deu
                        '1' => 'Outbox',
                        '2' => 'showBoth',
                        '3' => 'ID',
                        '4' => $var_MTextID
                     ));
                     $curlout =$obj_curl->curlSendData($param_ary['return']);
                     /** Teste empfänger */
                     /**
                      * curl login empfänger
                      */
                    {
                        $obj_curl2 = new cURLTools();
                        $var_Conf_ST= STMANAGEData::getGenCfgSTStd('0');
                        $var_httphost=$var_Conf_ST;
                        $var_httphost = 'http://'.$var_httphost['HTTP_HOST'].'/index.php';
                        $param_ary['return2']=$obj_curl2->curllogin($var_Conf_ST['User2']['profile'],$var_Conf_ST['User2']['password'],$var_Conf_ST['User2']['profile'],null,$var_httphost,$param_ary['return']);
                    }
                     $_GET = array('p'=> array(
                        '0' => 'PostOffice', //PostOffice&p[1]=InBox&p[]=showBoth&p[]=ID&p[]=1374&lang=deu
                        '1' => 'Inbox',
                        '2' => 'showBoth',
                        '3' => 'ID',
                        '4' => $var_MTextID
                     ));
                     $curlout2 =$obj_curl2->curlSendData($param_ary['return2']);
//                     D::show($curlout2,'$curlout2',1,1);
                     }else{

                     $_GET = array('p'=> array(
                        '0' => 'showSingle',
                        '1' => 'ID',
                        '2' => $var_MTextID
                     ));
                     $curlout =$obj_curl->curlSendData($param_ary['return']);
                     }
//                     D::show($_GET,'GET',1,1);
                     
                     //                    D::show($curlout,'CURLOUT',1,1);
                     $param_ary['return']['curl'] = $curlout;
                     if($curlout2){
                         $param_ary['return']['curl2'] = $curlout2;
                     }
		 }
		 return $param_ary['return'];
	}











	protected function manageDatahelper($param_ary) {
		if($param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['testAry']['TestArray']['C_ST']['0'] ) {
			$testarray= $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['testAry']['TestArray']['C_ST'];
			STMANAGEData::setGenIn($testarray,$param_ary['return']['cur']['MCase'].$param_ary['return']['cur']['BC'].$param_ary['return']['cur']['MT']);
			$var_POST = $param_ary['return'][$param_ary['return']['cur']['MCase']][$param_ary['return']['cur']['BC']][$param_ary['return']['cur']['MT']]['POST'];
			STMANAGEData::setGenIn($var_POST,$param_ary['return']['cur']['MCase'].$param_ary['return']['cur']['BC'].$param_ary['return']['cur']['MT'].'POST');
		}
		return $param_ary['return'];
	}

}

?>