<?php
/**
 * @file	Form.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 Form {
	/**
	 * static function chops a string at the sign "," OR ";" and returns an array with the trimed strings between the signs.
	 * Attention: ";" is only used if "," is not in the String
	 * If the String does not contain "," or ";" an array with $param_Varchar will be returned
	 *
	 * @param_Varchar String
	 *
	 * @return array
	 */
	public static function varcharToArray($param_Varchar) {
		$var_array = array();

		$param_Varchar = trim($param_Varchar);

		if(FALSE !== stripos($param_Varchar, ',')) {
			$var_array = explode(',', $param_Varchar);
		} else if(FALSE !== stripos($param_Varchar, ';')) {
			$var_array = explode(';', $param_Varchar);
		}
		else  {
			$var_array = array($param_Varchar);
		}

		$count_array = count($var_array);
		for($i=0; $i<$count_array; $i++) {
			$var_array[$i] = trim($var_array[$i]);
		}
		return $var_array;
	}
	public static function arrayToVarchar(array $param_Array) {
		$var_varchar = implode(", ", $param_Array);
		return $var_varchar;
	}
	/**
	 * functions formats an form-array to db-array
	 * @see class_BasisDesign::setData
	 *
	 * @param array $param_FormArray
	 *
	 * @return array
	 */
	public static function formValuesToArrayValues(array &$param_FormArray) {
		$var_Array = array();
		foreach($param_FormArray as $value) {
			if($value['VKey']){
				if($value['VKey'] == CONSTKindOf::DESIGN_MENUADDON && is_array($value['VValue'])){
					$tmp_value = '';
					foreach($value['VValue'] as $n_key => $n_value){
						if($n_value != '')
							$tmp_value .= $n_key.'[-]'.$n_value.',';
						else{
							$tmp_value .= $n_key.',';
						}
					}
					$var_Array[$value['VKey']] = substr($tmp_value, 0, -1);
				}
			else{
				$var_Array[$value['VKey']] = $value['VValue'];
				}
			}
		}
		return $var_Array;
    }
	/**
	 * This function cleans an Array (keys an values) or a String from Tags and supposed XSS-Code (calls Form::clearDataFromXSS)
	 *
	 * Attention: the parameter param_data will be overwritten
	 *
	 * @param $param_data the Array/String which should be cleaned
	 * @param String Whitelist string (optional)
	 *
	 * @return array the cleaned array/string
	 */
	public static function clearDataFromTags(&$param_data, $param_whitelist = ''){
		if(is_array($param_data)){
			foreach($param_data as $key => $value){

				$newKey = Form::clearDataFromXSS(strip_tags($key,$param_whitelist));
				if($newKey != $key){
					unset($param_data[$key]);
					$param_data[$newKey] = Form::clearDataFromTags($value,$param_whitelist);
				}
				else{
					$param_data[$key] = Form::clearDataFromTags($param_data[$key],$param_whitelist);
				}
			}
			return $param_data;
		}
		else{
			return Form::clearDataFromXSS(strip_tags($param_data,$param_whitelist));
		}
	}

	/**
	 * This function cleans a String from supposed XSS-Code
	 *
	 * @param String param_string
	 *
	 * @return String the cleaned String
	 */
	public static function clearDataFromXSS(&$param_string){
		$js_events_blacklist = '(on(abort|blur|change|click|dblclick|error|focus|keydown|keypress|keyup|load|mousedown|mousemove|mouseout|mouseover|mouseup|reset|resize|select|submit|unload)|(j){1,}[^>]*(a){1,}[^>]*(v){1,}[^>]*(a){1,}[^>]*(s){1,}[^>]*(c){1,}[^>]*(r){1,}[^>]*(i){1,}[^>]*(p){1,}[^>]*(t){1,}[^>]*\:)';

		$pattern = '/<[^>]*'.$js_events_blacklist.'[^>]*>/i';
		$param_string = preg_replace($pattern, '', $param_string);

		$src_blacklist = '(php\?|datasrc|datafld|dataformats|(\$\#){2,})';
		$pattern =  '/<[^>]*src[^>]*\=[^>]*'.$src_blacklist.'[^>]*>/i';
		$param_string = preg_replace($pattern, '', $param_string);

		return $param_string;
	}


	/**
	 * function replaces values defined in TreeCONFIG::$input_replace
	 * @param array $param_Data
	 */
	public static function replaceData(array &$param_Data){

		foreach(TreeCONFIG::$input_replace as $key => $value){
			if(array_key_exists($key,$param_Data)){
				foreach($value as $search => $replace){
					$param_Data[$key] = str_replace($search, $replace, $param_Data[$key]);
				}
			}
		}

	}

	public static function checkDataCompleteness(array $param_FormData, $param_MultimediaTextClassName) {
		//D::show($param_FormData, '$param_MultimediaTextClassName='.$param_MultimediaTextClassName.' ==== '.$param_FormData['losp_classname']);

		if(!empty($param_FormData) && is_subclass_of($param_MultimediaTextClassName, 'BasisElement')) {
			//D::show($param_FormData,'param_data');
			/*PflichtFelder*/
			$var_Formular_Check = CONFIG::getBC_XML($param_MultimediaTextClassName, 'Formular_Check');


			$var_Formular_Tags_KindOf = (CONFIG::getBC_XML($param_MultimediaTextClassName, 'Formular_Tags_KindOf'));

			if(is_array($var_Formular_Check)) {

				foreach($var_Formular_Check as $key => $value){
					if(array_key_exists($key,$param_FormData)){
						if(!$value){
							if($param_FormData[$key] == null){
								Error::newError("Form Error", $key." has no value","256");
								return false;
							}
						}
						else{
							Error::newError("Form Error", $value." rule is not defined","1");
							return false;
						}
					}
					/**
					 * @todo sonderbehandlung Link und Start überdenken @um
					 */
					else if($key == 'Link' && array_key_exists('files',$param_FormData)){
						if(!$value){
							if($param_FormData['files'] == null){
								Error::newError("Form Error", $key." has no value","256");
								return false;
							}
						}
						else{
							Error::newError("Form Error", $value." rule is not defined","1");
							return false;
						}
					}
					else if($key == 'Start' && array_key_exists('Start_day',$param_FormData) && array_key_exists('Start_month',$param_FormData) && array_key_exists('Start_year',$param_FormData)){
						if(!$value){
							if($param_FormData['Start_day'] == null || $param_FormData['Start_month'] == null || $param_FormData['Start_year'] == null){
								Error::newError("Form Error", $key." has no value","256");
								return false;
							}
						}
						else{
							Error::newError("Form Error", $value." rule is not defined","1");
							return false;
						}
					}
					else{
						Error::newError("Form Error", $key." does not exist as input","1");
						return false;
					}
				}

			}


			/*Existierende Felder*/
			$var_Formular_Tags = CONFIG::getBC_XML($param_MultimediaTextClassName, 'Formular_Tags');

			if(is_array($var_Formular_Tags)) {

				$var_CompositionColumns = CONFIG::getSQL_Data($param_MultimediaTextClassName, 'Composition');

				if(is_array($var_CompositionColumns)) {
					foreach($var_CompositionColumns as $var_ColumnKey => $var_ColumnValue) {
						$var_Formular_Tags = array_merge($var_Formular_Tags, CONFIG::getBC_XML($var_ColumnValue['class'], 'Formular_Tags'));
						$var_Formular_Tags_KindOf = array_merge($var_Formular_Tags_KindOf, CONFIG::getBC_XML($var_ColumnValue['class'], 'Formular_Tags_KindOf'));
					}
				}
				$var_Formular_Tags = array_unique ($var_Formular_Tags);
				//				$var_Formular_Tags_KindOf = array_unique ($var_Formular_Tags_KindOf);
				$var_Formular_Tags = array_flip($var_Formular_Tags);
				$var_Formular_Tags = array_diff_key($var_Formular_Tags, $var_Formular_Tags_KindOf);
				$var_array_intersect_key= array_intersect_key( $var_Formular_Tags , $param_FormData);
				$var_array_diff_key =  array_diff_key ( $var_Formular_Tags, $var_array_intersect_key);
			}
			if(empty($var_array_diff_key)) {
				return true;
			} else {
				D::show($var_array_diff_key, '$var_array_diff_key');
				//				D::show($param_FormData, '$param_FormData');
				//				D::show($var_Formular_Tags_KindOf, '$var_Formular_Tags_KindOf');
				return false;
			}

		} else {
			//			D::li('else und false');
			return false;
		}
	}

	public static function manageRightFromForm(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_FormData, array &$ReadProfileIDList, array &$WriteProfileIDList, $param_MultimediaTextClassName){//,&$ReadPropfileCollection = true) {

		$AuthorProfile = null;

 		if($param_HostAccount->getAuthorProfileID() != $param_HostAccount->getActiveProfileID()){
 			$AuthorProfile = MultimediaText::loadElement($param_HostAccount, $param_iStorable, null, $param_HostAccount->getAuthorProfileID());
 		} else{
 			$AuthorProfile = $param_HostAccount->getActiveProfile();
 		}
		if(is_object($AuthorProfile)) {
			$tmp_authorID = $AuthorProfile->getObjVar('ID');
		} else {
			$tmp_authorID = 0;
		}


		$tmp_write = true;
		$param_FormData['AuthorisationList']["WritePrivate"] = CONFIG::getRightManagementValues("WritePrivate");
		$tmp_read = true;
		$param_FormData['AuthorisationList']["ReadPrivate"] = CONFIG::getRightManagementValues("ReadPrivate");

		$specialRights = Config::getMultimediaTextPreferencs($param_MultimediaTextClassName, 'SpecialRights');
		if($specialRights){

			if(array_key_exists('Write', $specialRights)){
				$tmp_write = false;
				$WriteProfileIDList = self::getRWList($AuthorProfile , $specialRights['Write']);
			}
			if(array_key_exists('Read', $specialRights)){
				$tmp_read = false;
				$ReadProfileIDList = self::getRWList($AuthorProfile , $specialRights['Read']);
			}

		}

		/**
		 * profiles for write authorisation
		 */
		if($tmp_write)

		{
			if($param_FormData['AuthorisationList']["WriteNickName"]) {
				$param_FormData['AuthorisationList']["WriteNickName"] = Form::varcharToArray($param_FormData['AuthorisationList']["WriteNickName"]);
			} else {
				$param_FormData['AuthorisationList']["WriteNickName"] = array();
			}
			if(!array_key_exists('WriteFriends', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["WriteFriends"])){
				$param_FormData['AuthorisationList']["WriteFriends"]=array();
			}
			if(!array_key_exists('WriteSelected', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["WriteSelected"])){
				$param_FormData['AuthorisationList']["WriteSelected"]=array();
			}
			if(!array_key_exists('WriteGroups', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["WriteGroups"])){
				$param_FormData['AuthorisationList']["WriteGroups"]=array();
			}
			$WriteProfileIDList = array_merge($param_FormData['AuthorisationList']["WriteNickName"],$param_FormData['AuthorisationList']["WriteFriends"],$param_FormData['AuthorisationList']["WriteSelected"],$param_FormData['AuthorisationList']["WriteGroups"]);

			$var_count = count($WriteProfileIDList);
			for($i=0; $i<$var_count; $i++) {
				$WriteProfileIDList[$i] =Profile::NickNameToID($AuthorProfile->getObjVar('DB'), $WriteProfileIDList[$i]);
			}
			$WriteProfileIDList = array_unique ($WriteProfileIDList);
			sort($WriteProfileIDList);
		}

		/**
		 * right handling (@see http://vosp.info/index.php/LOSP_Abläufe#makeNew)
		 */
		if($tmp_read)
		{
			if($param_FormData['AuthorisationList']["WritePrivate"]==false && !empty($WriteProfileIDList)) {
				$param_FormData['AuthorisationList']["WritePrivate"] = true;
			}

			if($param_FormData['AuthorisationList']["WritePrivate"]==true) {
//				$tmp_authorID = $AuthorProfile->getObjVar('ID');
				if(array_key_exists('AuthorProfileID',$param_FormData) &&  $param_FormData['AuthorProfileID'] && $param_FormData['AuthorProfileID'] != $tmp_authorID){
					$tmp_authorID = $param_FormData['AuthorProfileID'];
				}
				if(false===array_search($tmp_authorID, $WriteProfileIDList)) {
					$WriteProfileIDList[] = $tmp_authorID;
				}

				/**
				 * profiles for read authorisation
				 */
				{

/**
 * @todo array auf existebs überprügen 100409
 */

					if($param_FormData['AuthorisationList']["ReadNickName"]) {
						$param_FormData['AuthorisationList']["ReadNickName"] = Form::varcharToArray($param_FormData['AuthorisationList']["ReadNickName"]);
					} else {
						$param_FormData['AuthorisationList']["ReadNickName"] = array();
					}
					if(!array_key_exists('ReadFriends', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["ReadFriends"])){
						$param_FormData['AuthorisationList']["ReadFriends"]=array();
					}
					if(!array_key_exists('ReadGroups', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["ReadGroups"])){
						$param_FormData['AuthorisationList']["ReadGroups"]=array();
					}
					if(!array_key_exists('ReadSelected', $param_FormData['AuthorisationList']) || !is_array($param_FormData['AuthorisationList']["ReadSelected"])){
						$param_FormData['AuthorisationList']["ReadSelected"]=array();
					}

					if(array_key_exists('ReadKind', $param_FormData)){
						switch($param_FormData['ReadKind']){
							case CONSTKindOf::BC_RIGHT_ALL : {
								$ReadProfileIDList = array();
				//				$ReadPropfileCollection = false;

								break;
							}
							case CONSTKindOf::BC_RIGHT_LOG : {
								$ReadProfileIDList = array();
					//			$ReadPropfileCollection = false;

								break;
							}
							case 'friends' : {
								$ReadProfileIDList = array();
								break;
							}
							case CONSTKindOf::BC_RIGHT_EXCLUSIVE : {
								$ReadProfileIDList = array_merge($param_FormData['AuthorisationList']["ReadNickName"], $param_FormData['AuthorisationList']["ReadSelected"],$param_FormData['AuthorisationList']["ReadGroups"]);
								break;
							}
							default : {
								$ReadProfileIDList = array_merge($param_FormData['AuthorisationList']["ReadNickName"],$param_FormData['AuthorisationList']["ReadFriends"],$param_FormData['AuthorisationList']["ReadGroups"],$param_FormData['AuthorisationList']["ReadSelected"]);
								break;
							}
						}
					}
					//abwärts kompatiblität
					else{
						$ReadProfileIDList = array_merge($param_FormData['AuthorisationList']["ReadNickName"],$param_FormData['AuthorisationList']["ReadFriends"],$param_FormData['AuthorisationList']["ReadGroups"],$param_FormData['AuthorisationList']["ReadSelected"]);
					}

					$var_count = count($ReadProfileIDList);
					for($i=0; $i<$var_count; $i++) {
						$ReadProfileIDList[$i] =Profile::NickNameToID($AuthorProfile->getObjVar('DB'), $ReadProfileIDList[$i]);
					}
					$ReadProfileIDList = array_unique ($ReadProfileIDList);
					sort($ReadProfileIDList);
				}

				if($param_FormData['AuthorisationList']["ReadPrivate"]==false && !empty($ReadProfileIDList)){
					$param_FormData['AuthorisationList']["ReadPrivate"] = true;
				}

				if($param_FormData['AuthorisationList']["ReadPrivate"] == true) {
					foreach($WriteProfileIDList as $var_pid) {
						if(false===array_search($var_pid, $ReadProfileIDList)) {
							$ReadProfileIDList[] = $var_pid;
						}
					}
				} else if($param_FormData['AuthorisationList']["ReadPrivate"] ==false && empty($ReadProfileIDList)) {
				}

			} else if($param_FormData['AuthorisationList']["WritePrivate"]==false && empty($WriteProfileIDList)) {
				$ReadProfileIDList = array();
			}
		}
	}

	/**
	 *	erstellt ein neues BasisElement aus den param_FormData (_POST) Formulardaten
	 * 	(in der Datenbank) und gibt es zurück
	 * 	@see http://vosp.info/index.php/LOSP_Abl%C3%A4ufe#makeNew
	 *
	 * 	@param array param_FormData
	 * 	@param Profile param_HostProfile
	 *
	 * 	@param BasisElement param_PartOf
	 * 	@param string param_BasisClipboardname
	 * 	@param string param_MultimediaTextClassName
	 * 	@param param_State
	 * 	@param array param_ConditionArray
	 * 	@param Account param_HostAccount
	 * 	@param array param_Tree
	 *  @param array param_addToLinkList
	 */
	public static function makeNewObjectFromFormData(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_FormData, MultimediaText $param_PartOf, $param_BasisClipboardname, $param_MultimediaTextClassName, $param_State, array $param_ConditionArray=null, array $param_Tree, $param_addToLinkList = false) {

		if(!array_key_exists('AuthorProfileID', $param_FormData) || !$param_FormData['AuthorProfileID']) {
			$param_FormData['AuthorProfileID'] = 0;
		}

		$var_AccountPossibleProfileIDArray = $param_HostAccount->getPossibleProfileIDArray();
D::show($var_AccountPossibleProfileIDArray, '$var_AccountPossibleProfileIDArray  - '.$param_FormData['AuthorProfileID']. ' ## '.array_key_exists($param_FormData['AuthorProfileID'], $var_AccountPossibleProfileIDArray));

//D::show($param_PartOf->getObjVar('RightManagement'), 'makeNewObjectFromFormData');

		if (	array_key_exists($param_FormData['AuthorProfileID'], $var_AccountPossibleProfileIDArray)
				&&
				(
					$var_AccountPossibleProfileIDArray[$param_FormData['AuthorProfileID']]['WriteRight']
						||
					array_key_exists('kindof', $var_AccountPossibleProfileIDArray[$param_FormData['AuthorProfileID']]) && $var_AccountPossibleProfileIDArray[$param_FormData['AuthorProfileID']]['kindof']==MemberProfileBC::STATE_AUTHOR_NAME
				)
		) {

			/**
			 * falls PartOf das Active Profile ist, aber mit einer anderen AuthorProfileID das BE erstellt werden soll, muss es auch dort eingehangen werden
			 */
			if(array_key_exists($param_PartOf->getObjVar('ID'), $var_AccountPossibleProfileIDArray) && array_key_exists($param_FormData['AuthorProfileID'], $var_AccountPossibleProfileIDArray)) {
				$param_PartOf = & MultimediaText::loadElement($param_HostAccount, $param_iStorable, '*', $param_FormData['AuthorProfileID']);
			}
			$var_BasisClipboardNameArray = CONFIG::getMT_BasisClipboards($param_PartOf->getObjVar('ThisClassName'), $param_ask='BasisClipboards');
			if(array_key_exists('chooseExistingBasisElements', $var_BasisClipboardNameArray[$param_BasisClipboardname]) && $var_BasisClipboardNameArray[$param_BasisClipboardname]['chooseExistingBasisElements']) {
				if($param_FormData['ChoosenBEID']) {
					$var_ID = $param_PartOf->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname)->add($param_HostAccount, $param_iStorable, $param_FormData['ChoosenBEID']);
					$BasisElement_1 =& MultimediaText::loadElement($param_HostAccount, $param_iStorable,'*', $param_FormData['ChoosenBEID']);
					unset($param_FormData['ChoosenBEID']);
				}
			}

			if(	(!array_key_exists('chooseExistingBasisElements', $var_BasisClipboardNameArray[$param_BasisClipboardname]))
			||
			(!$var_BasisClipboardNameArray[$param_BasisClipboardname]['chooseExistingBasisElements'])
			||
			($var_BasisClipboardNameArray[$param_BasisClipboardname]['chooseExistingBasisElements']['notCreateNew']==false)
			) {
					$param_FormData['RequestProfileID']  =$param_HostAccount->getActiveProfileID();
					$param_FormData['BECategoryChoiceBEID'] = CONFIG::getSoftwareCategoryMTextID($param_PartOf);

//D::show($param_FormData, '$param_FormData',1,1);
					/**
					 *	setAuth make new
					 */
					/**
					 * rigths management				 *
					 *
					 * śearchCodeAuthorisationList
					 */
					if(array_key_exists('PartOfRightMangement', $param_FormData) && $param_FormData['PartOfRightMangement'] && $param_PartOf->ThisClassName!=='Profile') {
//						D::show($param_PartOf->getObjVar('RightManagement')->getObjVar('RMProfileCollection'), '$param_FormData',1,1);
						$param_FormData['RightManagement']["RMProfileCollection"] = $param_PartOf->getObjVar('RightManagement')->getRMProfileCollection();
//						$param_FormData["AuthorisationList"] = $param_PartOf->getObjVar('RightManagement')->getAuthorisationList();

						$param_FormData['RightManagement']["AuthorisationList"] = $param_PartOf->getObjVar('RightManagement')->getAuthorisationList();
					} else if(	(array_key_exists('PartOfRightMangementRead', $param_FormData) && $param_FormData['PartOfRightMangementRead']) || (array_key_exists('PartOfRightMangementWrite', $param_FormData) && $param_FormData['PartOfRightMangementWrite'])) {
						return Error::newError('UserError','NotImplemented','Bis jetzt geht nur komplett PartOf oder gar nicht ;( ');
					} else {
						/**
						 * wandert endlich in die setData Funktion so wie bei den anderen auch 100612 @f
						 *
						 */
//						$WriteProfileIDList = $ReadProfileIDList = array();
//						Form::manageRightFromForm($param_AuthorProfile, $param_FormData, $ReadProfileIDList, $WriteProfileIDList, $param_MultimediaTextClassName);
//						$param_FormData["AuthorisationList"] = AuthorisationList::makeNew($param_HostAccount, $param_iStorable, $ReadProfileIDList, $WriteProfileIDList);
					}

//D::show($param_FormData, $param_PartOf);

					if($param_PartOf) {
						$BasisElement =& $param_PartOf->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname)->create($param_HostAccount, $param_iStorable, $param_FormData, $param_MultimediaTextClassName);
					} else {
						$BasisElement = BasisElement::makeNewObject($param_HostAccount, $param_iStorable,$param_MultimediaTextClassName, $param_FormData);
					}

					if(is_object($BasisElement)) {
						self::updateAddToLinkList ($param_HostAccount, $param_iStorable, $param_Tree, $param_PartOf, $param_BasisClipboardname, $BasisElement, $param_addToLinkList);
					} else {
						return Error::newError( 'DisplayError', 'NoSaveBE','nicht geklappt',' ');
					}
			}
			if($BasisElement) {
				return $BasisElement;
			} else {
				return $BasisElement_1;
			}
		} else {
			D::show($param_FormData, $param_PartOf);
			return Error::newError('UserError','you have not the right to create conent with the user id '.$param_FormData['AuthorProfileID'],E_USER_ERROR);
		}
	}
	private static function getRWList($param_HostProfile, $param_array){
		$return_array= array();
		foreach($param_array as $key => $value){
			if($key == 'hostProfile'){
				$return_array[]=$param_HostProfile->getID();
			}
		}
		return $return_array;
	}
	public static function updateAddToLinkList (Account &$param_HostAccount, iStorable &$param_iStorable, $param_Tree, BasisElement $param_PartOf, $param_BasisClipboardname, BasisElement $param_BasisElement, $param_addToLinkList= false) {

		$var_AvailbleBEs = self::getAvailableAddToLinkListBEArray($param_HostAccount, $param_iStorable, $param_PartOf, $param_Tree, $param_BasisClipboardname, $param_BasisElement);

		if(is_array($param_addToLinkList)) {

			foreach($param_addToLinkList as $var_AddToLink) {

				$var_BasisClipboardname = key($var_AddToLink);
				if(array_key_exists($var_AddToLink[$var_BasisClipboardname], $var_AvailbleBEs)) {
					/*
					 *  ausgewählt, !selected, ?required   =>  einhängen
					 */
					if(!array_key_exists('selected', $var_AvailbleBEs[$var_AddToLink[$var_BasisClipboardname]]) || $var_AvailbleBEs[$var_AddToLink[$var_BasisClipboardname]]['selected']!=='selected') {
						$var_AvailbleBEs[$var_AddToLink[$var_BasisClipboardname]]['obj']->getClipboard($param_HostAccount, $param_iStorable, $var_BasisClipboardname)->add($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'));
					}
					//  else  *  ausgewählt,  selected, ?required   =>  mache nichts
					unset($var_AvailbleBEs[$var_AddToLink[$var_BasisClipboardname]]);
				}
			}
		}

		foreach($var_AvailbleBEs as $var_PartOfID => $var_PartOfData) {

			$var_BasisClipboardname = $var_PartOfData['BasisClipboard'];

			/**
			 * !ausgewählt, !selected,  required   =>  einhängen
			 */
			if(( !array_key_exists('selected', $var_PartOfData) || $var_PartOfData['selected']!=='selected') && (array_key_exists('required', $var_PartOfData)  && $var_PartOfData['required']==='required')) {
				D::show($var_BasisClipboardname,$var_PartOfID.' EIN');
				$var_PartOfData['obj']->getClipboard($param_HostAccount, $param_iStorable, $var_BasisClipboardname)->add($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'));
			}
			/**
			 * !ausgewählt,  selected  !required   =>  aushängen
			 */
			else if((array_key_exists('selected', $var_PartOfData) && $var_PartOfData['selected']==='selected') && $var_PartOfData['required']!=='required') {
				D::show($var_BasisClipboardname,$var_PartOfID.' Out');
				$var_PartOfData['obj']->getClipboard($param_HostAccount, $param_iStorable, $var_BasisClipboardname)->remove($param_HostAccount, $param_iStorable,  $param_BasisElement->getObjVar('ID'));
			}
			// else * !ausgewählt,  selected,  required   =>  mache nichts*
			//      * !ausgewählt, !selected  !required   =>  mache nichts*
			//            D::ulli($var_PartOfID .' => selected='. $var_PartOfData['selected'] .'  disabled='.$var_PartOfData['disabled']. ' '. $var_PartOfData['']);
		}
	}

	/**
	 * @todo wird mindestens seit 100428 nicht merh aufgerufen @f
	 *
	 * @param iStorable param_DB
	 * @param int param_TheBEID
	 * @param array param_AddToLinkList it have to be keys param_AddToLinkList['HostID']['BasisClipboardname'][]
	 */
	private static function updateFromAddToLinkListArray(Account &$param_HostAccount, iStorable &$param_iStorable, $param_TheBEID, array $param_AddToLinkListArray, array &$param_deleteArray, array $param_ID_Array, BasisClipboard $param_PartOfBasisClipboard=null) {

		$var_SelectedArray = array();
		foreach($param_AddToLinkListArray as $var_return_value) {
			//D::ulli($var_return_value['HostID']);
			if(array_search($var_return_value['HostID'], $var_SelectedArray)===false) {
				/**
				 * @if POST: PartOf ausgewählt
				 */
				$Key_ID_Array = array_search($var_return_value['HostID'], $param_ID_Array);
				if($Key_ID_Array!==false) {
					//                    unset($param_ID_Array[$Key_ID_Array]);
					/**
					 * @if schon vorhanden
					 */
					if(is_object($param_PartOfBasisClipboard) && is_object($param_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_return_value['HostID']))) {
						/**
						 * @else noch nicht vorhanden
						 */
					} else {
						if(!array_key_exists('HostObject', $var_return_value) || !is_object($var_return_value['HostObject'])) {
							$var_return_value['HostObject'] =& MultimediaText::loadElement($param_HostAccount, $param_iStorable, $var_return_value['HostClassname'], $var_return_value['HostID'], $param_PartOf=null, $param_BasisClipboardArray=null, $param_OnlyWhenLouded=false);
						}
						$var_return_value['HostObject']->getClipboard($param_HostAccount, $param_iStorable, $var_return_value['BasisClipboardname'])->add($param_HostAccount, $param_iStorable, $param_TheBEID);
					}
					/**
					 *	Element vorhanden aber nicht ausgewählt
					 */
				} else if(is_object($param_PartOfBasisClipboard) && is_object($param_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_return_value['HostID']))) {
					$param_deleteArray[] =$var_return_value['HostID'] ;
					if(!array_key_exists('HostObject', $var_return_value) || !is_object($var_return_value['HostObject'])) {
						$var_return_value['HostObject'] = &MultimediaText::loadElement($param_HostAccount, $param_iStorable, $var_return_value['HostClassname'], $var_return_value['HostID'], $param_PartOf=null, $param_BasisClipboardArray=null, $param_OnlyWhenLouded=false);
					}
					$var_return_value['HostObject']->getClipboard($param_HostAccount, $param_iStorable, $var_return_value['BasisClipboardname'])->remove($param_HostAccount, $param_iStorable, $param_TheBEID);

				}
				$var_SelectedArray[] = $var_return_value['HostID'];
			}

		}
		//        D::show($param_deleteArray, '$param_deleteArray');
		//D::show($param_ID_Array, '$param_ID_Array');
	}
	private static function getDOMElementAddToLinkList(DOMDocument $param_DOMDocument, $param_HostID, $param_HostClassname, $param_HostSubject, $param_BasisClipboardname, $param_BasisElement, $param_CurrentObjectName) {
		//		D::backtrace();
		$var_KeyArray = array ();
		$var_KeyArray[0] = $param_HostClassname;
		$var_KeyArray[1] = $param_HostID;
		$var_KeyArray[2] = $param_BasisClipboardname;
		if(is_subclass_of($param_BasisElement, 'BasisElement')) {
			$var_KeyArray[3] = get_class($param_BasisElement);
			$var_KeyArray[4] = $param_BasisElement->getObjVar('ID');
		}

		$var_XMLaddToLinkList = $param_DOMDocument->createElement(CONSTKindOf::LINK_ADDTOLINKLIST);
		$var_XMLaddToLinkList->setAttribute('PartOfID', $param_HostID );
		$var_XMLaddToLinkList->setAttribute('BasisClipboardName', $param_BasisClipboardname);
		$var_XMLaddToLinkList->setAttribute('PartOfHostObject', $param_HostClassname);
		if(is_subclass_of($param_BasisElement, 'BasisElement')) {
			$var_XMLaddToLinkList->setAttribute('AttachID', $param_BasisElement->getObjVar('ID'));
			$var_XMLaddToLinkList->setAttribute('AttachObject', get_class($param_BasisElement));
		}
		$var_XMLaddToLinkList->setAttribute('parameter', self::arrayToVarchar($var_KeyArray));
		//		$var_Language2 =Language::getClassLinks($param_CurrentObjectName, $param_BasisClipboardname);
		$var_Language2 =Language::getClassLinks($param_HostClassname, $param_BasisClipboardname);
		$var_XMLaddToLinkList->setAttribute('label', $var_Language2['label'] );
		if(array_key_exists('image', $var_Language2) && $var_Language2['image']) {
			$var_XMLaddToLinkList->setAttribute('image', $var_Language2['image'] );
		}
		$var_XMLaddToLinkList->setAttribute('PartOfSubject', $param_HostSubject);

		return $var_XMLaddToLinkList;
	}

	/**
	 *  return an Array with available BasisElemets which can attach with param_BasisElement
	 *      (optional Parameter selected, disabled)
	 *
	 * @param BasisElement $param_PartOf
	 * @param array $param_Tree
	 * @param <type> $param_BasisClipboardname
	 * @param BasisElement $param_BasisElement
	 * @return <type>
	 */
	private static function getAvailableAddToLinkListBEArray(Account &$param_HostAccount, iStorable &$param_iStorable, BasisElement $param_PartOf=null, array $param_Tree, $param_BasisClipboardname=null, BasisElement $param_BasisElement=null) {
		$var_AvailbleBEs = array();

		/**
		 * @exeption
		 */
		if($param_BasisClipboardname==='ProfilePreferenceManager') {
			$param_BasisClipboardname = 'ProfileBC';
		} else if($param_BasisClipboardname===null && is_object($param_BasisElement) && is_subclass_of($param_BasisElement->ThisClassName.'BC', BasisClipboard)) {
			$param_BasisClipboardname = $param_BasisElement->ThisClassName.'BC';
		}

		/**
		 * $param_BasisElement Abhängigkeiten (only edit)
		 */
		if(is_object($param_BasisElement) && is_subclass_of($param_BasisElement, 'BasisElement') && (!class_exists($param_BasisClipboardname)  || !is_subclass_of($param_BasisClipboardname, 'BasisElement'))) {
			/**
			 * alle die schreiben dürfen sollen auch das BE verlinkt bekommen
			 */
			{
				$var_WriteList = $param_BasisElement->getObjVar('RightManagement')->getAuthorisationList()->getWriteList();

				foreach($var_WriteList as $var_WriteAuthorisation) {
					$var_WProfile =  &MultimediaText::loadElement($param_HostAccount, $param_iStorable, 'Profile', $var_WriteAuthorisation->getProfileID());

					if(is_array($var_WProfile) && $var_WProfile->getObjVar('ID') !== $param_BasisElement->getObjVar('ID') && $var_WProfile->checkBasisClipboardIfExists($param_BasisClipboardname)) {

						$var_AvailbleBEs[$var_WProfile->getObjVar('ID')] =  array(
															'disabled' => 'disabled',
															'required' => 'required',
															'kindofAddToLinkList' => 'WriteProfile',
															'BasisClipboard' => $param_BasisClipboardname,
															'obj' => $var_WProfile,
						);
						$var_Clipboard = &$var_WProfile->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
						if(is_object($var_Clipboard) && $var_Clipboard->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
							$var_AvailbleBEs[$var_WProfile->getObjVar('ID')]['selected'] = 'selected';
						}
					}
				}
			}


            /**
             * PartOfBasisClipboard
             * wenn param_BasisElement schon irgendwo einhängt ist, übernehme PartOfElemente ins $var_AvailbleBEs Array und setze  'selected' => 'selected'
             */
           {

                $var_PartOfBasisClipboard =& $param_BasisElement->getPartOfClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
//D::show($var_PartOfBasisClipboard,1,1,1);

				if(is_object($var_PartOfBasisClipboard)) {
					$var_PartOfIDList = $var_PartOfBasisClipboard->getObjVar('AttachIDList');
					foreach($var_PartOfIDList as $var_BEID => $var_PartOfID) {

						if(array_key_exists($var_BEID, $var_AvailbleBEs)) {
							$var_AvailbleBEs[$var_BEID]['selected'] = 'selected';
							$var_AvailbleBEs[$var_BEID]['kindofAddToLinkList'] = 'PartOfClipboard';
						} else {
							$var_AvailbleBEs[$var_BEID] =  array(
										'selected' => 'selected',
										'kindofAddToLinkList' => 'PartOfClipboard',
										'obj' => $var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID),
							);
						}

						$var_PartOfObjVar = $var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID)->getObjVar('PartOfObjVar');
						$var_CategoryName = $var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID)->getObjVar('CategoryName');

						 if($var_CategoryName) {
							$var_AvailbleBEs[$var_BEID]['BasisClipboard'] = $var_PartOfObjVar.'::'.$var_CategoryName;
						 } else {
							 $var_AvailbleBEs[$var_BEID]['BasisClipboard'] = $var_PartOfObjVar;
						 }
						 $var_AvailbleBEs[$var_BEID]['PartOfObjVar'] = $var_PartOfObjVar;
						 $var_AvailbleBEs[$var_BEID]['CategoryName'] = $var_CategoryName;
					}
				}
            }
        }
        /**
         *  PartOf
         *  PartOf Element muss falls noch nicht drinnen auch übernommen werden und zusätzlich 'disabled' => 'disabled' gesetzt werden
         */

		if(is_object($param_PartOf)) {
			if(array_key_exists($param_PartOf->getObjVar('ID'), $var_AvailbleBEs)) {
				$var_AvailbleBEs[$param_PartOf->getObjVar('ID')]['selected'] = 'selected';
				$var_AvailbleBEs[$param_PartOf->getObjVar('ID')]['disabled'] = 'disabled';
				//$var_AvailbleBEs[$param_PartOf->getObjVar('ID')]['required'] = 'required';
				$var_AvailbleBEs[$param_PartOf->getObjVar('ID')]['kindofAddToLinkList'] = 'PartOf';
			} else {
				$var_AvailbleBEs[$param_PartOf->getObjVar('ID')] =  array(
							'disabled' => 'disabled',
							'selected' => 'selected',
							//'required' => 'required',
							'kindofAddToLinkList' => 'PartOf',
							'obj' => $param_PartOf,
				);
			}
			//D::ulli($param_PartOf. ' PartOf');
			$var_AvailbleBEs[$param_PartOf->getObjVar('ID')]['BasisClipboard'] = $param_BasisClipboardname;
		}

		/**
		 * @exeption
		 */

		$var_IdentityManagement = CONFIG::getIdentityManagement();
		if(array_key_exists($param_BasisClipboardname, $var_IdentityManagement['SwitchProfiles']['BasisClipboards']) ) {
			  $param_BasisClipboardname = 'ProfileBC';
		 }


		/**
		 *  PartOfPartOf
		 *  PartOf Element muss falls noch nicht drinnen auch übernommen werden und zusätzlich 'disabled' => 'disabled' gesetzt werden
		 */

		if(is_object($param_PartOf) && is_object($param_PartOf->getObjVar('PartOf')) && $param_PartOf->getObjVar('PartOf')->checkBasisClipboardIfExists($param_BasisClipboardname)) {

			if(array_key_exists($param_PartOf->getObjVar('PartOf')->getObjVar('ID'), $var_AvailbleBEs)) {
				$var_AvailbleBEs[$param_PartOf->getObjVar('PartOf')->getObjVar('ID')]['selected'] = 'selected';
				$var_AvailbleBEs[$param_PartOf->getObjVar('PartOf')->getObjVar('ID')]['disabled'] = 'disabled';
				$var_AvailbleBEs[$param_PartOf->getObjVar('PartOf')->getObjVar('ID')]['kindofAddToLinkList'] = 'PartOf';
			} else {
				$var_AvailbleBEs[$param_PartOf->getObjVar('PartOf')->getObjVar('ID')] =  array(
                    'disabled' => 'disabled',
                    'selected' => 'selected',
                    'kindofAddToLinkList' => 'PartOfPartOf',
                    'obj' => $param_PartOf->getObjVar('PartOf'),
				);
			}
			//D::ulli($param_PartOf->getObjVar('PartOf'). ' PartOf->PartOf');
			$var_AvailbleBEs[$param_PartOf->getObjVar('PartOf')->getObjVar('ID')]['BasisClipboard'] = CONFIG::getAlias_BC($param_PartOf->getObjVar('PartOf')->ThisClassName,$param_BasisClipboardname);
		}



		/**
		 * PartOfPartOfClipboard
		 */
		if($param_PartOf) {
			$var_PartOfBasisClipboard =& $param_PartOf->getPartOfClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
			if(is_object($var_PartOfBasisClipboard)) {
				$var_PartOfIDList = $var_PartOfBasisClipboard->getObjVar('AttachIDList');
				foreach($var_PartOfIDList as $var_BEID => $var_PartOfID) {
					if(array_key_exists($var_BEID, $var_AvailbleBEs)) {
						$var_AvailbleBEs[$var_BEID]['kindofAddToLinkList'] = 'PartOfPartOfClipboard';
					} else if(is_object($var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID)) && $var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID)->checkBasisClipboardIfExists($param_BasisClipboardname)) {
						$var_AvailbleBEs[$var_BEID] =  array(
                                    'kindofAddToLinkList' => 'PartOfPartOfClipboard',
                                    'obj' => $var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID),
									'BasisClipboard' => CONFIG::getAlias_BC($var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID)->ThisClassName,$param_BasisClipboardname)
						);
					}
