class_Form.inc.php 48 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
<?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;
	}


}
?>