//					D::li($var_PartOfBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID) . '  ');
				}
			}
		}




		/**
		 * ActiveProfile
		 * falls ActiveProfile nicht PartOf und noch nicht drinnen ist, muss es auch rein ;)
		 */
		 if(array_key_exists('ActiveProfile', $param_Tree) && is_object($param_Tree['ActiveProfile'])) {
				if(( !$param_PartOf || $param_PartOf->getObjVar('ID') !== $param_Tree['ActiveProfile']->getObjVar('ID') )  && $param_Tree['ActiveProfile']->checkBasisClipboardIfExists($param_BasisClipboardname)) {

					if(array_key_exists($param_Tree['ActiveProfile']->getObjVar('ID'), $var_AvailbleBEs)) {
						$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['disabled'] = 'disabled';
						if($param_HostAccount->getAuthorProfileID() == $param_Tree['ActiveProfile']->getObjVar('ID')){
							$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['required'] = 'required';
						}
						else if(array_key_exists('required',$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')])){
							unset($var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['required']);
						}
						$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['kindofAddToLinkList'] = 'ActiveProfile';
						if(!is_object($var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['obj'])) {
							$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['obj'] = $param_Tree['ActiveProfile'];
						}
					} else {
						$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')] =  array(
										'disabled' => 'disabled',
										'kindofAddToLinkList' => 'ActiveProfile',
										'obj' => $param_Tree['ActiveProfile'],
						);
						if($param_HostAccount->getAuthorProfileID() == $param_Tree['ActiveProfile']->getObjVar('ID')){
							$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['required'] = 'required';
						}
						else if(array_key_exists('required',$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')])){
							unset($var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['required']);
						}
					}
					$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['BasisClipboard'] = CONFIG::getAlias_BC($param_Tree['ActiveProfile']->ThisClassName,$param_BasisClipboardname);
					if(is_object($param_BasisElement)) {
						$var_Clipboard  = &$var_AvailbleBEs[$param_Tree['ActiveProfile']->getObjVar('ID')]['obj']->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
						if(is_object($var_Clipboard) && $var_Clipboard->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
							$var_AvailbleBEs[$var_WProfile->getObjVar('ID')]['selected'] = 'selected';
						}
					}
				}
		 }

		/**
		 * Parts
		 * die inhaltlichen Stränge wie social movement, etc muss natürlich auch ins Array
		 */
		if(array_key_exists('Parts', $param_Tree)) {
			foreach($param_Tree['Parts'] as $var_PartObject) {

				if(!array_key_exists($var_PartObject->getObjVar('ID'), $var_AvailbleBEs)
					//&& $var_PartObject->checkBasisClipboardIfExists($param_BasisClipboardname)) {
					&& $var_PartObject->checkBasisClipboardIfExists($alias_BasisClipboardname = CONFIG::getAlias_BC(get_class($var_PartObject),$param_BasisClipboardname))){
					$var_AvailbleBEs[$var_PartObject->getObjVar('ID')] =  array('obj' => $var_PartObject,  'kindofAddToLinkList' => 'TreePart', 'BasisClipboard'=>$alias_BasisClipboardname );
				} else if(//$var_PartObject->checkBasisClipboardIfExists($param_BasisClipboardname)) {
					$var_PartObject->checkBasisClipboardIfExists($alias_BasisClipboardname = CONFIG::getAlias_BC(get_class($var_PartObject),$param_BasisClipboardname))){

						$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['kindofAddToLinkList'] = 'TreePart';
					if(!is_object($var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['obj'])) {
						$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['obj'] = $var_PartObject;
					}
					//$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['BasisClipboard'] = $param_BasisClipboardname;
					$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['BasisClipboard'] = $alias_BasisClipboardname;
					if(is_object($param_BasisElement)) {
						//$var_Clipboard  = &$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['obj']->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
						$var_Clipboard  = &$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['obj']->getClipboard($param_HostAccount, $param_iStorable, $alias_BasisClipboardname);
						if(is_object($var_Clipboard) && $var_Clipboard->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
							$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['selected'] = 'selected';
	//						D::show('haupt drin', $var_PartObject->getObjVar('ID'));
						}
					}
				}
			}
		}


		/**
		* ActiveProfile->Clipboard (Meine Sammlung), Meine Homepages, Meine Gruppen
		*/
		if(array_key_exists('ActiveProfile', $param_Tree) && is_object($param_Tree['ActiveProfile'])) {
		//		Meine Sammlung
			$var_ProfileBasisClipboard = &$param_Tree['ActiveProfile']->getClipboard($param_HostAccount, $param_iStorable, 'Clipboard');
			$param_Tree['ActiveProfile']->loadClipboard($param_HostAccount, $param_iStorable, 'Clipboard');

			if(is_object($var_ProfileBasisClipboard)) {

				$var_PartOfIDList = $var_ProfileBasisClipboard->getAllAttachIDList();

				foreach($var_PartOfIDList as $var_BEID => $var_PartOfID) {

					$var_BEobj =  &$var_ProfileBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID);
					if(is_object($var_BEobj) && $var_BEobj->checkBasisClipboardIfExists($param_BasisClipboardname)) {

						$var_AvailbleBEs[$var_BEID] =  array( 'kindofAddToLinkList' => 'MyClipboard');
						$var_AvailbleBEs[$var_BEID]['BasisClipboard'] = $param_BasisClipboardname;
						if(is_object($param_BasisElement) && $var_BEobj->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname)->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
							$var_AvailbleBEs[$var_BEID]['selected'] = 'selected';
						}
						$var_AvailbleBEs[$var_BEID]['obj'] =$var_BEobj;
					}

				}
			//	Meine Homepages
				$var_ProfileBasisClipboard = &$param_Tree['ActiveProfile']->getClipboard($param_HostAccount, $param_iStorable, 'TopicBC');
				$param_Tree['ActiveProfile']->loadClipboard($param_HostAccount, $param_iStorable, 'TopicBC');
				$var_PartOfIDList = $var_ProfileBasisClipboard->getAllAttachIDList();

				foreach($var_PartOfIDList as $var_BEID => $var_PartOfID) {

					$var_BEobj =  &$var_ProfileBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID);
					if(is_object($var_BEobj) && $var_BEobj->checkBasisClipboardIfExists($param_BasisClipboardname)) {

						$var_AvailbleBEs[$var_BEID] =  array( 'kindofAddToLinkList' => 'TopicBC');
						$var_AvailbleBEs[$var_BEID]['BasisClipboard'] = $param_BasisClipboardname;
						if(is_object($param_BasisElement) && $var_BEobj->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname)->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
							$var_AvailbleBEs[$var_BEID]['selected'] = 'selected';
						}
						$var_AvailbleBEs[$var_BEID]['obj'] =$var_BEobj;
					}

				}
				//add GroupProfileBEs

				$var_ProfileBasisClipboard = &$param_Tree['ActiveProfile']->getClipboard($param_HostAccount, $param_iStorable, 'GroupProfileBC');
				$param_Tree['ActiveProfile']->loadClipboard($param_HostAccount, $param_iStorable, 'GroupProfileBC');

				$var_PartOfIDList = $param_HostAccount->getPossibleProfileIDArray();
				foreach($var_PartOfIDList as $var_BEID => $var_PartOfID) {
					if( $param_PartOf->getObjVar('ID') !=  $var_BEID && $param_Tree['ActiveProfile']->getObjVar('ID') !=  $var_BEID){
						$var_BEobj =  &$var_ProfileBasisClipboard->get($param_HostAccount, $param_iStorable, $var_BEID);
						if(is_object($var_BEobj) && $var_BEobj->checkBasisClipboardIfExists($param_BasisClipboardname)) {
							$var_AvailbleBEs[$var_PartObject->getObjVar('ID')]['kindofAddToLinkList'] = 'GroupProfile';
							$var_AvailbleBEs[$var_BEID]['BasisClipboard'] = CONFIG::getAlias_BC($param_Tree['ActiveProfile']->ThisClassName,$param_BasisClipboardname);

							if($param_HostAccount->getAuthorProfileID() == $var_BEID){
								$var_AvailbleBEs[$var_BEID]['required'] = 'required';
							}
							/**
							 * @todo hab $var_BCGPBC jetzt mal überprüft wegen fettem error 100408 @f
							 */
							$var_BCGPBC = &$var_BEobj->getClipboard($param_HostAccount, $param_iStorable, $param_BasisClipboardname);
							if(is_object($param_BasisElement) && is_object($var_BCGPBC) && $var_BCGPBC->get($param_HostAccount, $param_iStorable, $param_BasisElement->getObjVar('ID'))) {
								$var_AvailbleBEs[$var_BEID]['selected'] = 'selected';
							}
							$var_AvailbleBEs[$var_BEID]['obj'] =$var_BEobj;
						}
					}
				}
			}
		}
		foreach($var_AvailbleBEs as $id => $el) {
			if(!is_object($el['obj'])) {
				$el['obj'] = MultimediaText::loadElement($param_HostAccount, $param_iStorable, '', $id);
			}

//			/**
//			 * @todo hier müssten noch die verschiedenen ProfileIDs und nicht nur das aktive 100408 @f
//			 */
//			if(!$el['obj']->getObjVar('RightManagement')->getObjVar('RightManagementBC')->checkWriteBC($el['BasisClipboard'], $param_HostAccount->getActiveProfileID())) {
			if(!$el['obj']->getObjVar('RightManagement')->getObjVar('RightManagementBC')->checkIfPossibleAddToBC($param_HostAccount, $param_iStorable, $el['BasisClipboard'])) {
				unset($var_AvailbleBEs[$id]);
			}
		}
		return $var_AvailbleBEs;
	}

	public static function getDOMElementsAddToLinkList(Account &$param_HostAccount, iStorable &$param_iStorable, $param_PartOf, $param_BasisClipboardname, $param_Tree, $param_DOMDocument, $param_BasisElement=null) {

		$var_DOMElementeArray = array();

		$var_AvailbleBEs = self::getAvailableAddToLinkListBEArray($param_HostAccount, $param_iStorable, $param_PartOf, $param_Tree, $param_BasisClipboardname, $param_BasisElement);
		foreach($var_AvailbleBEs as $var_AddToLinkBEID => $var_AddToLinkData) {
			if($var_AddToLinkData['BasisClipboard']) {
				$var_XMLaddToLinkList = self::getDOMElementAddToLinkList($param_DOMDocument, $var_AddToLinkBEID, $var_AddToLinkData['obj']->ThisClassName, $var_AddToLinkData['obj']->getObjVar('Subject'), $var_AddToLinkData['BasisClipboard'], $param_BasisElement, $var_AddToLinkData['obj']->ThisClassName);
			} else {
				$var_XMLaddToLinkList = self::getDOMElementAddToLinkList($param_DOMDocument, $var_AddToLinkBEID, $var_AddToLinkData['obj']->ThisClassName, $var_AddToLinkData['obj']->getObjVar('Subject'), $param_BasisClipboardname, $param_BasisElement, $var_AddToLinkData['obj']->ThisClassName);
			}

			if(array_key_exists('disabled', $var_AddToLinkData) && $var_AddToLinkData['disabled']) {
				$var_XMLaddToLinkList->setAttribute('disabled', 'disabled' );
			}
			if(array_key_exists('selected', $var_AddToLinkData) && $var_AddToLinkData['selected']) {
				$var_XMLaddToLinkList->setAttribute('selected', 'selected' );
			}
			$var_XMLaddToLinkList->setAttribute('kindofAddToLinkList', $var_AddToLinkData['kindofAddToLinkList'] );

			$var_DOMElementeArray[] = $var_XMLaddToLinkList;
		}

		return $var_DOMElementeArray;
	}


}
?>