<?php
/*
 * DON'T REMOVE THE FOLLOWING LICENSE
 *           INFORMATION!
 * ----------------------------------
 * Copyright by
 * Global Cube Business Solutions
 * Author: Dennis Ritz
 * info@global-cube.de
 * 2007-2008
 * ----------------------------------
 */
class MISConfigurator extends App {	
	static private $generatedSectionIDs = array();
    static private $generatedReportIDs = array();
    static private $version = "20111130";
    
	public function __construct() {
		parent::__construct(__file__);
	}
	
	/*
	 * init
	 * ----
	 * This function sets the main workaround for this class.
	 */
	public function __init() {
		return $this->__COMPONENT();
	}
	
	private function _createSection($projectDOM,$projectXpath,$p_ID,$p_parentID,$p_username,$p_sectionName,$p_showHauptampel){
		$MISConfig = new MISConfig();
        
        if($projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_ID.'"]')->length > 0
                    ||  in_array($p_ID,self::$generatedSectionIDs)) {
	        $ID = null;
	        while($ID == null) {
	            $temp = mt_rand(0,99999);
	            if($projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$temp.'"]')->length == 0
	            &&  !in_array($temp,self::$generatedSectionIDs)) {
	                self::$generatedSectionIDs[] = $temp;
	                $ID = $temp;
	            }
	        }
	        $p_ID = $ID;
        }
		if(empty($p_ID))
            $newID = $this->_generateSectionID();
        else 
            $newID = $p_ID;   
            
        $PP = $projectDOM->createElement('Publish');
        $PP->setAttribute('ID',$newID);
        $PP->setAttribute('parentID',$p_parentID);
        $PP->setAttribute('User',utf8_encode($p_username));
        $PP->setAttribute('Name',utf8_encode("_".str_replace(" ","_",trim($p_sectionName,"_ "))."_"));
        $PP->setAttribute('Alert',utf8_encode($p_showHauptampel));
        $PP->appendChild($projectDOM->createElement('Images'));
        $projectDOM->getElementsByTagName("Publishes")->item(0)->appendChild($PP);
        
        $SS = $projectDOM->createElement("Scorecard");
        $SS->setAttribute("ID",$newID);
        $SS->setAttribute("Directory",utf8_encode($p_username)."\\");
        $SS->setAttribute("Name",utf8_encode("_".str_replace(" ","_",trim($p_sectionName,"_ "))."_"));
        $SS->appendChild($projectDOM->createElement("Reports"));
        $projectDOM->getElementsByTagname("Scorecards")->item(0)->appendChild($SS);
        
        $SS = $projectDOM->createElement("Dashboard");
        $SS->setAttribute("ID",$newID);
        $SS->setAttribute("Directory",utf8_encode($p_username)."\\");
        $SS->setAttribute("Name",utf8_encode("_".str_replace(" ","_",trim($p_sectionName,"_ "))."_"));
        $SS->appendChild($projectDOM->createElement("Reviews"));
        $projectDOM->getElementsByTagname("Dashboards")->item(0)->appendChild($SS);

        $projectDOM->save($MISConfig->getConfigFile());
        return $newID;
	}
	
	private function _registerEmails($p_emailStr) {
		$MISConfig = new MISConfig();
        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $ProjectDOM->load($MISConfig->getConfigFile());
        $ProjectXpath = new DOMXpath($ProjectDOM); 
        
        $emailArr = explode(";",$p_emailStr);
        foreach($emailArr as $i => $email) {
        	$emailExists = $ProjectXpath->query("/Configuration/Emails/Email[. = '".trim($email)."']")->length > 0 ? true : false;
        	if(!$emailExists && $email != "") $MISConfig->setNodeValue("Email",trim($email),$ProjectDOM,$ProjectXpath->query("/Configuration/Emails")->item(0),$ProjectXpath->query("/Configuration/Emails/Email")->length);
        }
        $ProjectDOM->save($MISConfig->getConfigFile());
	}
	
	public function _getAllDashboards() {
		$MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);  
         
        $PPRPath = $projectXpath->query("/Configuration/General/DashboardPath")->item(0)->nodeValue;
        $PPRArr = array();
        $handle = opendir($PPRPath);
        while ($file = readdir ($handle)) {
            if($file != "." && $file != "..") {
                if(is_file($PPRPath."/".$file)) {
                    $filename = substr($file,0,strripos($file,"."));
                    array_push($PPRArr,$filename);
                }
            }
        }
        if(!$this->isRole("admin")) return array();
        return $PPRArr;
	}
	
	public function getMain($p_section = null) {
		if($this->getAuth()) {
			if($this->isRole("admin")) {
				
				$p_args = func_get_args();
				$p_section = array_shift($p_args);
				if(!$this->isRole("admin") && $p_section == "configSettings")$p_section="general";
				$eval = array();
				//if($p_section=="configSettings") {
					$menu = new Tree("configuratorMenu");
					$this->getConfiguratorMenu($menu);
					array_push($eval,'CMgr.getMODEL().setNavContainer(\''.addslashes(''.$menu.'').'\')');
					array_push($eval,'Tree.setToUserView(Browser.getElementById("configuratorMenu"))');
					if($this->isRole("master"))
					array_push($eval,'if(DEBUG_LEVEL != 0){Browser.getElementById("debug").getElementsByTagName("td")[0].style.color="#ff0000";}else{Browser.getElementById("debug").getElementsByTagName("td")[0].style.color="#000053";};');
				//}
				$ret = '<div id="content">';
					$arr = call_user_func_array(array($this, $p_section), $p_args);
					$ret.= $arr[0];
					array_push($eval,$arr[1]);
					array_push($eval,';CMgr.getMODEL().setLocationName(\''.addslashes(new Label($this->_getI18N("administration"))).'\')');
				$ret.= '</div>';
				
                $sectionLabel = new Label(new Icon("img/arrow_back.png"),$this->_getI18N("back"));
                array_push($eval,';CMgr.getMODEL().setLeftToolbar(\'<div id="sectionItem" onclick="CMgr.getMODEL().getMain(\\\'MISView\\\',\\\'overview\\\');">'.$sectionLabel.'</div>\')');
                array_push($eval,'CMgr.getMODEL().setMainToolbar("");CMgr.getMODEL().setMainHead(\''.addslashes(new Label($this->_getI18N($p_section))).'\')');
               	$sectionLabel = new Label(new Icon("img/Configurator.png"),$this->_getI18N("configurator"));
				array_push($eval,'CMgr.getMODEL().setLeftFootbar(\'<div id="sectionItem" onclick="CMgr.getMODEL().getMain(\\\'MISConfigurator\\\',\\\'info\\\');">'.$sectionLabel.'</div>\')');                
				return array($ret,implode(";",$eval));
			} else {
				return array('','');
			}
		} else {
			return array('','CMgr.getMODEL().__construct();');	
		}
	}
	
	private function getConfiguratorMenu($p_node) {
		if($this->isRole("admin")) {
				$adminNode = new TreeNode(new Label($this->_getI18N("info")),"info");
				$p_node->appendChild($adminNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","info");');
				$adminNode->addEventListener($eventListener);
			if($this->getUsername() == "master") {
				$infoNode = $adminNode;
                
                $adminNode = new TreeNode(new Label($this->_getI18N("version")),"version");
                $infoNode->appendChild($adminNode);
                $eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","version");');
                $adminNode->addEventListener($eventListener);
			}
				$c_node = new TreeNode(new Label($this->_getI18N("configSettings")),"configSettings");
				$p_node->appendChild($c_node);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","configSettings");');
				$c_node->addEventListener($eventListener);
				
				$adminNode = new TreeNode(new Label($this->_getI18N("general")),"general");
				$c_node->appendChild($adminNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","general");');
				$adminNode->addEventListener($eventListener);
				
				$adminSubNode = new TreeNode(new Label($this->_getI18N("alarmConfig")),"alarmConfig");
				$adminNode->appendChild($adminSubNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","alarmConfig");');
				$adminSubNode->addEventListener($eventListener);
				
				$adminSubNode = new TreeNode(new Label($this->_getI18N("imageConfig")),"imageConfig");
				$adminNode->appendChild($adminSubNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","imageConfig");');
				$adminSubNode->addEventListener($eventListener);
				
                $adminSubNode = new TreeNode(new Label($this->_getI18N("versionConfig")),"versionConfig");
                $adminNode->appendChild($adminSubNode);
                $eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","versionConfig");');
                $adminSubNode->addEventListener($eventListener);
				
				$adminNode = new TreeNode(new Label($this->_getI18N("publishes")),"publishes");
				$c_node->appendChild($adminNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","publishes");');
				$adminNode->addEventListener($eventListener);
				
				$adminNode = new TreeNode(new Label($this->_getI18N("emailSetup")),"emailSetup");
				$c_node->appendChild($adminNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","emailSetup");');
				$adminNode->addEventListener($eventListener);			

				$emailNode = new TreeNode(new Label($this->_getI18N("export")),"emailExport");
				$adminNode->appendChild($emailNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","emailExport");');
				$emailNode->addEventListener($eventListener);								
				
				$adminNode = new TreeNode(new Label($this->_getI18N("languages")),"languages");
				$p_node->appendChild($adminNode);
				$eventListener = new EventListener("onclick",'CMgr.getMODEL().getMain("MISConfigurator","languages");');
				$adminNode->addEventListener($eventListener);
				
                $adminNode = new TreeNode(new Label($this->_getI18N("debug")),"debug");
                $p_node->appendChild($adminNode);
                $eventListener = new EventListener("onclick",'if(DEBUG_LEVEL == 0){this.parentNode.getElementsByTagName("td")[0].style.color="#ff0000";DEBUG_LEVEL=3;} else {this.parentNode.getElementsByTagName("td")[0].style.color="#000053";DEBUG_LEVEL=0;}');
                $adminNode->addEventListener($eventListener);
		}
	}
	
	public function saveMain(){
		if($this->getAuth()) {
			if($this->isRole("admin")) {
				global $Core;
				
				$p_args = func_get_args();
				$p_method = array_shift($p_args);
				//ATTENTION CLIENT CAN CALL PRIVATE FUNCTIONS! MUST VERIFY THAT USER IS MASTER
				$ret = call_user_func_array(array($this, $p_method), $p_args);
		
				$MISConfig = new MISConfig();
				$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
				$ProjectDOM->load($MISConfig->getConfigFile());
				$ProjectXpath = new DOMXpath($ProjectDOM);
				$creatorPath = $ProjectXpath->query('/Configuration/General/WebCreatorPath')->item(0)->nodeValue;
				if(is_dir($creatorPath)) {
					copy($MISConfig->getConfigFile(),$creatorPath.basename($MISConfig->getConfigFile()));
					$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
			        $ProjectDOM->load($creatorPath.basename($MISConfig->getConfigFile()));
			        $ProjectXpath = new DOMXpath($ProjectDOM);
					$ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Dashboards")->item(0));
					$ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Version")->item(0));
					$ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Emails")->item(0));
					$ProjectDOM->save($creatorPath.basename($MISConfig->getConfigFile()));
				}
				return $ret;
			}
			return array('CMgr.getMODEL().__construct();');
		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function configSettings() {
		$ret = "";
		if($this->isRole("admin")) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$temp_projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$xpath = new DOMXpath($projectDOM);
		$currentConfigFile = basename($MISConfig->getConfigFile());
		$Tree = new Tree("administrationMenu5");
		$ret .= '
	<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\');" style="position:absolute;top:0px;left:305px;border:0px solid #ff0000;bottom:0px;width:300px;">
		<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
			<legend  style="position:absolute;" style="font-size:1.2em;"><label for="createConfig" style="font-size:1.2em;">'.$this->_getI18N("configSettings").'';
		if($this->isRole("master")) $ret.='<input class="btn" type="button" value="'.$this->_getI18N('import').'" onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'loadConfig\');">';
		$ret.='</label></legend>
			<div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">
			<input type="hidden" name="saveMethod" value="saveConfigFile">';
			$configFiles = $MISConfig->getAllConfigFiles();
			foreach($configFiles as $configFile) {
				if($configFile=="default.xml")continue;
				$temp_projectDOM->load(ROOT_DIR."apps/MISConfig/data/".$configFile);
				$temp_projectXpath = new DOMXpath($temp_projectDOM);
				$configName = $temp_projectXpath->query("/Configuration")->item(0)->getAttribute("Name");
				
				if($currentConfigFile == $configFile) {
					$configLabelInput = new Input($configFile,"currentConfig","btn","radio",$configFile,true);
				} else {
					$configLabelInput = new Input($configFile,"currentConfig","btn","radio",$configFile);
					$newEventListener = new EventListener("onclick",'this.form.onsubmit();');
					$configLabelInput->addEventListener($newEventListener);
				}
				$newIcon = new Icon("./img/package.png");
				$newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
				if($this->isRole("master"))
					$configLabel = new Label($configLabelInput,"<label for='".$configFile."'>".$newIcon.$configName." (".$configFile.")</label>");
				else
					$configLabel = new Label($configLabelInput,"<label for='".$configFile."'>".$newIcon.$configName."</label>");
				
				$configNode = new TreeNode($configLabel);
				$Tree->appendChild($configNode);
				if(strtolower($configName) != "default" && $this->isRole("master")) {
				
					$newContextMenu = new ContextMenu();

					$newLabel = new Label(new Icon("img/download.png"),$this->_getI18N("export"));
					$newContextMenuNode = new ContextMenuNode($newLabel);
					$newEventListener = new EventListener("onclick",'window.location="?&rc=MISConfigurator&rm=exportConfig&ras[]='.$configFile.'"');
					$newContextMenuNode->addEventListener($newEventListener);
					$newContextMenu->appendChild($newContextMenuNode);
					
					$newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
					$newContextMenuNode = new ContextMenuNode($newLabel);
					$newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editConfig","'.$configFile.'");');
					$newContextMenuNode->addEventListener($newEventListener);
					$newContextMenu->appendChild($newContextMenuNode);

                    $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
                    $newContextMenuNode = new ContextMenuNode($newLabel);
                    $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteConfig","'.$configFile.'");');
                    $newContextMenuNode->addEventListener($newEventListener);
                    $newContextMenu->appendChild($newContextMenuNode);
					
					$configNode->addContextMenu($newContextMenu);
				}
			}
			$ret.= $Tree->__toString();

			$ret.= '</div>
		</fieldset>
	</form>';

			if($this->isRole("master")){
				$Tree = new Tree("administrationMenu6");
		$ret .= '
	<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\');" style="position:absolute;top:0px;left:0px;border:0px solid #ff0000;bottom:0px;width:300px;">
		<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
			<legend  style="position:absolute;" style="font-size:1.2em;"><label for="createConfig" style="font-size:1.2em;">'.$this->_getI18N("defaultConfig").'</label></legend>
			<div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;padding:5px;">
			<input type="hidden" name="saveMethod" value="saveDefaultConfigFile">';
		$ret.=$this->_getI18N("defaultConfigInfoMsg");
		$ret.= '<select style="float:right;margin:10px;" onchange="this.form.onsubmit();">';
		$defaultConfigFile = $MISConfig->getDefaultConfigFile();
		foreach($configFiles as $configFile) {
			if($configFile=="default.xml" && $defaultConfigFile != $configFile)continue;
			$temp_projectDOM->load(ROOT_DIR."apps/MISConfig/data/".$configFile);
			$temp_projectXpath = new DOMXpath($temp_projectDOM);
			$configName = $temp_projectXpath->query("/Configuration")->item(0)->getAttribute("Name");
			if($defaultConfigFile == $configFile)
			$ret.= '<option value="'.$configFile.'" selected="selected">'.$configName.' ('.$configFile.')</option>';
			else
			$ret.= '<option value="'.$configFile.'">'.$configName.' ('.$configFile.')</option>';	
		}
		$ret.= '</select>';
			$ret.= '</div>
		</fieldset>
	</form>';
			}
		}
		return array($ret,'');
	}

	private function saveConfigFile($p_currentConfigFile) {
		if($this->isRole("admin") && $p_currentConfigFile != "" && $p_currentConfigFile!= null) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$MISConfig->setConfigFile($p_currentConfigFile);
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		return array('CMgr.getMODEL().__construct();CMgr.getMODEL().setConfig("'.$projectXpath->query("/Configuration")->item(0)->getAttribute("Name").'")');
		}else{
		return array('CMgr.getMODEL().__construct();');
		}
	}
	
	private function saveDefaultConfigFile($p_defaultConfigFile) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		$this->deleteDir($projectXpath->query("/Configuration/General/PublishImagePath")->item(0)->nodeValue);
		if($this->isRole("master") && $p_defaultConfigFile != "" && $p_defaultConfigFile!= null) $MISConfig->setDefaultConfigFile($p_defaultConfigFile);
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function info(){
		$ret = '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("info").'</label></legend>
					<table>';
		$ret .= '<tr><td class="label">'.$this->_getI18N("info_welcome").'</td></tr>';
		$ret.= '	</table>
				</fieldset>
			</form><br>';
		$ret.= '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("changelog").'</label></legend>
					<table>';
		$ret .= '<tr><td class="label">30.11.2011 - New feature - PDF Layer at Email export</td></tr>';
		$ret .= '<tr><td class="label">30.11.2011 - Fixed bug - Freeze of andministration module</td></tr>';
		$ret .= '<tr><td class="label">30.11.2011 - New feature - Infoscreen in administration module</td></tr>';
		$ret .= '<tr><td class="label">30.11.2011 - Fixed bug - Blank screen of administration module on offline systems</td></tr>';
		$ret .= '<tr><td class="label">15.11.2011 - Fixed bug - Switching between reportpreview YES/NO</td></tr>';
		$ret.= '	</table>
				</fieldset>
			</form>';
		return array($ret,'');
	}
	
	private function version(){
		$ret="";
		if($this->isRole("master")) {
					$buffer = "";

					if (fsockopen("www.global-cube.de", 80, $errno, $errstr, 5)) {
						$filestream = fopen("http://www.global-cube.de/GAPS/version.txt", "r");
						
						while(!feof($filestream)) {
						    $buffer .= fgets($filestream, 4096);
						}
						fclose($filestream);
					}
					if($buffer==""){
						$versionLabel2 = new Label($this->_getI18N("offline")); 
					}else{
						$versionLabel2 = new Label($buffer); 
					}
					if(is_numeric(self::$version) && $buffer > self::$version) {
						$versionLabel1 = new Label("<font color='dd0000'>".self::$version."</font>"); ;
					}elseif(is_numeric(self::$version) && $buffer < self::$version) {
						$versionLabel1 = new Label("<font color='00dd00'>".self::$version." (Pre Build)</font>"); ;
					}elseif(is_numeric(self::$version) && $buffer == self::$version){
						$versionLabel1 = new Label(self::$version); ;
					}else{
						$versionLabel1 = new Label("<font color='ff6600'>".self::$version." (Customer Build)</font>"); ;
					}

		$ret.= '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("version").'</label></legend>
					<table>';
		$ret.= '<tr><td class="label">'.$this->_getI18N("info_version").'</td></tr>';
		$ret.= '	</table>
				</fieldset>
			</form><br>';
		$ret.= '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("current_version").'</label></legend>
					<table>';
		$ret.= '<tr><td class="label">'.$versionLabel1.'</td></tr>';
		$ret.= '	</table>
				</fieldset>
			</form>';
		$ret.= '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("available_version").'</label></legend>
					<table>';
		$ret.= '<tr><td class="label">'.$versionLabel2.'</td></tr>';
		$ret.= '	</table>
				</fieldset>
			</form>';
		}
		return array($ret,'');
	}
	
	
	private function general() {
		$MISConfig = new MISConfig();
		$structureDOM = new DOMDocument('1.0', 'iso-8859-1');
		$structureDOM->load($MISConfig->getConfigFile());
				
		$xpath = new DOMXpath($structureDOM);
		$general['DashboardPath'] = $xpath->query('/Configuration/General/DashboardPath')->item(0)->nodeValue;
		$general['WebCreatorPath'] = $xpath->query('/Configuration/General/WebCreatorPath')->item(0)->nodeValue;
		$general['CubePath'] = $xpath->query('/Configuration/General/CubePath')->item(0)->nodeValue;
		$general['ReportPath'] = $xpath->query('/Configuration/General/ReportPath')->item(0)->nodeValue;
		$general['WebReportPath'] = $xpath->query('/Configuration/General/WebReportPath')->item(0)->nodeValue;
		$general['PublishPath'] = $xpath->query('/Configuration/General/PublishPath')->item(0)->nodeValue;
		$_SESSION["Config"]["General"]["PublishImagePath"] = $general['PublishImagePath'] = $xpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;
		$general['PublishAlarmPath'] = $xpath->query('/Configuration/General/PublishAlarmPath')->item(0)->nodeValue;
		$general['WebServerName'] = $xpath->query('/Configuration/General/WebServerName')->item(0)->nodeValue;
		$general['PortalStartPage'] = $xpath->query('/Configuration/General/PortalStartPage')->item(0)->nodeValue;
		$general['PDFURL'] = $xpath->query('/Configuration/General/PDFURL')->item(0)->nodeValue;
		$general['ReportURL'] = $xpath->query('/Configuration/General/ReportURL')->item(0)->nodeValue;
		$general['CubeURL'] = $xpath->query('/Configuration/General/CubeURL')->item(0)->nodeValue;
		$general['GatewayURL'] = $xpath->query('/Configuration/General/GatewayURL')->item(0)->nodeValue;
		$general['SecURL'] = $xpath->query('/Configuration/General/SecURL')->item(0)->nodeValue;
		$general['SMTPHost'] = $xpath->query('/Configuration/General/SMTPHost')->item(0)->nodeValue;
		$general['SMTPUser'] = $xpath->query('/Configuration/General/SMTPUser')->item(0)->nodeValue;
		$general['SMTPPassword'] = $xpath->query('/Configuration/General/SMTPPassword')->item(0)->nodeValue;
		$general['SenderMail'] = $xpath->query('/Configuration/General/SenderMail')->item(0)->nodeValue;
		$general['GenerateImage'] = $xpath->query('/Configuration/General/GenerateImage')->item(0)->nodeValue;
		$general['GeneratePPX'] = $xpath->query('/Configuration/General/GeneratePPX')->item(0)->nodeValue;
		$general['GenerateAlert'] = $xpath->query('/Configuration/General/GenerateAlert')->item(0)->nodeValue;
		$general['GenerateWeb'] = $xpath->query('/Configuration/General/GenerateWeb')->item(0)->nodeValue;
			
		$ret = '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\',\'DashboardPath:PATH\',\'WebCreatorPath:PATH\',\'CubePath:PATH\',\'ReportPath:PATH\',\'WebReportPath:PATH\',\'PublishPath:PATH\',\'PublishImagePath:PATH\',\'PublishAlarmPath:PATH\',\'WebServerName\',\'PortalStartPage\',\'PDFURL\',\'ReportURL\',\'CubeURL\',\'GatewayURL\',\'SecURL\');">
				<fieldset>
					<legend><label style="font-size:1.2em;">'.$this->_getI18N("general").'</label></legend>
					<input type="hidden" name="saveMethod" value="saveGeneral">
					<table>';
		$ret .= '<tr><td class="label">'.$this->_getI18N("companyImage").'</td><td><input class="btn" type="button" value="'.$this->_getI18N('loadCompanyImage').'" onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'loadCompanyImage\');"></td></tr>';
		foreach($general as $item => $value) {
			if($value == "J" || $value == "N") {
				$ret.= '<tr><td class="label">'.$this->_getI18N($item).'</td><td><select name="'.$item.'">';
				if($value == "N") {
					$ret.= '<option value="N" selected="selected">'.$this->_getI18N('no').'</option>';
				}else{
					$ret.= '<option value="N">'.$this->_getI18N('no').'</option>';
				}
				if($value == "J") {
					$ret.= '<option value="J" selected="selected">'.$this->_getI18N('yes').'</option>';
				}else{
					$ret.= '<option value="J">'.$this->_getI18N('yes').'</option>';
				}					
				$ret.= '</select></td></tr>';
			} elseif($item == "SMTPPassword") {
				$ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="password" name="'.$item.'" value="'.$value.'"></td></tr>';
			} else {
				$ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="text" name="'.$item.'" value="'.$value.'"></td></tr>';
			}
		}
		$ret.= '	<tr><td>&nbsp;</td><td><hr><input class="btn" type="reset" value="'.$this->_getI18N('reset').'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>
					</table>
				</fieldset>
			</form>';
		return array($ret,'');
	}
	
	private function saveGeneral() {
		$args = func_get_args();
				
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$selectedGeneralNodeChilds = $projectXpath->query('/Configuration/General')->item(0)->childNodes;
		$k=0;
		for($i=0;$i<(count($args)+$k);$i++) {
			if($selectedGeneralNodeChilds->item($i)->nodeType != XML_ELEMENT_NODE){
				$k++;continue;
			}
			$oldNode = $selectedGeneralNodeChilds->item($i);
			$newNode = $oldNode->cloneNode(false);
			$newTextNode = $projectDOM->createTextNode(utf8_encode($args[($i-$k)]));
			$newNode->appendChild($newTextNode);
			$oldNode->parentNode->replaceChild($newNode,$oldNode);
		}
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function alarmConfig() {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$alarm['EmailCreation'] = $projectXpath->query('/Configuration/General/AlarmConfig/EmailCreation')->item(0)->nodeValue;
		$alarm['GIFCreation'] = $projectXpath->query('/Configuration/General/AlarmConfig/GIFCreation')->item(0)->nodeValue;
		$alarm['JPGCreation'] = $projectXpath->query('/Configuration/General/AlarmConfig/JPGCreation')->item(0)->nodeValue;
		
		$ret = '
	<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\');">
		<fieldset>
			<legend style="font-size:1.2em;">'.$this->_getI18N("alarmConfig").'</legend>
			<input type="hidden" name="saveMethod" value="saveAlarmConfig">
			<table>';
		foreach($alarm as $item => $value) {
			if($value == "J" || $value == "N") {
				$ret.= '<tr><td class="label">'.$this->_getI18N($item).'</td><td><select>';
				if($value == "N") {
					$ret.= '<option value="N" selected="selected">'.$this->_getI18N('no').'</option>';
				}else{
					$ret.= '<option value="N">'.$this->_getI18N('no').'</option>';
				}
				if($value == "J") {
					$ret.= '<option value="J" selected="selected">'.$this->_getI18N('yes').'</option>';
				}else{
					$ret.= '<option value="J">'.$this->_getI18N('yes').'</option>';
				}					
				$ret.= '</select></td></tr>';
			} else {
				$ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="text" value="'.$value.'"></td></tr>';
			}
		}
		$ret.= '<tr><td>&nbsp;</td><td><hr><input class="btn" type="reset" value="'.$this->_getI18N('reset').'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>
			</table>
		</fieldset>
	</form>';
		return array($ret,'');
	}
	
	private function saveAlarmConfig() {
		$args = func_get_args();
				
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$selectedGeneralNodeChilds = $projectXpath->query('/Configuration/General/AlarmConfig')->item(0)->childNodes;
		$k=0;
		for($i=0;$i<(count($args)+$k);$i++) {
			if($selectedGeneralNodeChilds->item($i)->nodeType != XML_ELEMENT_NODE){
				$k++;continue;
			}
			$oldTextNode = $selectedGeneralNodeChilds->item($i)->firstChild;
			$newTextNode = $projectDOM->createTextNode(utf8_encode($args[($i-$k)]));
			$selectedGeneralNodeChilds->item($i)->replaceChild($newTextNode,$oldTextNode);
		}
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function imageConfig() {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());

		$xpath = new DOMXpath($projectDOM);
		$image['GIFCreation'] = $xpath->query('/Configuration/General/ImageConfig/GIFCreation')->item(0)->nodeValue;
		$image['JPGCreation'] = $xpath->query('/Configuration/General/ImageConfig/JPGCreation')->item(0)->nodeValue;
		
		$ret = '<form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\');">
				<fieldset>
					<legend style="font-size:1.2em;">'.$this->_getI18N("imageConfig").'</legend>
					<input type="hidden" name="saveMethod" value="saveImageConfig">
					<table>';
		foreach($image as $item => $value) {
			if($value == "J" || $value == "N") {
				$ret.= '<tr><td class="label">'.$this->_getI18N($item).'</td><td><select>';
				if($value == "N") {
					$ret.= '<option value="N" selected="selected">'.$this->_getI18N('no').'</option>';
				}else{
					$ret.= '<option value="N">'.$this->_getI18N('no').'</option>';
				}
				if($value == "J") {
					$ret.= '<option value="J" selected="selected">'.$this->_getI18N('yes').'</option>';
				}else{
					$ret.= '<option value="J">'.$this->_getI18N('yes').'</option>';
				}					
				$ret.= '</select></td></tr>';
			} else {
				$ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="text" value="'.$value.'"></td></tr>';
			}
		}
		$ret.= '<tr><td>&nbsp;</td><td><hr><input class="btn" type="reset" value="'.$this->_getI18N('reset').'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>
			</table>
		</fieldset>
	</form>';
		return array($ret,'');
	}
	
	private function saveImageConfig() {
		$args = func_get_args();
			
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$selectedGeneralNodeChilds = $projectXpath->query('/Configuration/General/ImageConfig')->item(0)->childNodes;
		$k=0;
		for($i=0;$i<(count($args)+$k);$i++) {
			if($selectedGeneralNodeChilds->item($i)->nodeType != XML_ELEMENT_NODE){
				$k++;continue;
			}
			$oldTextNode = $selectedGeneralNodeChilds->item($i)->firstChild;
			$newTextNode = $projectDOM->createTextNode(utf8_encode($args[($i-$k)]));
			$selectedGeneralNodeChilds->item($i)->replaceChild($newTextNode,$oldTextNode);
		}
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().getMain();');
	}
	
	private function versionConfig($selectedSection=null) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        $Version = $projectXpath->query('/Configuration/Version')->item(0);
        $alarm['show'] = $projectXpath->query('./@show',$Version)->item(0)->nodeValue;
        $alarm['odbc'] = $projectXpath->query('./@odbc',$Version)->item(0)->nodeValue;
        $alarm['user'] = $projectXpath->query('./@user',$Version)->item(0)->nodeValue;
        $alarm['pw'] = $projectXpath->query('./@pw',$Version)->item(0)->nodeValue;
        $alarm['fp_feld'] = $projectXpath->query('./Views/@fp_feld',$Version)->item(0)->nodeValue;
        $alarm['fp_description'] = $projectXpath->query('./Views/@fp_description',$Version)->item(0)->nodeValue;
        $alarm['view_feld'] = $projectXpath->query('./Views/@view_feld',$Version)->item(0)->nodeValue;
        $alarm['view_description'] = $projectXpath->query('./Views/@view_description',$Version)->item(0)->nodeValue;
        
        $ret = '
    <form id="administrationForm" style="position:absolute;top:0px;left:0px;border:0px solid #ff0000;bottom:0px;width:400px;" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return Form.submit(this,\'MISConfigurator\',\'saveMain\');">
        <fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;top:0px;font-size:1.2em;">'.$this->_getI18N("versionConfig").'</legend>
            <input type="hidden" name="saveMethod" value="saveVersionConfig">
            <div class="treeContainer" style="top:30px;">
            <table style="position:relative;left:0px;right:0px;width:97%;">';
	        foreach($alarm as $item => $value) {
            if($value == "true" || $value == "false") {
                $ret.= '<tr><td class="label">'.$this->_getI18N($item).'</td><td><select>';
                if($value == "false") {
                    $ret.= '<option value="false" selected="selected">'.$this->_getI18N('no').'</option>';
                }else{
                    $ret.= '<option value="false">'.$this->_getI18N('no').'</option>';
                }
                if($value == "true") {
                    $ret.= '<option value="true" selected="selected">'.$this->_getI18N('yes').'</option>';
                }else{
                    $ret.= '<option value="true">'.$this->_getI18N('yes').'</option>';
                }                   
                $ret.= '</select></td></tr>';
            } elseif($item == "pw") {
                $ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="password" value="     "></td></tr>';
            } else {
            	$ret.= '<tr><td>'.$this->_getI18N($item).'</td><td><input type="text" value="'.$value.'"></td></tr>';
            }
        }
        $ret.= '<tr><td>&nbsp;</td><td><hr><input class="btn" type="reset" value="'.$this->_getI18N('reset').'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>
            </table>
            </div>
        </fieldset>
    </form>';
                $Tree = new Tree("administrationMenu");
                $ret .= ' 
    <form id="administrationForm2" name="administrationForm2" style="position:absolute;top:0px;left:405px;border:0px solid #ff0000;bottom:0px;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;">
        <fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;top:0px;"><label style="font-size:1.2em;">'.$this->_getI18N("views").'</label>   <input style="width:140px" id="createView" type="button" value="'.$this->_getI18N("createView").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createView\');"></legend>            
            <div class="treeContainer" style="top:30px;">';
        $this->versionViewMenu($Tree);
        $ret.= $Tree->__toString();
        $ret.='
            </div>
        </fieldset>
    </form>';
        return array($ret,'Tree.setToUserView(Browser.getElementById("administrationMenu"));');
	}
	
	private function saveVersionConfig($p_show,$p_odbc,$p_user,$p_pw,$p_fp_feld,$p_fp_description,$p_view_feld,$p_view_description) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        $Version = $projectXpath->query('/Configuration/Version')->item(0);
        
        $Version->setAttribute("show",$p_show);
        $Version->setAttribute("odbc",utf8_encode($p_odbc));
        $Version->setAttribute("user",utf8_encode($p_user));
        if($p_pw != "     ") $Version->setAttribute("pw",utf8_encode($p_pw));
        $Views = $projectXpath->query("./Views",$Version)->item(0);
        $Views->setAttribute("fp_feld",utf8_encode($p_fp_feld));
        $Views->setAttribute("fp_description",utf8_encode($p_fp_description));
        $Views->setAttribute("view_feld",utf8_encode($p_view_feld));
        $Views->setAttribute("view_description",utf8_encode($p_view_description));
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().__construct();');
	}
	
	private function publishes($selectedSection="") {
		$eval = "";
		if($selectedSection!="") {
		    $_SESSION["configurator"]["publishes"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["publishes"]) && isset($_SESSION["configurator"]["publishes"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["publishes"]["section"];
		}
	    $selectedSectionArr = explode("_",$selectedSection);
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        if($projectXpath->query("/Configuration/Publishes/Publish[./@ID='".$selectedSectionArr[0]."']")->length == 0) {
        	$selectedSection="";
        	$selectedSectionArr = array();
        }
        $ret = '<form id="configUsersForm" class="adminListForm" name="adminUsersForm" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;" style="position:absolute;top:0px;left:0px;border:0px solid #ff0000;bottom:0px;width:300px;">';
        $ret.= $this->configUsersForm($selectedSection);
        $ret.='</form>';

		if($selectedSection!="")$eval = 'Tree.setToUserView(Browser.getElementById("administrationMenu2"));Tree.setToUserView(Browser.getElementById("administrationMenu3"));Tree.setToUserView(Browser.getElementById("administrationMenu4"));';
        $ret .= '<form id="configReportsForm" class="adminListForm" name="adminReportsForm" style="position:absolute;top:0px;left:305px;border:0px solid #ff0000;bottom:0px;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;">';
        $selectedSection!="" ? $ret.=$this->configReportsForm($selectedSection) : false;
		$ret.='</form>';
		
        $ret .= '<form id="configScorecardsForm" class="adminListForm" name="adminScorecardsForm" style="position:absolute;padding:0px;top:0px;left:610px;border:0px solid #ff0000;bottom:51%;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;">';
        $selectedSection!="" ? $ret.= $this->configScorecardsForm($selectedSection):false;
        $ret.='</form>';
        
        $ret .= '<form id="configDashboardsForm" class="adminListForm" name="adminDashboardsForm" style="position:absolute;padding:0px;bottom:0px;top:51%;left:610px;border:0px solid #ff0000;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;">';
        $selectedSection!="" ? $ret.= $this->configDashboardsForm($selectedSection):false;
        $ret.='</form>';

		return array($ret,$eval.'Tree.setToUserView(Browser.getElementById("administrationMenu1"));');
	}
	
    private function versionViewMenu($p_node) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);      
        
        $childsHaveValue = $sectionHasValue = false;
        
        $PPList = $projectXpath->query('/Configuration/Version/Views/View');
        for($k=0;$k < $PPList->length;$k++) {
            $PP = $PPList->item($k);
            
            if($PP->nodeType != XML_ELEMENT_NODE) continue;
            $sectionID = $PP->getAttribute("ID");
            $sectionName = $PP->getElementsByTagName("Name")->item(0)->nodeValue;
            $sectionDesc = $PP->getElementsByTagName("Description")->item(0)->nodeValue;

            $newIcon = new Icon("img/view.png");
                $newLabel = new Label($newIcon,$sectionName);
            $newTreeNode = new TreeNode($newLabel,$sectionID);
            
            $newContextMenu = new ContextMenu();
            
            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'MISConfigurator.selectReport(event,Browser.getElementById("'.$sectionID.'"));CMgr.getMODEL().getRetrieveInput("MISConfigurator","editView","'.$sectionID.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteView","'.$sectionID.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newTreeNode->addContextMenu($newContextMenu);

            $p_node->appendChild($newTreeNode);
        }
    }
    
    public function configUsersForm($selectedSection) {
    	$Tree = new Tree("administrationMenu1");

		$ret='<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">';
		$ret.='<legend style="position:absolute;"><label for="createUser" style="font-size:1.2em;">'.$this->_getI18N("users").'</label>';
		if($this->isRole("master")) {
			$ret.='<input style="width:140px" id="createUser" type="button" value="'.$this->_getI18N("createUser").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createUser\',\'\');">';
		}
		$ret.='</legend><div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">';
		$usersArr = $this->getAllUsernames();
		foreach($usersArr as $username) {
			if($username == "master" && !$this->isRole("master")) continue;
			$userIcon = new Icon("img/personal.png");
			$userIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
			$userLabel = new Label($username,$userIcon);
			$userNode = new TreeNode($userLabel,$username);
            $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"user","'.$username.'");');
            $userNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"user","user,section","MISConfigurator","'.$username.'");');
            if($this->isRole("master") || $username != "admin") $userNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
            $userNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onclick",'return false;');
            $userNode->addEventListener($newEventListener);
            
            $newContextMenu = new ContextMenu();
            
            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editUser",Cookie.read("Tree_administrationMenu1_selected"));');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            if($username != "master" && $username != "admin") {
	            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
	            $newContextMenuNode = new ContextMenuNode($newLabel);
	            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteUser",Cookie.read("Tree_administrationMenu1_selected"));');
	            $newContextMenuNode->addEventListener($newEventListener);
	            $newContextMenu->appendChild($newContextMenuNode);
            }
            $newLabel = new Label(new Icon("img/package.png"),$this->_getI18N("createSection"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createSection","","'.$username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            if($this->isRole("master") || $username != "admin") $newContextMenu->appendChild($newContextMenuNode);
            
            $userNode->addContextMenu($newContextMenu);
            
			$Tree->appendChild($userNode);
			
			$MISConfig = new MISConfig();
       		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
       		$projectDOM->load($MISConfig->getConfigFile());
       		$projectXpath = new DOMXpath($projectDOM);

			$this->usersSectionMenu($userNode,"",$username,$projectDOM,$projectXpath);
		}

		$ret.= $Tree->__toString();

		$ret.='
			</div>
		</fieldset>';
		return $ret;
    }
	
    private function usersSectionMenu($p_node,$p_parentID="",$p_username,$projectDOM = null, $projectXpath = null) {
        $MISConfig = new MISConfig();
        if($projectDOM == null) {
        	$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        	$projectDOM->load($MISConfig->getConfigFile());
        }
        if($projectXpath == null) {
        	$projectXpath = new DOMXpath($projectDOM);
        }      
        
        $childsHaveValue = $sectionHasValue = false;
        
        $PPList = $projectXpath->query('/Configuration/Publishes/Publish[./@parentID = "'.$p_parentID.'" and ./@User = "'.$p_username.'"]');
        for($k=0;$k < $PPList->length;$k++) {
            $PP = $PPList->item($k);
            
            if($PP->nodeType != XML_ELEMENT_NODE) continue;
            $sectionID = $PP->getAttribute("ID");
            $sectionName = $PP->getAttribute("Name");
            $sectionHasValue = false;//($projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./../../@User = "'.$p_username.'"]')->length > 0) ? true : false;
            //if(!$sectionHasValue)$sectionHasValue = ($projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./../../@ID="'.$sectionID.'" and ./../../@Directory = "'.$p_username.'\\"]')->length > 0) ? true : false;
            //if(!$sectionHasValue)$sectionHasValue = ($projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./../../@ID="'.$sectionID.'" and ./../../@Directory = "'.$p_username.'\\"]')->length > 0) ? true : false;
            $subPublishNodeList = $projectXpath->query('/Configuration/Publishes/Publish[./@parentID = "'.$sectionID.'"]');
            
            $PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./Directory="'.utf8_encode($p_username).'\\" and ./Active="J"]');

            $newIcon = new Icon("img/package.png");
            $newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
            if($sectionHasValue) $newLabel = new Label($newIcon,"<b>".str_replace("_", " ",$sectionName)."</b>"); 
            else $newLabel = new Label($newIcon,str_replace("_", " ", $sectionName));
            $newTreeNode = new TreeNode($newLabel,$sectionID."_".$p_username);

            $newEventListener = new EventListener("onmousedown",'MISConfigurator.selectSection(event,this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);');
            $newLabel->addEventListener($newEventListener);

            $newEventListener = new EventListener("ronmousedown",'MISConfigurator.selectSection(event,this.parentNode.parentNode)');
            $newTreeNode->addEventListener($newEventListener);
            
            $newContextMenu = new ContextMenu();
            
            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editSection",Cookie.read("Tree_administrationMenu1_selected"));');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteSection",Cookie.read("Tree_administrationMenu1_selected"));');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newLabel = new Label(new Icon("img/package.png"),$this->_getI18N("createSection"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createSection","'.$sectionID.'","'.$p_username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
/*            $newLabel = new Label(new Icon("img/empty.png"),$this->_getI18N("emptySection"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","emptySection","'.$sectionID.'","'.$p_username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newLabel = new Label(new Icon("img/report.png"),$this->_getI18N("createReport"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createReport","'.$sectionID.'","'.$p_username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $newLabel = new Label(new Icon("img/scorecard.png"),$this->_getI18N("createScorecard"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createScorecard","'.$sectionID.'","'.$p_username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);

            $newLabel = new Label(new Icon("img/dashboard.png"),$this->_getI18N("createDashboard"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createDashboard","'.$sectionID.'","'.$p_username.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
*/            
            $newTreeNode->addContextMenu($newContextMenu);
            
            $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"section","'.$sectionID.'_'.$p_username.'");MISConfigurator.selectSection(event,this.parentNode.parentNode);');
            $newTreeNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"section","section,report,scorecard,dashboard","MISConfigurator","'.$sectionID.'_'.$p_username.'");');
            $newTreeNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
            $newTreeNode->addEventListener($newEventListener);

            if($subPublishNodeList->length > 0) {
                $childsHaveValue = $this->usersSectionMenu($newTreeNode,$sectionID,$p_username,$projectDOM,$projectXpath);    
            }
            $p_node->appendChild($newTreeNode);
        }
        if($childsHaveValue || $sectionHasValue) {
            return true;
        } else {
            return false;
        }
    }
	
	public function configReportsForm($selectedSection) {
		$MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        if($selectedSection!="") {
		    $_SESSION["configurator"]["publishes"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["publishes"]) && isset($_SESSION["configurator"]["publishes"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["publishes"]["section"];
		}
	    $selectedSectionArr = explode("_",$selectedSection);

		$sectionID = $selectedSectionArr[0];
		$p_username = utf8_encode($selectedSectionArr[1]);
		$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./Directory="'.$p_username.'\\" and ./Active="J"]');
		$Tree = new Tree("administrationMenu2");
	   for($i=0;$i<$PIList->length;$i++){
                
                if($PIList->item($i)->getElementsByTagname("Ansicht")->item(0)->nodeValue == "Client")
                    $newIcon = new Icon("img/report.png");
                else
                    $newIcon = new Icon("img/pdficon_small.gif");
                $newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
                $newLabel = new Label($newIcon,'<i>'.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.'</i>');
                $newReportTreeNode = new TreeNode($newLabel,$PIList->item($i)->getAttribute("ID")."_".$p_username);
                $Tree->appendChild($newReportTreeNode);
                 $newEventListener = new EventListener("onclick",'');
                //$newLabel->addEventListener($newEventListener);               
                $newEventListener = new EventListener("ondblclick",'window.location.href = "?&rc=MISConfigurator&rm=getReport&ras[]='.$PIList->item($i)->getAttribute("ID").'";');
                $newLabel->addEventListener($newEventListener);
                
                $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"report","'.$PIList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"report","","MISConfigurator","'.$PIList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
                $newReportTreeNode->addEventListener($newEventListener);
                
                $newContextMenu = new ContextMenu();
                
                $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editReport",Cookie.read("Tree_administrationMenu2_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteReport",Cookie.read("Tree_administrationMenu2_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newReportTreeNode->addContextMenu($newContextMenu);
        }
        return '<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;"><label style="font-size:1.2em;">'.$this->_getI18N("reports").'</label>   <input style="width:140px" id="createUser" type="button" value="'.$this->_getI18N("createReport").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createReport\',\''.$selectedSectionArr[0].'\',\''.$p_username.'\');"></legend>            
            <div id="configReportsContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">'
            .$Tree->__toString()
            .'</div>
        	</fieldset>';
	}
	
	public function configScorecardsForm($selectedSection) {
		
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        if($selectedSection!="") {
		    $_SESSION["configurator"]["publishes"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["publishes"]) && isset($_SESSION["configurator"]["publishes"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["publishes"]["section"];
		}
	    $selectedSectionArr = explode("_",$selectedSection);
        
        $sectionID = $selectedSectionArr[0];
        $p_username = utf8_encode($selectedSectionArr[1]);
        $PSList = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./../../@ID="'.$sectionID.'" and ./../../@Directory="'.$p_username.'\\"]');
        $Tree = new Tree("administrationMenu3");
        
	   for($i=0;$i<$PSList->length;$i++){
                $newIcon = new Icon("img/scorecard.png");
                $newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
                $newLabel = new Label($newIcon,'<i>'.$PSList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.'</i>');
                $newReportTreeNode = new TreeNode($newLabel,$PSList->item($i)->getAttribute("ID")."_".$p_username);
                $Tree->appendChild($newReportTreeNode);

                $newEventListener = new EventListener("onclick",'');
                $newLabel->addEventListener($newEventListener);                
                
                $newEventListener = new EventListener("ondblclick",'window.location.href = "?&rc=MISConfigurator&rm=getScorecard&ras[]='.$PSList->item($i)->getAttribute("ID").'";');
                $newLabel->addEventListener($newEventListener);
                
                $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"scorecard","'.$PSList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"scorecard","","MISConfigurator","'.$PSList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
                $newReportTreeNode->addEventListener($newEventListener);
                
                $newContextMenu = new ContextMenu();
                
                $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editScorecard",Cookie.read("Tree_administrationMenu3_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteScorecard",Cookie.read("Tree_administrationMenu3_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newReportTreeNode->addContextMenu($newContextMenu);
            }
        return '<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;"><label style="font-size:1.2em;">'.$this->_getI18N("scorecards").'</label>   <input style="width:140px" id="createUser" type="button" value="'.$this->_getI18N("createScorecard").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createScorecard\',\''.$selectedSectionArr[0].'\',\''.$p_username.'\');"></legend>
            <div id="configScorecardsForm"  onscroll="Tree.scrolling(this);"class="treeContainer" style="top:30px;">'
        	.$Tree->__toString()
        	.'</div></fieldset>';
	}
	
    public function configDashboardsForm($selectedSection) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        if($selectedSection!="") {
		    $_SESSION["configurator"]["publishes"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["publishes"]) && isset($_SESSION["configurator"]["publishes"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["publishes"]["section"];
		}
	    $selectedSectionArr = explode("_",$selectedSection);
        
        $sectionID = $selectedSectionArr[0];
        $p_username = utf8_encode($selectedSectionArr[1]);
        $PSList = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./../../@ID="'.$sectionID.'" and ./../../@Directory="'.$p_username.'\\"]');
        $Tree = new Tree("administrationMenu4");
        
       for($i=0;$i<$PSList->length;$i++){
                $newIcon = new Icon("img/dashboard.png");
                $newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
                $newLabel = new Label($newIcon,'<i>'.$PSList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.'</i>');
                $newReportTreeNode = new TreeNode($newLabel,$PSList->item($i)->getAttribute("ID")."_".$p_username);
                $Tree->appendChild($newReportTreeNode);

                $newEventListener = new EventListener("onclick",'');
                $newLabel->addEventListener($newEventListener);                
                
                $newEventListener = new EventListener("ondblclick",'window.location.href = "?&rc=MISConfigurator&rm=getDashboard&ras[]='.$PSList->item($i)->getAttribute("ID").'";');
                $newLabel->addEventListener($newEventListener);
                
                $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"dashboard","'.$PSList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"dashboard","","MISConfigurator","'.$PSList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
                $newReportTreeNode->addEventListener($newEventListener);
                
                $newContextMenu = new ContextMenu();
                
                $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editDashboard",Cookie.read("Tree_administrationMenu4_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteDashboard",Cookie.read("Tree_administrationMenu4_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newReportTreeNode->addContextMenu($newContextMenu);
            }
        return '
        <fieldset id="configDashboardsForm" style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;"><label style="font-size:1.2em;">'.$this->_getI18N("dashboards").'</label>   <input style="width:140px" id="createUser" type="button" value="'.$this->_getI18N("createDashboard").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createDashboard\',\''.$selectedSectionArr[0].'\',\''.$p_username.'\');"></legend>
            <div onscroll="Tree.scrolling(this);" class="treeContainer" style="top:30px;">'
        	.$Tree->__toString()
        	.'</div></fieldset>';    	
    }
	
	private function emailSetup($selectedSection="") {
       
		if($selectedSection!="") {
		    $_SESSION["configurator"]["emailSetup"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["emailSetup"]) && isset($_SESSION["configurator"]["emailSetup"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["emailSetup"]["section"];
		}

        $ret = '<form id="configEmailUsersForm" class="adminListForm" name="adminUsersForm" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;" style="position:absolute;top:0px;left:0px;border:0px solid #ff0000;bottom:0px;width:300px;">';
        $ret.= $this->configEmailUsersForm($selectedSection);
        $ret.='</form>';
        $eval ="";
        $ret .= '<form id="configEmailReportsForm" class="adminListForm" name="adminReportsForm" style="position:absolute;top:0px;left:305px;border:0px solid #ff0000;bottom:0px;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;">';
        $selectedSection!="" ? $ret.=$this->configEmailReportsForm($selectedSection) : false;
        $selectedSection!="" ? $eval='Tree.setToUserView(Browser.getElementById("administrationMenu9"));' : false;
		$ret.='</form>';
        return array($ret,'Tree.setToUserView(Browser.getElementById("administrationMenu8"));'.$eval);
	}
	
	public function configEmailUsersForm($selectedSection) {
		$MISConfig = new MISConfig();
        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $ProjectDOM->load($MISConfig->getConfigFile());
        $ProjectXpath = new DOMXpath($ProjectDOM);
		
		$ret='<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">';
		$ret.='<legend style="position:absolute;"><label for="createUser" style="font-size:1.2em;">'.$this->_getI18N("email").'</label>';
		if($this->isRole("master")) {
			$ret.='<input style="width:140px" id="createUser" type="button" value="'.$this->_getI18N("createEmail").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createEmailUser\',\'\');">';
		}
		$ret.='</legend><div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">';

        $Tree = new Tree("administrationMenu8");
        
        $emailArr = array();
        
        $EmailList = $ProjectXpath->query("/Configuration/Emails/Email");
        for($i=0;$i<$EmailList->length;$i++){
        	if(!array_key_exists(trim($EmailList->item($i)->nodeValue), $emailArr)) {
        		$emailArr[trim($EmailList->item($i)->nodeValue)] = array();
        	}
        }
        
        foreach($emailArr as $email => $Images){
        
            $emailIcon = new Icon("img/package.png");
            $emailIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
            
            $emailLabel = new Label($emailIcon,trim($email));
            $newEventListener = new EventListener("onmousedown",'CMgr.getMODEL().getMain("MISConfigurator","emailSetup","'.$email.'");');
            $emailLabel->addEventListener($newEventListener);
            $emailNode = new TreeNode($emailLabel,trim($email));
            
            $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"emailUser","'.$email.'");');
            $emailNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"emailUser","emailUser,emailReport","MISConfigurator","'.$email.'");');
            $emailNode->addEventListener($newEventListener);
            $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
            $emailNode->addEventListener($newEventListener);
            
            //$app = Core::getApp($app);
            
            $newContextMenu = new ContextMenu();
            
            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editEmailUser","'.$email.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
                
            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteEmailUser","'.$email.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $emailNode->addContextMenu($newContextMenu);
            $Tree->appendChild($emailNode);

        }
        $ret.= $Tree->__toString();

		$ret.='
			</div>
		</fieldset>';
		return $ret;		
	}
	
	public function configEmailReportsForm($selectedSection) {
				$MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
	    $ImageList = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active='J' and ./SendEmail='J' and ./Email!='']");
        
        $Tree = new Tree("administrationMenu9");

        
        $emailArr = array();
        for($i=0;$i < $ImageList->length;$i++) {
        	$Image = $ImageList->item($i);
        	$ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
            
            foreach($ImageEmailArr as $email) {
	            if(!array_key_exists(trim($email), $emailArr)) {
	            	$emailArr[trim($email)] = array();
	            }
	            $emailArr[trim($email)][trim($Image->getElementsByTagName("Name")->item(0)->nodeValue)] = $Image->getAttribute("ID");
            }
        }
        if($projectXpath->query("/Configuration/Emails/Email[.='".$selectedSection."']")->length == 0)return;
		$ret='<fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">';
		$ret.='<legend style="position:absolute;"><label for="createEmailReport" style="font-size:1.2em;">'.$this->_getI18N("reports").'   <input style="width:140px" id="createEmailReport" type="button" value="'.$this->_getI18N("createReport").'"  onclick="CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'createEmailReport\',\''.$selectedSection.'\');"></label>';
		$ret.='</legend><div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">';


        foreach($emailArr as $email => $Images){
        	if($selectedSection!=$email)continue;
            foreach($Images as $imageName => $ID){
	            $imageIcon = new Icon("img/pdficon_small.gif");
	            $imageIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
	            
	            $imageLabel = new Label($imageIcon,$imageName);
	            $newEventListener = new EventListener("ondblclick",'window.location.href = "?&rc=MISConfigurator&rm=getReport&ras[]='.$ID.'";');
	            $imageLabel->addEventListener($newEventListener);
	            $imageNode = new TreeNode($imageLabel,$ID);
	            $Tree->appendChild($imageNode);
	            
	            $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"emailReport","'.$ID.'");');
                $imageNode->addEventListener($newEventListener);
                //$newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"","","MISConfigurator","'.$PIList->item($i)->getAttribute("ID").'");');
                //$imageNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
                $imageNode->addEventListener($newEventListener);
	            
	            $newContextMenu = new ContextMenu();
	            
	            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
	            $newContextMenuNode = new ContextMenuNode($newLabel);
	            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createEmailReportForm2","'.$email.'",Cookie.read("Tree_administrationMenu9_selected"));');
	            $newContextMenuNode->addEventListener($newEventListener);
	            $newContextMenu->appendChild($newContextMenuNode);
	                
	            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
	            $newContextMenuNode = new ContextMenuNode($newLabel);
	            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteEmailReport",Cookie.read("Tree_administrationMenu9_selected"));');
	            $newContextMenuNode->addEventListener($newEventListener);
	            $newContextMenu->appendChild($newContextMenuNode);
	            
	            $imageNode->addContextMenu($newContextMenu);
            }
        }
        $ret.= $Tree->__toString();

		$ret.='
			</div>
		</fieldset>';
		return $ret;
	}
	
	private function createEmailUser(){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'email\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('createEmail').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateEmailUser">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createUserInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('email').':</label></td><td><input id="inp_name" name="email" type="text" value=""></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateEmailUser($p_email) {
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$ProjectXpath = new DOMXpath($projectDOM);
		
		$emailExists = $ProjectXpath->query("/Configuration/Emails/Email[. = '".$p_email."']")->length > 0 ? true : false;
		if($emailExists) return array('alert("'.$this->_getI18N("emailAlreadyExists").'")');
		$Emails = $ProjectXpath->query("/Configuration/Emails")->item(0);
		$EmailList = $ProjectXpath->query("/Configuration/Emails/Email");
		$MISConfig->setNodeValue("Email", trim($p_email), $projectDOM, $Emails, $EmailList->length);

		$projectDOM->save($MISConfig->getConfigFile());

		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function editEmailUser($ID){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'email\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('editEmail').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveEditEmailUser">';
		$ret.= '<input type="hidden" name="ID" value="'.$ID.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editUserInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('email').':</label></td><td><input id="inp_name" name="email" type="text" value="'.$ID.'"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveEditEmailUser($ID,$p_email) {
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$ProjectDOM->load($MISConfig->getConfigFile());
		$ProjectXpath = new DOMXpath($ProjectDOM);
		
		$emailExists = $ProjectXpath->query("/Configuration/Emails/Email[. = '".$p_email."']")->length > 0 ? true : false;
		if($emailExists) return array('alert("'.$this->_getI18N("emailAlreadyExists").'")');

		$Email = $ProjectXpath->query("/Configuration/Emails/Email[. = '".$ID."']")->item(0)->nodeValue =trim($p_email);

		$ImageList = $ProjectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active='J' and ./SendEmail='J' and ./Email!='']");
        
        $emailArr = array();
        for($i=0;$i < $ImageList->length;$i++) {
        	$Image = $ImageList->item($i);
        	$ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
            
            for($j=0;$j<count($ImageEmailArr);$j++) {
            	$email = trim($ImageEmailArr[$j]);
	            if($email == $ID) $ImageEmailArr[$j] = trim($p_email);
	            else $ImageEmailArr[$j] = $email;
            }
            $Image->getElementsByTagName("Email")->item(0)->nodeValue = implode(";", $ImageEmailArr);            
        }
		
		$ProjectDOM->save($MISConfig->getConfigFile());

		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function deleteEmailUser($ID){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('deleteEmail').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteEmailUser">';
		$ret.= '<input type="hidden" name="ID" value="'.$ID.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteEmailUserInfoMsg1')." ".$ID." ".$this->_getI18N('deleteEmailUserInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteEmailUser($ID) {
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$ProjectDOM->load($MISConfig->getConfigFile());
		$ProjectXpath = new DOMXpath($ProjectDOM);
		
		$Emails = $ProjectXpath->query("/Configuration/Emails")->item(0);
		$Email = $ProjectXpath->query("/Configuration/Emails/Email[. = '".$ID."']")->item(0);

		$ImageList = $ProjectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active='J' and ./Email!='']");
        
        for($i=0;$i < $ImageList->length;$i++) {
        	$Image = $ImageList->item($i);
        	$ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
            $NewImageEmailArr = array();
            for($j=0;$j<count($ImageEmailArr);$j++) {
            	$email = trim($ImageEmailArr[$j]);
	            if($email != $ID) $NewImageEmailArr[] = trim($email);
	     
            }
            $Image->getElementsByTagName("Email")->item(0)->nodeValue = implode(";", $NewImageEmailArr);
            if(count($NewImageEmailArr)==0)$Image->getElementsByTagName("SendEmail")->item(0)->nodeValue = "N";            
        }
		$Emails->removeChild($Email);		
		$ProjectDOM->save($MISConfig->getConfigFile());

		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function createEmailReport($ID){
		$eval = "";
	 	if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["createEmailReport"]) && isset($_SESSION["configurator"]["createEmailReport"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["createEmailReport"]["section"];
		}else{
			$selectedSection = "";
		}
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);

        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return MISConfigurator.submitCreateEmailReport(this);" style="position:absolute;top:0px;left:50%;border:0px solid #ff0000;bottom:0px;width:0%;padding:5px;">';
        $ret.= '<input type="hidden" name="func" value="saveCreateEmailReportForm"><input type="hidden" id="ID" name="ID" value="'.$ID.'"><input type="hidden" id="createEmailReportSelected" name="createEmailReportSelected" value=""><div id="emailUsersForm" name="adminUsersForm" encoding="utf-8" action="" target="_self" method="post" class="" onsubmit="return false;" style="position:absolute;top:0px;left:-300px;border:0px solid #ff0000;bottom:0px;width:300px;">';
        $ret.= $this->createEmailReportUsersForm($ID);
        $ret.='</div>';

		if($selectedSection!="")$eval = 'Tree.setToUserView(Browser.getElementById("administrationMenu11"));Tree.setToUserView(Browser.getElementById("administrationMenu3"));Tree.setToUserView(Browser.getElementById("administrationMenu4"));';
        $ret .= '<div id="emailReportsForm" name="adminReportsForm" style="position:absolute;top:0px;left:5px;border:0px solid #ff0000;bottom:0px;width:300px;" encoding="utf-8" action="" target="_self" method="post" class="">';
        $selectedSection!="" ? $ret.=$this->createEmailReportsForm($selectedSection) : false;
		$ret.='</div>';
		$ret.='</form>';

		return array($ret,$eval.'Tree.setToUserView(Browser.getElementById("administrationMenu10"));');

	}
	
	private function saveCreateEmailReport($p_email) {
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$ProjectXpath = new DOMXpath($projectDOM);
		
		$Emails = $ProjectXpath->query("/Configuration/Emails")->item(0);
		$EmailList = $ProjectXpath->query("/Configuration/Emails/Email");
		$MISConfig->setNodeValue("Email", trim($p_email), $projectDOM, $Emails, $EmailList->length);

		$projectDOM->save($MISConfig->getConfigFile());

		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	public function createEmailReportUsersForm() {
    	$Tree = new Tree("administrationMenu10");

		$ret='<div style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">';
		$ret.='<legend style="position:absolute;"><label for="createUser" style="font-size:1.2em;">'.$this->_getI18N("users").'</label>';
		$ret.='</legend><div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;bottom:30px;">';
		$usersArr = $this->getAllUsernames();
		foreach($usersArr as $username) {
			if($username == "master" && !$this->isRole("master")) continue;
			$userIcon = new Icon("img/personal.png");
			$userLabel = new Label($username,$userIcon);
			$userNode = new TreeNode($userLabel,$username);
            
			$Tree->appendChild($userNode);
			
			$MISConfig = new MISConfig();
       		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
       		$projectDOM->load($MISConfig->getConfigFile());
       		$projectXpath = new DOMXpath($projectDOM);

			$this->emailUsersSectionMenu($userNode,"",$username,$projectDOM,$projectXpath);
		}

		$ret.= $Tree->__toString();

		$ret.='
			</div><input type="button" value="Abbrechen" onclick="CMgr.getMODEL().abortRetrieveInput();" style="position:absolute;left:0px;width:100%;bottom:0px;">
		</div>';
		return $ret;	
	}
	
    private function emailUsersSectionMenu($p_node,$p_parentID="",$p_username,$projectDOM = null, $projectXpath = null) {
        $MISConfig = new MISConfig();
        if($projectDOM == null) {
        	$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        	$projectDOM->load($MISConfig->getConfigFile());
        }
        if($projectXpath == null) {
        	$projectXpath = new DOMXpath($projectDOM);
        }      
        
        $childsHaveValue = $sectionHasValue = false;
        
        $PPList = $projectXpath->query('/Configuration/Publishes/Publish[./@parentID = "'.$p_parentID.'" and ./@User = "'.$p_username.'"]');
        for($k=0;$k < $PPList->length;$k++) {
            $PP = $PPList->item($k);
            
            if($PP->nodeType != XML_ELEMENT_NODE) continue;
            $sectionID = $PP->getAttribute("ID");
            $sectionName = $PP->getAttribute("Name");
            $sectionHasValue = false;//($projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./../../@User = "'.$p_username.'"]')->length > 0) ? true : false;
            //if(!$sectionHasValue)$sectionHasValue = ($projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./../../@ID="'.$sectionID.'" and ./../../@Directory = "'.$p_username.'\\"]')->length > 0) ? true : false;
            //if(!$sectionHasValue)$sectionHasValue = ($projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./../../@ID="'.$sectionID.'" and ./../../@Directory = "'.$p_username.'\\"]')->length > 0) ? true : false;
            $subPublishNodeList = $projectXpath->query('/Configuration/Publishes/Publish[./@parentID = "'.$sectionID.'"]');
            
            $PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./Directory="'.utf8_encode($p_username).'\\" and ./Active="J"]');

            $newIcon = new Icon("img/package.png");
            //$newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
            if($sectionHasValue) $newLabel = new Label($newIcon,"<b>".str_replace("_", " ",$sectionName)."</b>"); 
            else $newLabel = new Label($newIcon,str_replace("_", " ", $sectionName));
            $newTreeNode = new TreeNode($newLabel,$sectionID."_".$p_username);

            $newEventListener = new EventListener("onmousedown",'MISConfigurator.selectEmailSection(event,this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode);');
            $newLabel->addEventListener($newEventListener);
            
            if($subPublishNodeList->length > 0) {
                $childsHaveValue = $this->emailUsersSectionMenu($newTreeNode,$sectionID,$p_username,$projectDOM,$projectXpath);    
            }
            $p_node->appendChild($newTreeNode);
        }
        if($childsHaveValue || $sectionHasValue) {
            return true;
        } else {
            return false;
        }
    }
	
	public function createEmailReportsForm($selectedSection) {
		$MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        if($selectedSection!="") {
		    $_SESSION["configurator"]["createEmailReport"]["section"] = $selectedSection;
		}else if(isset($_SESSION["configurator"]) && isset($_SESSION["configurator"]["createEmailReport"]) && isset($_SESSION["configurator"]["createEmailReport"]["section"])){
		    $selectedSection = $_SESSION["configurator"]["createEmailReport"]["section"];
		}
	    $selectedSectionArr = explode("_",$selectedSection);

		$sectionID = $selectedSectionArr[0];
		$p_username = utf8_encode($selectedSectionArr[1]);
		$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$sectionID.'" and ./Directory="'.$p_username.'\\" and ./Active="J"]');
		$Tree = new Tree("administrationMenu11");
	   for($i=0;$i<$PIList->length;$i++){
                
                if($PIList->item($i)->getElementsByTagname("Ansicht")->item(0)->nodeValue == "Client")
                    $newIcon = new Icon("img/report.png");
                else
                    $newIcon = new Icon("img/pdficon_small.gif");
                $newIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
                $newLabel = new Label($newIcon,'<i>'.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.'</i>');
                $newReportTreeNode = new TreeNode($newLabel,$PIList->item($i)->getAttribute("ID")."_".$p_username);
                $Tree->appendChild($newReportTreeNode);
                 $newEventListener = new EventListener("onclick",'');
                //$newLabel->addEventListener($newEventListener);               
                $newEventListener = new EventListener("ondblclick",'window.location.href = "?&rc=MISConfigurator&rm=getReport&ras[]='.$PIList->item($i)->getAttribute("ID").'";');
                $newLabel->addEventListener($newEventListener);
                
                $newEventListener = new EventListener("onmousedown",'DragAndDrop.startDrag(event,this,"report","'.$PIList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmousemove",'DragAndDrop.setDrop(event,this,"report","","MISConfigurator","'.$PIList->item($i)->getAttribute("ID").'_'.$p_username.'");');
                $newReportTreeNode->addEventListener($newEventListener);
                $newEventListener = new EventListener("onmouseout","DragAndDrop.clearDrop();");
                $newReportTreeNode->addEventListener($newEventListener);
                
                $newContextMenu = new ContextMenu();
                
                $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editReport",Cookie.read("Tree_administrationMenu11_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
                $newContextMenuNode = new ContextMenuNode($newLabel);
                $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteReport",Cookie.read("Tree_administrationMenu11_selected"));');
                $newContextMenuNode->addEventListener($newEventListener);
                $newContextMenu->appendChild($newContextMenuNode);
                
                $newReportTreeNode->addContextMenu($newContextMenu);
        }
        return '<div style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;"><label style="font-size:1.2em;">'.$this->_getI18N("reports").'</label></legend>            
            <div id="configReportsContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;bottom:30px;">'
            .$Tree->__toString()
            .'</div><input type="submit" value="Weiter" style="position:absolute;left:0px;width:100%;bottom:0px;">
        	</div>';
	}
	
	private function saveCreateEmailReportForm($ID,$IDs) {
		return array('CMgr.getMODEL().getRetrieveInput("MISConfigurator","createEmailReportForm2","'.$ID.'","'.$IDs.'");');
	}
	
	private function createEmailReportForm2($p_email,$p_ID) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		$ID = explode("_",$IDArr[0]);
		$ID = $ID[0];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
		
		//$PIs = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'"]');
		$PI = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="J"]')->item(0);

		if($PI->getElementsByTagName("Email")->item(0)->nodeValue != "" && $PI->getElementsByTagName("SendEmail")->item(0)->nodeValue == "J"){
			$emailArr = explode(";",$PI->getElementsByTagName("Email")->item(0)->nodeValue);
		}else{
			$emailArr = array();
		}
		
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/report.png">'.$PI->getElementsByTagName("Name")->item(0)->nodeValue.' '.$this->_getI18N('sendSettings').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateEmailReportForm2"><input type="hidden" name="ID" value="'.$p_ID.'"><input type="hidden" name="emailID" value="'.$p_email.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createEmailReportInfoMsg').'<hr></td></tr>';
		if(count($emailArr)>0 && !(count($emailArr)==1 && in_array($p_email,$emailArr) )) {
					$ret.= '<tr><td colspan="2" style="color:#ff0000;"><img src="img/warning.png">'.implode(", ",$emailArr)." ".$this->_getI18N('createEmailReportWarningMsg').'<hr></td></tr>';
		}
		
		$ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('pprName').':</label></td><td>'.$PI->getElementsByTagName("Report")->item(0)->nodeValue.'</td></tr>';
		
		$ret.= '<tr><td><label for="inp_imageGenerate">'.$this->_getI18N('imageGenerate').':</label></td><td><label for="inp_gifGenerate1">'.$this->_getI18N('GIF').'</label>';
			$ret.= '<input class="btn" type="checkbox" id="inp_gifGenerate1" name="gifGenerate"';
				if($PI->getElementsByTagName("GIFGenerate")->item(0)->nodeValue == "J") $ret.= ' checked="checked"';
			$ret.= ' value="GIF">/';
			$ret.= '<input class="btn" type="checkbox" id="inp_jpgGenerate1" name="jpgGenerate"';
				if($PI->getElementsByTagName("JPGGenerate")->item(0)->nodeValue == "J") $ret.= ' checked="checked"';
			$ret.= ' value="JPG"><label for="inp_jpgGenerate1">'.$this->_getI18N('JPG').'</label></td></tr>';
		$ret.= '<tr><td><label for="inp_imageType1">'.$this->_getI18N('imageType').':</label></td><td>';
			$ret.= '<select id="inp_imageType1" name="imageType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($key == $PI->getElementsByTagName("ImageType")->item(0)->nodeValue) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageLayer1">'.$this->_getI18N('imageLayer').':</label></td><td><input id="inp_imageLayer1" name="imageLayer1" type="text" value="';
			$ret.= $PI->getElementsByTagName("ImageLayer")->item(0)->nodeValue;
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_pdfGenerate1">'.$this->_getI18N('pdfGenerate').':</label></td><td>';
			$ret.= '<select id="inp_pdfGenerate1" name="pdfGenerate1"><option value="N">'.$this->_getI18N("no").'</option>';
			if($PI->getElementsByTagName("PDFGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
			else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfType1">'.$this->_getI18N('pdfType').':</label></td><td>';
			$ret.= '<select id="inp_pdfType1" name="pdfType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($PI->getElementsByTagName("PDFImageType")->item(0)->nodeValue == $key) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfLayer1">'.$this->_getI18N('pdfLayer').':</label></td><td><input id="inp_pdfLayer1" name="pdfLayer1" type="text" value="';
			$ret.= $PI->getElementsByTagName("PDFImageLayer")->item(0)->nodeValue;
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_xlsGenerate1">'.$this->_getI18N('xlsGenerate').':</label></td><td>';
			$ret.= '<select id="inp_xlsGenerate1" name="xlsGenerate1"><option value="N">'.$this->_getI18N("no").'</option>';
				if($PI->getElementsByTagName("XLSGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
				else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_sendEmail">'.$this->_getI18N('sendEmail').':</label></td><td>';
			$ret.= '<select id="inp_sendEmail" name="sendEmail"><option value="N">'.$this->_getI18N("no").'</option>';
			$ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</selected>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_email">'.$this->_getI18N('email').':</label></td><td><input id="inp_email" name="email" type="text" value="';

		if(in_array($p_email,$emailArr)) {
			$ret.= $PI->getElementsByTagName("Email")->item(0)->nodeValue;
		}else{
			$emailArr[] = $p_email;
			$ret.= implode(";",$emailArr);
		}
		$ret.= '"></td></tr>';
		
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateEmailReportForm2($p_ID,$p_emailID,$p_gifGenerate,$p_jpgGenerate,$p_imageType1,$p_imageLayer1,$p_pdfGenerate1,$p_pdfType1,$p_pdfLayer1,$p_xlsGenerate1,$p_sendEmail,$p_email) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		$ID = explode("_",array_shift($IDArr));
		$ID = $ID[0];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'"]');
		$PI = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="J"]')->item(0);
		
		$p_gifGenerate = ($p_gifGenerate == "true") ? "J" : "N";
		$p_jpgGenerate = ($p_jpgGenerate == "true") ? "J" : "N";		

		$MISConfig->setNodeValue("GIFGenerate",$p_gifGenerate,$projectDOM,$PI);
		$MISConfig->setNodeValue("JPGGenerate",$p_jpgGenerate,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFGenerate",$p_pdfGenerate1,$projectDOM,$PI);
		$MISConfig->setNodeValue("XLSGenerate",$p_xlsGenerate1,$projectDOM,$PI);
		$MISConfig->setNodeValue("SendEmail",$p_sendEmail,$projectDOM,$PI);
		$MISConfig->setNodeValue("ImageType",$p_imageType1,$projectDOM,$PI);
		$MISConfig->setNodeValue("ImageLayer",$p_imageLayer1,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFImageType",$p_pdfType1,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFImageLayer",$p_pdfLayer1,$projectDOM,$PI);
		$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PI);

		$projectDOM->save($MISConfig->getConfigFile());
		$this->_registerEmails($p_email);
		if(count($IDArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","createEmailReportForm2","'.$p_emailID.'","'.implode("|",$IDArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().__construct();';
		}
		return array($eval);
	}
	
	private function deleteEmailReport($p_ID) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		$emailNames = array();
		foreach($IDArr as $ID) {
			$emailNames[] = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image/Name[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
		}
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/report.png">'.$this->_getI18N('deleteEmailReport').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteEmailReport"><input type="hidden" name="ID" value="'.$p_ID.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteEmailReportInfoMsg1').' <i>'.implode(",",$emailNames).'</i> '.$this->_getI18N('deleteEmailReportInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteEmailReport($p_ID) {
		$MISConfig = new MISConfig();
		
		$IDArr = explode("|",$p_ID);

		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		foreach($IDArr as $ID) {
			$Image = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="J"]')->item(0);
			$newEmailArr = array();
			$emailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
			foreach($emailArr as $email) {
				if(trim($email) == $_SESSION["configurator"]["emailSetup"]["section"]) continue;
				$newEmailArr[] = trim($email);
			}
			$Image->getElementsByTagName("Email")->item(0)->nodeValue = implode(";",$newEmailArr);
		}
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().abortRetrieveInput();CMgr.getMODEL().getMain("MISConfigurator","emailSetup","'.utf8_encode($_SESSION["configurator"]["emailSetup"]["section"]).'");');
	}
	
	private function emailExport() {
		$ret = "";
		if($this->isRole("admin")){
			$ret = '<form action="?&rc=MISConfigurator&rm=saveRetrieveInput" enctype="multipart/form-data" encoding="utf-8" method="post" target="">';
			//$ret.= '<fieldset>';
			//$ret.= '<legend>'.$this->_getI18N('emailImport').'</legend>';
			$ret.= '<input type="hidden" name="ras[0]" value="saveEmailExport">';
			$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('emailExportInfoMsg').'</td></tr>';
			$ret.= '<tr><td colspan="2"><hr><input class="btn" type="submit" value="'.$this->_getI18N('export').'"></td></tr>';
			$ret.= '</table>';
			//$ret.= '</fieldset>';
			$ret.= '</form>';
		}
		return array($ret,'');
	}
	
	private function saveEmailExport() {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$configName = $projectXpath->query("/Configuration")->item(0)->getAttribute("Name");
		if($this->getAuth()) {
			if($this->isRole("admin")) {
				$filepath = $MISConfig->getTempFilesPath().'email.csv';
				$list[] = array($configName,basename($MISConfig->getConfigFile()),gmdate("d.m.Y H:i:s") );
				$list[] = array();
				$list[] = array();
				$list[] = array("E-Mail", "Bericht", "Benutzer", "PDF Layer");
				$list[] = array();
				$ImageList = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active='J' and ./SendEmail='J' and ./Email!='']");

		        $emailArr = array();
		        for($i=0;$i < $ImageList->length;$i++) {
		        	$Image = $ImageList->item($i);
		        	$ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
		            
		            foreach($ImageEmailArr as $email) {
			            if(!array_key_exists(trim($email), $emailArr)) {
			            	$emailArr[trim($email)] = array();
			            }
			            $emailArr[trim($email)][trim($Image->getElementsByTagName("Name")->item(0)->nodeValue)] = array($Image->getElementsByTagName("Directory")->item(0)->nodeValue,$Image->getElementsByTagName("PDFImageLayer")->item(0)->nodeValue);
		            }
		        }
		        $currentEmail="";
			    foreach($emailArr as $email => $Images){
		            foreach($Images as $imageName => $ID){
		            	if($currentEmail != $email){
							$list[] = array($email,$imageName,$ID[0],$ID[1]);
		            	}else{
		            		$list[] = array("",$imageName,$ID[0],$ID[1]);
		            	}
		            	$currentEmail = $email;
		            }
		        }
				
				$fp = fopen($filepath, 'w');
				
				foreach ($list as $fields) {
				    fputcsv($fp, $fields,";");
				}
				
				fclose($fp);

				header("Pragma: public");
				header("Expires: 0");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Cache-Control: private",false);
				header("Content-Type: application/csv");
				header("Content-Disposition: attachment; filename=\"".basename($filepath)."\";");
				header("Content-Transfer-Encoding: binary");
				header("Content-Length: ".@filesize($filepath));
				readfile($filepath);
			}
		}
	}
	
	private function languages() {
        $Tree = new Tree("administrationMenu7");
        $ret = '
    <form id="administrationForm" name="administrationForm" encoding="utf-8" action="" target="_self" method="post" class="adminListForm" onsubmit="return false;" style="position:absolute;top:0px;left:0px;border:0px solid #ff0000;bottom:0px;width:300px;">
        <fieldset style="position:absolute;left:0px;top:0px;overflow:hidden;right:0px;;bottom:0px;padding:0px;margin:0px;">
            <legend style="position:absolute;" style="font-size:1.2em;"><label for="createModule" style="font-size:1.2em;">'.$this->_getI18N("applications").'</label></legend>
            <div id="configUsersContainer" class="treeContainer" onscroll="Tree.scrolling(this);" style="top:30px;">';
        $appsArr = Core::getApps();
        foreach($appsArr as $app) {
            $appIcon = new Icon("img/package.png");
            $appIcon->addEventListener(new EventListener("onclick",'ContextMenu.leftClick();ContextMenu.show(this.parentNode.parentNode.parentNode.parentNode.parentNode,event);'));
            
            $appLabel = new Label($appIcon,$app);
            $appNode = new TreeNode($appLabel,$app);
            
            //$app = Core::getApp($app);
            
            $newContextMenu = new ContextMenu();
            
            $newLabel = new Label(new Icon("img/edit.png"),$this->_getI18N("edit"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editLanguage","'.$app.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
                
            $newLabel = new Label(new Icon("img/delete.png"),$this->_getI18N("delete"));
            $newContextMenuNode = new ContextMenuNode($newLabel);
            $newEventListener = new EventListener("onclick",'CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteLanguage","'.$app.'");');
            $newContextMenuNode->addEventListener($newEventListener);
            $newContextMenu->appendChild($newContextMenuNode);
            
            $appNode->addContextMenu($newContextMenu);
            $Tree->appendChild($appNode);
        }
        $ret.= $Tree->__toString();
        $ret.='
            </div>
        </fieldset>
    </form>';
        return array($ret,'Tree.setToUserView(Browser.getElementById("administrationMenu"));');
	}
	
	public function getRetrieveInput() {
		$ret = "";
		if($this->getAuth()) {
			if($this->isRole("admin")) {
				global $Core;
				
				$p_args = func_get_args();
				$p_section = array_shift($p_args);
							
				$eval = "";
				$arr = call_user_func_array(array($this, $p_section), $p_args);
				$ret.= $arr[0];$eval.=$arr[1];

				return array($ret,$eval);
			} else {
				return array('','CMgr.getMODEL().__construct();');
			}
		} else {
			return array('','CMgr.getMODEL().__construct();');	
		}
	}
	
	public function exportConfig($p_configFile) {
		$MISConfig = new MISConfig();
		if($this->getAuth()) {
			if($this->isRole("master")) {
				$filepath = $MISConfig->getConfigFilesPath().$p_configFile;
				header("Pragma: public");
				header("Expires: 0");
				header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				header("Cache-Control: private",false);
				header("Content-Type: application/xml");
				header("Content-Disposition: attachment; filename=\"".basename($filepath)."\";");
				header("Content-Transfer-Encoding: binary");
				/*header("Content-Length: ".@filesize($filepath));*/
				//$fn = fopen($filepath,"r");
     			$content = file_get_contents($filepath);
      			print mb_convert_encoding($content, 'ISO-8859-1', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true)); 

			}
		}
	}
	
	public function saveRetrieveInput() {
		if($this->getAuth()) {
			if($this->isRole("admin")) {
				global $Core;
				
				$p_args = func_get_args();
				$p_method = array_shift($p_args);
				//ATTENTION CLIENT CAN CALL PRIVATE FUNCTIONS! MUST VERIFY THAT USER IS MASTER
				$ret = call_user_func_array(array($this, $p_method), $p_args);
				
				$MISConfig = new MISConfig();
                $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
                $ProjectDOM->load($MISConfig->getConfigFile());
                $ProjectXpath = new DOMXpath($ProjectDOM);
                $creatorPath = $ProjectXpath->query('/Configuration/General/WebCreatorPath')->item(0)->nodeValue;
                if(is_dir($creatorPath)) {
                    copy($MISConfig->getConfigFile(),$creatorPath.basename($MISConfig->getConfigFile()));
                    $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
                    $ProjectDOM->load($creatorPath.basename($MISConfig->getConfigFile()));
                    $ProjectXpath = new DOMXpath($ProjectDOM);
                    $ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Dashboards")->item(0));
                    $ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Version")->item(0));
                    $ProjectXpath->query("/Configuration")->item(0)->removeChild($ProjectXpath->query("/Configuration/Emails")->item(0));
                    $ProjectDOM->save($creatorPath.basename($MISConfig->getConfigFile()));
                }
				return $ret;
			}
		}
		return array('CMgr.getMODEL().__construct();');
	}
	
    private function loadCompanyImage() {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
                
        $ret = '<form action="?&rc=MISConfigurator&rm=saveRetrieveInput" enctype="multipart/form-data" encoding="utf-8" method="post" target="fileupload">';
        $ret.= '<fieldset>';
        $ret.= '<legend>'.$this->_getI18N('loadCompanyImage').'</legend>';
        $ret.= '<input type="hidden" name="ras[0]" value="saveLoadCompanyImage">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('loadCompanyImageInfoMsg').'<hr></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_file">'.$this->_getI18N('companyImage').':</label></td><td><input id="inp_file" name="file" type="file" maxlength="100000" accept="text/xml"></td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
        $ret.= '<iframe style="display:none;" src="about:blank" id="fileupload" name="fileupload" onload=""></iframe>';
        return array($ret,'');
    }
    
    private function saveLoadCompanyImage() {
        $MISConfig = new MISConfig();

        $filename = basename( $_FILES['file']['name']);
        
        move_uploaded_file($_FILES['file']['tmp_name'], ROOT_DIR."htdocs/img/MISView/company.png");
        print '<script type="text/javascript">parent.CMgr.getMODEL().__construct();parent.alert("'.$this->_getI18N("deleteTempInternetFiles").'");</script>';  
    }
	
	private function loadConfig() {
		$ret ="";
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
				
		$ret = '<form action="?&rc=MISConfigurator&rm=saveRetrieveInput" enctype="multipart/form-data" encoding="utf-8" method="post" target="fileupload">';
		$ret.= '<fieldset>';
		$ret.= '<legend>'.$this->_getI18N('import').'</legend>';
		$ret.= '<input type="hidden" name="ras[0]" value="saveLoadConfig">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('loadConfigInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_file">'.$this->_getI18N('configFile').':</label></td><td><input id="inp_file" name="file" type="file" maxlength="100000" accept="text/xml"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		$ret.= '<iframe style="display:none;" src="about:blank" id="fileupload" name="fileupload" onload=""></iframe>';
		}
		return array($ret,'');
	}
	
	private function saveLoadConfig() {
		if($this->isRole("master")){
		$MISConfig = new MISConfig();
		$target_path = $MISConfig->getConfigFilesPath();
		$filename = basename( $_FILES['file']['name']);
		$target_path .= $filename;
		$infoMsg = "";
		
		$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $ProjectDOM->load($_FILES['file']['tmp_name']);
        $ProjectXpath = new DOMXpath($ProjectDOM);
        
		if($ProjectXpath->query("/Configuration")->item(0)->getAttribute("Version") != "" && $ProjectXpath->query("/Configuration")->item(0)->getAttribute("Version") > self::$version){
			$ret = '<form action="?" enctype="multipart/form-data" encoding="utf-8" method="post">';
	        $ret.= '<fieldset>';
	        $ret.= '<legend>'.$this->_getI18N('loadConfig').'</legend>';
	        $ret.= '<table><tr><td colspan="2" style="color:#ff0000">'.$this->_getI18N('updatePortal').'<hr></td></tr>';
	        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('goon').'" onclick="CMgr.getMODEL().__construct();"></td></tr>';
	        $ret.= '</table>';
	        $ret.= '</fieldset>';
	        $ret.= '</form>';
        	print '<script type="text/javascript">parent.CMgr.getMODEL().getRetrieveInputCb({0:"'.
            addslashes($ret)
        	.'",1:""});</script>';
        	return;
		}
		
		if(file_exists($target_path)){
			$filename = basename($filename,".xml").".".date("YmdHis").".xml";
			$target_path = $MISConfig->getConfigFilesPath().$filename;
		  move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
		    if(is_file($target_path)) {
		      $infoMsg = $this->_getI18N("configFileAlreadyExists");
		    }else{
		    	$infoMsg = $this->_getI18N("fileNotFound");
		    }
		}else{
			 move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
		}
		
		$MISConfig->setConfigFile($filename);
        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $ProjectDOM->load($MISConfig->getConfigFile());
        $ProjectXpath = new DOMXpath($ProjectDOM);
        
        $Project = $ProjectXpath->query("/Configuration")->item(0);
		/* UPDATE PROJECT FILE VERSION */

        if($ProjectXpath->query("./General/WebCreatorPath",$Project)->length==0){
        	$ProjectXpath->query("./General",$Project)->item(0)->insertBefore($ProjectDOM->createElement("WebCreatorPath"),$ProjectXpath->query("./General",$Project)->item(0)->firstChild);
            $MISConfig->setNodeValue("WebCreatorPath","",$ProjectDOM,$ProjectXpath->query("/Configuration/General")->item(0));       
        }
        
	    if($ProjectXpath->query("./General/DashboardPath",$Project)->length==0){
            $ProjectXpath->query("./General",$Project)->item(0)->insertBefore($ProjectDOM->createElement("DashboardPath"),$ProjectXpath->query("./General",$Project)->item(0)->firstChild);
            $MISConfig->setNodeValue("DashboardPath","",$ProjectDOM,$ProjectXpath->query("/Configuration/General")->item(0));       
        }
        
	    if($ProjectXpath->query("./General/Language",$Project)->length==0){
            $ProjectXpath->query("./General",$Project)->item(0)->appendChild($ProjectDOM->createElement("Language"));
            $MISConfig->setNodeValue("Language","de",$ProjectDOM,$ProjectXpath->query("/Configuration/General")->item(0));       
        }
        
	    if($ProjectXpath->query("./Dashboards",$Project)->length==0){
            $Project->appendChild($ProjectDOM->createElement("Dashboards"));       
        }
        
		if($ProjectXpath->query("./Emails",$Project)->length==0){
            $Project->appendChild($ProjectDOM->createElement("Emails"));       
        }
        
	    if($ProjectXpath->query("./Version",$Project)->length==0){
	    	$Version = $ProjectDOM->createElement("Version");
	    	$Views = $ProjectDOM->createElement("Views");
	    	$Views->setAttribute("fp_feld","");
	    	$Views->setAttribute("fp_description","");
	    	$Views->setAttribute("view_feld","");
	    	$Views->setAttribute("view_description","");
	    	$Version->appendChild($Views); 
            $Project->appendChild($Version);
            $Version->setAttribute("show","false");
            $Version->setAttribute("odbc","");
            $Version->setAttribute("user","");
            $Version->setAttribute("pw","");
        }
        $ProjectDOM->save($MISConfig->getConfigFile());
        
        $users = array();
        $SectionIDs = array();
        $ImageIDs = array();
        $ReportIDs = array();
        
        /* GENERATE ID ARRAY FOR IMAGES AND REPORTS */
        $iPublishes = $Project->removeChild($ProjectXpath->query("./Publishes",$Project)->item(0));
        $iPublishesList = $ProjectXpath->query("./Publish",$iPublishes);
        $iImageList = $ProjectXpath->query("./Publish/Images/Image",$iPublishes);
        $Publishes = $iPublishes->cloneNode(false);
        $Project->appendChild($Publishes);
        
        $iScorecards = $Project->removeChild($ProjectXpath->query("./Scorecards",$Project)->item(0));
        $iReportList = $ProjectXpath->query("./Scorecard/Reports/Report",$iScorecards);
        $Scorecards = $iScorecards->cloneNode(false);
        $Project->appendChild($Scorecards);
        
        $iDashboards = $Project->removeChild($ProjectXpath->query("./Dashboards",$Project)->item(0));
        $iDashboardList = $ProjectXpath->query("./Dashboard/Reviews/Review",$iDashboards);
        $Dashboards = $iDashboards->cloneNode(false);
        $Project->appendChild($Dashboards);
        
        $iEmails = $Project->removeChild($ProjectXpath->query("./Emails",$Project)->item(0));
        $iEmailList = $ProjectXpath->query("./Email",$iEmails);
        $Emails = $iEmails->cloneNode(false);
        $Project->appendChild($Emails);
        
        foreach($iPublishesList as $iPublish) { 
        	$SectionIDs[str_replace("|"," ",str_replace("_"," ",$iPublish->getAttribute("User")))][$iPublish->getAttribute("ID")] = $this->_createSection($ProjectDOM,$ProjectXpath,$iPublish->getAttribute("ID"), $iPublish->getAttribute("parentID"), utf8_decode(str_replace("|"," ",str_replace("_"," ",$iPublish->getAttribute("User")))), utf8_decode($iPublish->getAttribute("Name")),$iPublish->getAttribute("Alert"));
        }
        
        $emailArr = array();
       
        foreach($iImageList as $iImage) {
        	$MISConfig->setNodeValue("Directory",utf8_decode(str_replace("|"," ",str_replace("_"," ",$iImage->getElementsByTagName("Directory")->item(0)->nodeValue))),$ProjectDOM,$iImage);
        	$Image = $iImage->cloneNode(true);
        	$ImageName = $iImage->getElementsByTagname("Name")->item(0)->nodeValue;
            $ImageDirectory = $iImage->getElementsByTagName("Directory")->item(0)->nodeValue;
            $ImageUser = substr($ImageDirectory,0,(strlen($ImageDirectory)-1));
            $PublishID = $iImage->parentNode->parentNode->getAttribute("ID");
            $PublishName = $iImage->parentNode->parentNode->getAttribute("Name");
            $PublishParentID = $iImage->parentNode->parentNode->getAttribute("parentID");
            $PublishAlert = $iImage->parentNode->parentNode->getAttribute("Alert");
            
        	if(!array_key_exists($ImageUser,$SectionIDs) || !array_key_exists($PublishID,$SectionIDs[$ImageUser])) {
                $SectionIDs[$ImageUser][$PublishID] = $this->_createSection($ProjectDOM,$ProjectXpath,$PublishID,$PublishParentID,utf8_decode($ImageUser),utf8_decode($PublishName),$PublishAlert);
                $Publish = $ProjectXpath->query("./Publish[./@ID='".$SectionIDs[$ImageUser][$PublishID]."']",$Publishes)->item(0);
        	}else{
                $Publish = $ProjectXpath->query("./Publish[./@ID='".$SectionIDs[$ImageUser][$PublishID]."']",$Publishes)->item(0);
            }
            $Publish->getElementsByTagname("Images")->item(0)->appendChild($Image);
            
            if($Image->getAttribute("ID") == "") {
                if(array_key_exists($ImageName,$ImageIDs) && array_key_exists($ImageUser,$ImageIDs[$ImageName])){
                    $newID = $ImageIDs[$ImageName][$ImageUser];
                }else{
                    $newID = $this->_generateReportID();
                    $ImageIDs[$ImageName][$ImageUser] = $newID;
                }
                $Image->setAttribute("ID",$newID);
            }
            if($Image->getElementsByTagName("ppx")->length != 1) {
                $MISConfig->setNodeValue("ppx","N",$ProjectDOM,$Image);
            }
            $users[$ImageUser] = $Image->getElementsByTagName("Ansicht")->item(0)->nodeValue;
            
            $ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
            foreach($ImageEmailArr as $email) {
            	if($email != "") {
	            	array_push($emailArr,trim($email));
            	}
            }
            
            if($Image->getElementsByTagName("SendEmail")->item(0)->nodeValue != "J") {
            	$MISConfig->setNodeValue("Email", "", $ProjectDOM, $Image);
            }
        }
        for($i=0;$iEmailList->length>$i;$i++){
        	$ImageEmailArr = explode(";",$iEmailList->item($i)->nodeValue);
            foreach($ImageEmailArr as $email) {
            	if($email != "") {
	            	array_push($emailArr,trim($email));
            	}
            }
        }

        $xPublishes = $ProjectXpath->query("./Publish",$Publishes); 
        foreach($xPublishes as $xPublish) {
        	$xPublish->setAttribute("parentID",$SectionIDs[str_replace("|"," ",str_replace("_"," ",$xPublish->getAttribute("User")))][$xPublish->getAttribute("parentID")]);
        }

	    foreach($iReportList as $iReport) {
	    	$iReport->parentNode->parentNode->setAttribute("Directory",str_replace("|"," ",str_replace("_"," ",$iReport->parentNode->parentNode->getAttribute("Directory"))));
	    	$Report = $iReport->cloneNode(true);
            $ReportDirectory = $iReport->parentNode->parentNode->getAttribute("Directory");
            $ReportUser = substr($ReportDirectory,0,(strlen($ReportDirectory)-1));
            $PublishID = $iReport->parentNode->parentNode->getAttribute("ID");
            $PublishParentID = $iReport->parentNode->parentNode->getAttribute("parentID");
            $PublishName = $iReport->parentNode->parentNode->getAttribute("Name");
            if(!array_key_exists($ReportUser,$SectionIDs) || !array_key_exists($PublishID,$SectionIDs[$ReportUser])) {
                $SectionIDs[$ReportUser][$PublishID] = $this->_createSection($ProjectDOM,$ProjectXpath,$PublishID,$PublishParentID,utf8_decode($ReportUser),utf8_decode($PublishName),false);
                $Scorecard = $ProjectXpath->query("./Scorecard[./@ID='".$SectionIDs[$ReportUser][$PublishID]."']",$Scorecards)->item(0);
            }else{
            	$Scorecard = $ProjectXpath->query("./Scorecard[./@ID='".$SectionIDs[$ReportUser][$PublishID]."']",$Scorecards)->item(0);
            }
            $Scorecard->getElementsByTagname("Reports")->item(0)->appendChild($Report);          
            $Report->getAttribute("ID") == "" ? $Report->setAttribute("ID",$this->_generateReportID()) : false;
            if(!array_key_exists($ReportUser,$users)) $users[$ReportUser] = "Info-User";
        }
        
        
	    foreach($iDashboardList as $iReport) {
	    	$iReport->parentNode->parentNode->setAttribute("Directory",str_replace("|"," ",str_replace("_"," ",$iReport->parentNode->parentNode->getAttribute("Directory"))));
            $Report = $iReport->cloneNode(true);
            $ReportDirectory = $iReport->parentNode->parentNode->getAttribute("Directory");
            $ReportUser = substr($ReportDirectory,0,(strlen($ReportDirectory)-1));
            $PublishID = $iReport->parentNode->parentNode->getAttribute("ID");
            $PublishParentID = $iReport->parentNode->parentNode->getAttribute("parentID");
            $PublishName = $iReport->parentNode->parentNode->getAttribute("Name");
            if(!array_key_exists($ReportUser,$SectionIDs) || !array_key_exists($PublishID,$SectionIDs[$ReportUser])) {
            	$SectionIDs[$ReportUser][$PublishID] = $this->_createSection($ProjectDOM,$ProjectXpath,$PublishID,$PublishParentID,utf8_decode($ReportUser),utf8_decode($PublishName),false);
            	$Dashboard = $ProjectXpath->query("./Dashboard[./@ID='".$SectionIDs[$ImageUser][$PublishID]."']",$Dashboards)->item(0);
            }else{
                $Dashboard = $ProjectXpath->query("./Dashboard[./@ID='".$SectionIDs[$ReportUser][$PublishID]."']",$Dashboards)->item(0);
            }
            $Dashboard->getElementsByTagname("Reviews")->item(0)->appendChild($Report);          
            $Report->getAttribute("ID") == "" ? $Report->setAttribute("ID",$this->_generateReportID()) : false;
            if(!array_key_exists($ReportUser,$users)) $users[$ReportUser] = "Info-User";
        }
        $ProjectXpath->query("/Configuration")->item(0)->setAttribute("Version",self::$version);
	    $ProjectDOM->save($MISConfig->getConfigFile());
        $this->_registerEmails(implode(";",$emailArr));
        $allUsersArr = $MISConfig->getAllUsernames();
        
        foreach($users as $username => $ansicht) {
            if(!in_array($username,$allUsersArr)) {
                $this->saveRetrieveInput("saveCreateUser",utf8_decode($username),"asdf","asdf","de",$ansicht);
            }
        }
        
        $configName = $ProjectXpath->query("/Configuration")->item(0)->getAttribute("Name");
        if($infoMsg != ""){
	        $ret = '<form action="?" enctype="multipart/form-data" encoding="utf-8" method="post">';
	        $ret.= '<fieldset>';
	        $ret.= '<legend>'.$this->_getI18N('loadConfig').'</legend>';
	        $ret.= '<table><tr><td colspan="2">'.$infoMsg.'<hr></td></tr>';
	        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('goon').'" onclick="CMgr.getMODEL().__construct();"></td></tr>';
	        $ret.= '</table>';
	        $ret.= '</fieldset>';
	        $ret.= '</form>';
        	print '<script type="text/javascript">parent.CMgr.getMODEL().setConfig("'.$configName.'");parent.CMgr.getMODEL().getRetrieveInputCb({0:"'.
            addslashes($ret)
        	.'",1:""});</script>';
        }else{
		print '<script type="text/javascript">parent.CMgr.getMODEL().setConfig("'.$configName.'");parent.CMgr.getMODEL().__construct();</script>';
        }		
		}else{
			print '<script type="text/javascript">parent.CMgr.getMODEL().__construct();</script>';
		}
	}

    private function editConfig($p_ID) {
    	$ret = "";
    	if($this->isRole("master")){
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFilesPath().utf8_encode($p_ID));
        $projectXpath = new DOMXpath($projectDOM);

        $configName = $projectXpath->query("/Configuration")->item(0)->getAttribute("Name");
        $configLang = $projectXpath->query("/Configuration/General/Language")->item(0)->nodeValue;
                
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
        $ret.= '<fieldset>';
        $ret.= '<legend>'.$this->_getI18N('editConfig').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveEditConfig"><input type="hidden" name="ID" value="'.utf8_encode($p_ID).'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editConfigInfoMsg').' <i>'.utf8_encode($p_ID).'</i>.<hr></td><td></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('configName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.$configName.'"></td></tr>';
            $ret.= '<tr><td class="label"><label for="inp_lang">'.$this->_getI18N('lang').':</label></td><td>';
            $ret.= '<select id="inp_lang" name="lang">';
            $allLangsArr = I18N::getLanguages();
            foreach($allLangsArr as $key => $lang) {
                if($configLang == $lang)
                $ret.= '<option value="'.$lang.'" selected="selected">'.utf8_encode($lang).'</option>';
                else 
                $ret.= '<option value="'.$lang.'">'.utf8_encode($lang).'</option>';
            }
            $ret.= '</select>';
        $ret.= '</td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
    	}
        return array($ret,'');
    }
    
    private function saveEditConfig($p_configFile,$p_name,$p_lang) {
    	if($this->isRole("master")){
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFilesPath().utf8_encode($p_configFile));
        $projectXpath = new DOMXpath($projectDOM);
        
        $PP = $projectXpath->query('/Configuration')->item(0);
        $PP->setAttribute("Name",utf8_encode($p_name));
        $PX = $projectXpath->query('/Configuration/General')->item(0);
        $MISConfig->setNodeValue("Language",$p_lang,$projectDOM,$PX); 
        
        $projectDOM->save($MISConfig->getConfigFilesPath().utf8_encode($p_configFile));
    	}
        return array('CMgr.getMODEL().__construct();'); 
    }
	
	private function deleteConfig($p_configFile) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
				
		$PPName = $p_configFile;
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend>'.$this->_getI18N('deleteConfig').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteConfig"><input type="hidden" name="ID" value="'.utf8_encode($p_configFile).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteConfigInfoMsg1').' <i>'.utf8_encode($PPName).'</i> '.$this->_getI18N('deleteConfigInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name"><font color="#ee3333">'.$this->_getI18N('deleteUserConfig').':</font></label></td><td><input id="inp_name" name="deleteUserConfig" checked="checked" type="checkbox"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteConfig($p_configFile,$p_deleteUserConfig) {
		$MISConfig = new MISConfig();
		
		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
		$authDOM->load($MISConfig->authFile);
		$authXpath = new DOMXpath($authDOM);
		if($p_deleteUserConfig == "true") {
			$AUList = $authXpath->query("/auth/users/user[@setting='".utf8_encode(basename($p_configFile,".xml"))."']");
			for($i=0;$i<$AUList->length;$i++) {
				$AU = $AUList->item($i);
				$AU->parentNode->removeChild($AU);
			}
			$authDOM->save($MISConfig->authFile);
	    }
		unlink(ROOT_DIR."apps/MISConfig/data/".utf8_encode($p_configFile));
		
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        $configName = $projectXpath->query("/Configuration")->item(0)->getAttribute("Name");

		return array('CMgr.getMODEL().__construct();CMgr.getMODEL().setConfig("'.$configName.'");');	
	}

	private function editSection($p_ID){
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$ret="";
		$eval="";
		if(count($IDArr)>1){
			$ID = $IDArr[0];
			$username = $IDArr[1];
			$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
			$projectDOM->load($MISConfig->getConfigFile());
			$projectXpath = new DOMXpath($projectDOM);
					
			$PPName = $projectXpath->query('/Configuration/Publishes/Publish/@Name[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
			$PPHauptampel = $projectXpath->query('/Configuration/Publishes/Publish/@Alert[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
			$ret.= '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
			$ret.= '<fieldset>';
			$ret.= '<legend><img src="img/package.png">'.str_replace("_"," ",trim($PPName,"_ ")).' '.$this->_getI18N('editSection').'</legend>';
			$ret.= '<input type="hidden" name="saveMethod" value="saveEditSection"><input type="hidden" name="ID" value="'.utf8_encode($p_ID).'">';
			$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editSectionInfoMsg').' <i>'.str_replace("_"," ",trim($PPName,"_ ")).'</i>.<hr></td><td></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('sectionName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.str_replace("_"," ",trim($PPName,"_ ")).'"></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_showHauptampel">'.$this->_getI18N('showHauptampel').':</label></td><td><input id="inp_name" name="showHauptampel" type="checkbox" ';
			if($PPHauptampel == "true") {
				$ret.= ' checked="checked" ';
			}
			$ret.= '></td></tr>';
			$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
			$ret.= '</table>';
			$ret.= '</fieldset>';
			$ret.= '</form>';
		}else{
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editUser","'.$p_ID.'");';
		}
		return array($ret,$eval);
	}
	
	private function saveEditSection($p_ID,$p_name,$p_showHauptampel){
		$MISConfig = new MISConfig();	
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",array_shift($IDsArr));
		
		$ID = $IDArr[0];
		$username = $IDArr[1];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$dataDir = $projectXpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;
		
		$PP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$ID.'" and ./@User = "'.utf8_encode($username).'"]')->item(0);
		
		@rename(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name"))."\\",
				utf8_decode($dataDir.$PP->getAttribute("User"))."\\".
				"_".str_replace(" ","_",$p_name)."_\\");
		
		$PP->setAttribute("Name",utf8_encode("_".str_replace(" ","_",trim($p_name,"_ "))."_"));
		$PP->setAttribute("Alert",utf8_encode($p_showHauptampel));
		

		
		$PSList = $projectXpath->query('/Configuration/Scorecards/Scorecard[./@ID = "'.$ID.'" and ./@Directory = "'.utf8_encode($username).'\\"]');
		for($i=0;$i<$PSList->length;$i++) {
			$PS = $PSList->item($i);
			$PS->setAttribute("Name",utf8_encode("_".str_replace(" ","_",trim($p_name,"_ "))."_"));
		}
		$PSList = $projectXpath->query('/Configuration/Dashboards/Dashboard[./@ID = "'.$ID.'" and ./@Directory = "'.utf8_encode($username).'\\"]');
		for($i=0;$i<$PSList->length;$i++) {
			$PS = $PSList->item($i);
			$PS->setAttribute("Name",utf8_encode("_".str_replace(" ","_",trim($p_name,"_ "))."_"));
		}
		$projectDOM->save($MISConfig->getConfigFile());
		if(count($IDsArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editSection","'.implode("|",$IDsArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().__construct();';
		}
		return array($eval);		
	}

	private function deleteSection($p_ID){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		$PPNames = Array();
		$IDsArr = explode("|",$p_ID);
		$deleteUsers = false;
		$newIDsArr = array();
		foreach($IDsArr as $IDStr){
			$IDArr = explode("_",$IDStr);
			if(count($IDArr)>1) {
				$ID = $IDArr[0];
				$username = $IDArr[1];
				array_push($PPNames, str_replace("_"," ",trim($projectXpath->query('/Configuration/Publishes/Publish/@Name[./../@ID="'.$ID.'"]')->item(0)->nodeValue))." (".utf8_encode($username).")");
			}else{
				$deleteUsers = true;
				array_push($newIDsArr,$IDArr[0]);
			}
		}

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/package.png">'.$this->_getI18N('deleteSection').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteSection"><input type="hidden" name="ID" value="'.utf8_encode($p_ID).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteSectionInfoMsg1').' <i>'.implode(", ",$PPNames).'</i> '.$this->_getI18N('deleteSectionInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="';
		if($deleteUsers) {
			$ret.='CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'deleteUser\',\''.implode("|",$newIDsArr).'\');';
		}else{
			$ret.='CMgr.getMODEL().abortRetrieveInput();';
		}
		$ret.='"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteSection($p_ID){
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$newIDsArr = Array();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		
		foreach($IDsArr as $IDStr) {
			$IDArr = explode("_",$IDStr);
			if(count($IDArr)>1){
				$ID = $IDArr[0];
				$username = $IDArr[1];
				$PPList = $projectXpath->query('/Configuration/Publishes/Publish[./@parentID="'.$ID.'" and ./@User = "'.utf8_encode($username).'"]');
				for($i=0;$i<$PPList->length;$i++) {
					$PP = $PPList->item($i);
					$currentID = $PP->getAttribute('ID');				
					$this->saveDeleteSection($currentID."_".$username);
				}
				$this->saveDeleteSubSection($ID,$username);
			}else{
				array_push($newIDsArr,$IDStr);
			}
		}
		if(count($newIDsArr)>0){
			$eval='CMgr.getMODEL().__construct();CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteUser","'.implode("|",$newIDsArr).'");';
		}else{
			$eval='CMgr.getMODEL().__construct();';
		}
		return array($eval);
	}
	
	private function saveDeleteSubSection($p_ID,$p_username) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
			
		$PP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID="'.$p_ID.'" and ./@User = "'.utf8_encode($p_username).'"]');
		if($PP->length>0) {
			$dataDir = $projectXpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;

			$PP = $PP->item(0);
			$this->deleteDir(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name"))."\\");
			
			$PP->parentNode->removeChild($PP);
			$PS = $projectXpath->query('/Configuration/Scorecards/Scorecard[./@ID="'.$p_ID.'" and ./@Directory = "'.utf8_encode($p_username).'\\"]');
			for($i=0;$i<$PS->length;$i++){
				$PS->item($i)->parentNode->removeChild($PS->item($i));
			}
		    $PS = $projectXpath->query('/Configuration/Dashboards/Dashboard[./@ID="'.$p_ID.'" and ./@Directory = "'.utf8_encode($p_username).'\\"]');
	        for($i=0;$i<$PS->length;$i++){
	            $PS->item($i)->parentNode->removeChild($PS->item($i));
	        }
			$projectDOM->save($MISConfig->getConfigFile());
		}
	}
	
	private function createSection($p_parentID="",$p_username){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/package.png">'.$this->_getI18N('createSection').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateSection"><input type="hidden" name="parentID" value="'.$p_parentID.'"><input type="hidden" name="username" value="'.utf8_encode($p_username).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createSectionInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('sectionName').':</label></td><td><input id="inp_name" name="name" type="text" value=""></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_showHauptampel">'.$this->_getI18N('showHauptampel').':</label></td><td><input id="inp_showHauptampel" name="showHauptampel" type="checkbox" checked=checked value="1"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateSection($p_parentID,$p_username,$p_sectionName,$p_showHauptampel){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$ProjectXpath = new DOMXpath($projectDOM);
		
		$this->_createSection($projectDOM,$ProjectXpath,"",$p_parentID,$p_username,$p_sectionName,$p_showHauptampel);

		$projectDOM->save($MISConfig->getConfigFile());
			
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function emptySection($p_ID,$p_username){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
				
		$PPName = $projectXpath->query('/Configuration/Publishes/Publish/@Name[./../@ID="'.$p_ID.'"]')->item(0)->nodeValue;
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/package.png">'.$PPName.' '.$this->_getI18N('emptySection').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveEmptySection"><input type="hidden" name="ID" value="'.$p_ID.'"><input type="hidden" name="username" value="'.$p_username.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('emptySectionReportsInfoMsg1').' <i>'.$PPName.'</i> '.$this->_getI18N('emptySectionReportsInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveEmptySection($p_ID,$p_username){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./../../@ID="'.$p_ID.'" and ./Directory="'.$p_username.'\\"]');
		
		for($i=0;$i<$PIList->length;$i++) {
			$PI = $PIList->item($i);
			$PI->parentNode->removeChild($PI);
		}
		
	    $SRList = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./../../@ID="'.$p_ID.'" and ./../../@Directory="'.$p_username.'\\"]');
        
        for($i=0;$i<$SRList->length;$i++) {
            $SR = $SRList->item($i);
            $SR->parentNode->removeChild($SR);
        }
        
	    $SRList = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./../../@ID="'.$p_ID.'" and ./../../@Directory="'.$p_username.'\\"]');
        
        for($i=0;$i<$SRList->length;$i++) {
            $SR = $SRList->item($i);
            $SR->parentNode->removeChild($SR);
        }
		$projectDOM->save($MISConfig->getConfigFile());

		return array('CMgr.getMODEL().__construct();');
	}
	
	private function createReport($p_sectionID,$p_username) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
				
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/report.png">'.$this->_getI18N('createReport').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateReport"><input type="hidden" name="ID" value="'.$p_sectionID.'"><input type="hidden" name="username" value="'.utf8_encode($p_username).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createReportInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td><label for="inp_name">'.$this->_getI18N('reportName').':</label></td><td><input id="inp_name" name="name" type="text" value=""></td></tr>';
		$ret.= '<tr><td><label for="inp_description">'.$this->_getI18N('reportDescription').':</label></td><td><textarea id="inp_description" name="description"></textarea></td></tr>';
		$ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('pprName').':</label></td><td>';
		$ret.= '<select name="pprname">';
		$PPRArr = $MISConfig->getAllPPR();
		foreach($PPRArr as $PPRName) {
			$ret.= '<option value="'.$PPRName.'">'.$PPRName.'</option>';		
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_ppxFile">'.$this->_getI18N("ppxFile").'</label></td><td>';
        $ret.= '<input type="checkbox" id="inp_ppxFile" name="inp_ppxFile" ';

        $ret.= ' value="PPX"></td></tr>';
		$ret.= '<tr><td><label for="inp_imageGenerate">'.$this->_getI18N('imageGenerate').':</label></td><td><label for="inp_gifGenerate1">'.$this->_getI18N('GIF').'</label><input class="btn" type="checkbox" id="inp_gifGenerate1" name="gifGenerate" value="GIF">/<input class="btn" type="checkbox" id="inp_jpgGenerate1" name="jpgGenerate" value="JPG"><label for="inp_jpgGenerate1">'.$this->_getI18N('JPG').'</label></td></tr>';
		$ret.= '<tr><td><label for="inp_imageType1">'.$this->_getI18N('imageType').':</label></td><td>';
			$ret.= '<select id="inp_imageType1" name="imageType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				$ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageLayer1">'.$this->_getI18N('imageLayer').':</label></td><td><input id="inp_imageLayer1" name="imageLayer1" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_pdfGenerate1">'.$this->_getI18N('pdfGenerate').':</label></td><td>';
			$ret.= '<select id="inp_pdfGenerate1" name="pdfGenerate1"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfType1">'.$this->_getI18N('pdfType').':</label></td><td>';
			$ret.= '<select id="inp_pdfType1" name="pdfType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				$ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfLayer1">'.$this->_getI18N('pdfLayer').':</label></td><td><input id="inp_pdfLayer1" name="pdfLayer1" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_xlsGenerate1">'.$this->_getI18N('xlsGenerate').':</label></td><td>';
			$ret.= '<select id="inp_xlsGenerate1" name="xlsGenerate1"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_sendEmail">'.$this->_getI18N('sendEmail').':</label></td><td>';
			$ret.= '<select id="inp_sendEmail" name="sendEmail"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_email">'.$this->_getI18N('email').':</label></td><td><input id="inp_email" name="email" type="text" value=""></td></tr>';
		
		if(!$this->isRole("master")){
			$ret.='<input type="hidden" value="'.$this->_getView($p_username).'" name="ansicht"/>';
		}else{
        $ret.= '<tr><td><label for="inp_ansicht">'.$this->_getI18N('view').':</label></td><td>';
			$ret.= '<select id="inp_ansicht" name="ansicht">';
			$viewsArr = $MISConfig->getAllViews();
			foreach($viewsArr as $key => $view) {
				$ret.= '<option value="'.$key.'"';
				if($key == $this->_getView($p_username)) $ret.= ' selected="selected"';
				$ret.= '>'.$view.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		}
		//-------------------------------------------
		$ret.= '<tr><td colspan="2"><hr></td></tr>';
		//-------------------------------------------
		$ret.= '<tr><td><label for="inp_previewReport">'.$this->_getI18N('previewReport').':</label></td><td>';
			$ret.= '<select id="inp_previewReport" name="previewReport"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>&nbsp;<label for="inp_gifGenerate">'.$this->_getI18N('GIF').'</label><input class="btn" type="radio" id="gifGenerate" name="imageGenerate" checked="checked" value="GIF">/<input class="btn" type="radio" id="inp_jpgGenerate" name="imageGenerate" value="JPG"><label for="inp_jpgGenerate">'.$this->_getI18N('JPG').'</label>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageType2">'.$this->_getI18N('imageType').':</label></td><td>';
			$ret.= '<select id="inp_imageType2" name="imageType2">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				$ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageLayer2">'.$this->_getI18N('imageLayer').':</label></td><td><input id="inp_imageLayer2" name="imageLayer2" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_pdfGenerate2">'.$this->_getI18N('pdfGenerate').':</label></td><td>';
			$ret.= '<select id="inp_pdfGenerate2" name="pdfGenerate2"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfType2">'.$this->_getI18N('pdfType').':</label></td><td>';
			$ret.= '<select id="inp_pdfType2" name="pdfType2">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				$ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfLayer2">'.$this->_getI18N('pdfLayer').':</label></td><td><input id="inp_pdfLayer2" name="pdfLayer1" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_xlsGenerate2">'.$this->_getI18N('xlsGenerate').':</label></td><td>';
			$ret.= '<select id="inp_xlsGenerate2" name="xlsGenerate2"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateReport($p_sectionID,$p_username,$p_reportName,$p_reportDescription,$p_pprReport,$p_ppxFile,$p_gifGenerate,$p_jpgGenerate,$p_imageType1,$p_imageLayer1,$p_pdfGenerate1,$p_pdfType1,$p_pdfLayer1,$p_xlsGenerate1,$p_sendEmail,$p_email,$p_view,$p_previewReport,$p_imageGenerate,$p_imageType2,$p_imageLayer2,$p_pdfGenerate2,$p_pdfType2,$p_pdfLayer2,$p_xlsGenerate2) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$newID = $this->_generateReportID();
		
		$p_gifGenerate = ($p_gifGenerate == "true") ? "J" : "N";
		$p_jpgGenerate = ($p_jpgGenerate == "true") ? "J" : "N";
		$p_ppxFile = ($p_ppxFile == "true") ? "J" : "N";
		
		$PI = $projectDOM->createElement("Image");
		$PI->setAttribute("ID",$newID);
		$temp = $projectDOM->createElement("Name");
		$temp->appendChild($projectDOM->createTextNode(utf8_encode($p_reportName)));
		$PI->appendChild($temp);
		$temp = $projectDOM->createElement("Description");
		$temp->appendChild($projectDOM->createTextNode(utf8_encode($p_reportDescription)));
		$PI->appendChild($temp);
		$PI->appendChild($projectDOM->createElement("Directory",utf8_encode($p_username)."\\"));
		$PI->appendChild($projectDOM->createElement("Report",utf8_encode($p_pprReport)));
		$PI->appendChild($projectDOM->createElement("GIFGenerate",$p_gifGenerate));
		$PI->appendChild($projectDOM->createElement("JPGGenerate",$p_jpgGenerate));
		$PI->appendChild($projectDOM->createElement("PDFGenerate",$p_pdfGenerate1));
		$PI->appendChild($projectDOM->createElement("XLSGenerate",$p_xlsGenerate1));
		$PI->appendChild($projectDOM->createElement("Active","J"));
		$PI->appendChild($projectDOM->createElement("SendEmail",$p_sendEmail));
		$PI->appendChild($projectDOM->createElement("ImageType",$p_imageType1));
		$PI->appendChild($projectDOM->createElement("ImageLayer",$p_imageLayer1));
		$PI->appendChild($projectDOM->createElement("PDFImageType",$p_pdfType1));
		$PI->appendChild($projectDOM->createElement("PDFImageLayer",$p_pdfLayer1));
		if($this->isRole("master")) {
		  $PI->appendChild($projectDOM->createElement("Ansicht",$p_view));
		}else{
			$PI->appendChild($projectDOM->createElement("Ansicht",$this->_getView($p_username)));
		}
		$PI->appendChild($projectDOM->createElement("Email",utf8_encode($p_email)));
		$PI->appendChild($projectDOM->createElement("ppx",utf8_encode($p_ppxFile)));
		
		$PIs = $projectXpath->query("/Configuration/Publishes/Publish/Images[./../@ID='".$p_sectionID."']")->item(0);
		$PIs->appendChild($PI);
		
		if($p_previewReport == "J") {
			$PI = $projectDOM->createElement("Image");
			$PI->setAttribute("ID",$newID);
			$temp = $projectDOM->createElement("Name");
			$temp->appendChild($projectDOM->createTextNode(utf8_encode($p_reportName)));
			$PI->appendChild($temp);
			$temp = $projectDOM->createElement("Description");
			$temp->appendChild($projectDOM->createTextNode(utf8_encode($p_reportDescription)));
			$PI->appendChild($temp);
			$PI->appendChild($projectDOM->createElement("Directory",utf8_encode($p_username)."\\"));
			$PI->appendChild($projectDOM->createElement("Report",utf8_encode($p_pprReport)."_Graf"));
			if($p_imageGenerate == "GIF") {
				$PI->appendChild($projectDOM->createElement("GIFGenerate","J"));
				$PI->appendChild($projectDOM->createElement("JPGGenerate","N"));
			}else{
				$PI->appendChild($projectDOM->createElement("GIFGenerate","N"));
				$PI->appendChild($projectDOM->createElement("JPGGenerate","J"));
			}
			$PI->appendChild($projectDOM->createElement("PDFGenerate",$p_pdfGenerate2));
			$PI->appendChild($projectDOM->createElement("XLSGenerate",$p_xlsGenerate2));
			$PI->appendChild($projectDOM->createElement("Active","N"));
			$PI->appendChild($projectDOM->createElement("SendEmail","N"));
			$PI->appendChild($projectDOM->createElement("ImageType",$p_imageType2));
			$PI->appendChild($projectDOM->createElement("ImageLayer",$p_imageLayer2));
			$PI->appendChild($projectDOM->createElement("PDFImageType",$p_pdfType2));
			$PI->appendChild($projectDOM->createElement("PDFImageLayer",$p_pdfLayer2));
			$PI->appendChild($projectDOM->createElement("Ansicht",$p_view));
			$PI->appendChild($projectDOM->createElement("Email",$p_email));
			$PI->appendChild($projectDOM->createElement("ppx",utf8_encode($p_ppxFile)));
			
			$PIs = $projectXpath->query("/Configuration/Publishes/Publish/Images[./../@ID='".$p_sectionID."']")->item(0);
			$PIs->appendChild($PI);
		}
		
		$projectDOM->save($MISConfig->getConfigFile());
		$this->_registerEmails($p_email);
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configReportsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configReportsFormCb);');
	}
	
	private function editReport($p_ID) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		$ID = explode("_",$IDArr[0]);
		$ID = $ID[0];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
		
		$PIs = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'"]');
		$PI = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="J"]')->item(0);

		if($PIs->length == 2) {
			$previewImage = true;
			$PIpreview = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="N"]')->item(0);
		}else{
			$previewImage = false;
			$PIpreview = null;
		}
				
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/report.png">'.$PI->getElementsByTagName("Name")->item(0)->nodeValue.' '.$this->_getI18N('editReport').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveEditReport"><input type="hidden" name="ID" value="'.utf8_encode($p_ID).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editReportInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('reportName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.$PI->getElementsByTagName("Name")->item(0)->nodeValue.'"></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_description">'.$this->_getI18N('reportDescription').':</label></td><td><textarea id="inp_description" name="description">'.$PI->getElementsByTagName("Description")->item(0)->nodeValue.'</textarea></td></tr>';
		$ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('pprName').':</label></td><td>';
		$ret.= '<select name="pprname">';
		$PPRArr = $MISConfig->getAllPPR();
		foreach($PPRArr as $PPRName) {
			$ret.= '<option';
			if(strtoupper($PPRName) == strtoupper($PI->getElementsByTagName("Report")->item(0)->nodeValue)) $ret.= ' selected="selected"';
			$ret.= ' value="'.$PPRName.'">'.$PPRName.'</option>';		
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_ppxFile">'.$this->_getI18N("ppxFile").'</label></td><td>';
		$ret.= '<input type="checkbox" id="inp_ppxFile" name="inp_ppxFile" ';
		if($PI->getElementsByTagName("ppx")->item(0)->nodeValue == "J") $ret.= 'checked="checked" ';
		$ret.= ' value="PPX"></td></tr>';
		$ret.= '<tr><td><label for="inp_imageGenerate">'.$this->_getI18N('imageGenerate').':</label></td><td><label for="inp_gifGenerate1">'.$this->_getI18N('GIF').'</label>';
			$ret.= '<input class="btn" type="checkbox" id="inp_gifGenerate1" name="gifGenerate"';
				if($PI->getElementsByTagName("GIFGenerate")->item(0)->nodeValue == "J") $ret.= ' checked="checked"';
			$ret.= ' value="GIF">/';
			$ret.= '<input class="btn" type="checkbox" id="inp_jpgGenerate1" name="jpgGenerate"';
				if($PI->getElementsByTagName("JPGGenerate")->item(0)->nodeValue == "J") $ret.= ' checked="checked"';
			$ret.= ' value="JPG"><label for="inp_jpgGenerate1">'.$this->_getI18N('JPG').'</label></td></tr>';
		$ret.= '<tr><td><label for="inp_imageType1">'.$this->_getI18N('imageType').':</label></td><td>';
			$ret.= '<select id="inp_imageType1" name="imageType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($key == $PI->getElementsByTagName("ImageType")->item(0)->nodeValue) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageLayer1">'.$this->_getI18N('imageLayer').':</label></td><td><input id="inp_imageLayer1" name="imageLayer1" type="text" value="';
			$ret.= $PI->getElementsByTagName("ImageLayer")->item(0)->nodeValue;
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_pdfGenerate1">'.$this->_getI18N('pdfGenerate').':</label></td><td>';
			$ret.= '<select id="inp_pdfGenerate1" name="pdfGenerate1"><option value="N">'.$this->_getI18N("no").'</option>';
			if($PI->getElementsByTagName("PDFGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
			else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfType1">'.$this->_getI18N('pdfType').':</label></td><td>';
			$ret.= '<select id="inp_pdfType1" name="pdfType1">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($PI->getElementsByTagName("PDFImageType")->item(0)->nodeValue == $key) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';		
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfLayer1">'.$this->_getI18N('pdfLayer').':</label></td><td><input id="inp_pdfLayer1" name="pdfLayer1" type="text" value="';
			$ret.= $PI->getElementsByTagName("PDFImageLayer")->item(0)->nodeValue;
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_xlsGenerate1">'.$this->_getI18N('xlsGenerate').':</label></td><td>';
			$ret.= '<select id="inp_xlsGenerate1" name="xlsGenerate1"><option value="N">'.$this->_getI18N("no").'</option>';
				if($PI->getElementsByTagName("XLSGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
				else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_sendEmail">'.$this->_getI18N('sendEmail').':</label></td><td>';
			$ret.= '<select id="inp_sendEmail" name="sendEmail"><option value="N">'.$this->_getI18N("no").'</option>';
				if($PI->getElementsByTagName("SendEmail")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
				else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</selected>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_email">'.$this->_getI18N('email').':</label></td><td><input id="inp_email" name="email" type="text" value="';
			$ret.= $PI->getElementsByTagName("Email")->item(0)->nodeValue;
		$ret.= '"></td></tr>';

	        if(!$this->isRole("master")){
                $ret.='<input type="hidden" name="ansicht" value="'.$PI->getElementsByTagName("Ansicht")->item(0)->nodeValue.'" />';
            }else{
        $ret.= '<tr><td><label for="inp_ansicht">'.$this->_getI18N('view').':</label></td><td>';            	
			$ret.= '<select id="inp_ansicht" name="ansicht"';
/*			if(!$this->isRole("master")){
				$ret.=' disabled="disabled" ';
			}
*/			$ret.='>';
			$viewsArr = $MISConfig->getAllViews();
			foreach($viewsArr as $key => $view) {
				$ret.= '<option value="'.$key.'"';
				if($PI->getElementsByTagName("Ansicht")->item(0)->nodeValue == $key) $ret.= ' selected="selected"';
				$ret.= '>'.$view.'</option>';		
			}
			$ret.= '</select>';
        $ret.= '</td></tr>';			
            }

		//--------------------------------------------
		$ret.= '<tr><td colspan="2"><hr></td></tr>';
		//--------------------------------------------
		$ret.= '<tr><td><label for="inp_previewReport">'.$this->_getI18N('previewReport').':</label></td><td>';
			$ret.= '<select id="inp_previewReport" name="previewReport"><option value="N">'.$this->_getI18N("no").'</option><option';
			if($previewImage) $ret.= ' selected="selected"';
			$ret.= ' value="J">'.$this->_getI18N("yes").'</option></select>&nbsp;<label for="inp_gifGenerate2">'.$this->_getI18N('GIF').'</label><input class="btn" type="radio" id="gifGenerate2" name="imageGenerate2"';
			if(!$previewImage || ($previewImage && $PIpreview->getElementsByTagName("GIFGenerate")->item(0)->nodeValue == 'J')) $ret.= ' checked="checked"';
			$ret.= ' value="GIF">/<input class="btn" type="radio" id="inp_jpgGenerate2" name="imageGenerate2"';
			if($previewImage && $PIpreview->getElementsByTagName("JPGGenerate")->item(0)->nodeValue == 'J') $ret.= ' checked="checked"';
			$ret.= ' value="JPG"><label for="inp_jpgGenerate2">'.$this->_getI18N('JPG').'</label>';
		$ret.= '</td></tr>';

		$ret.= '<tr><td><label for="inp_imageType2">'.$this->_getI18N('imageType').':</label></td><td>';
			$ret.= '<select id="inp_imageType2" name="imageType2">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($previewImage && $key == $PIpreview->getElementsByTagName("ImageType")->item(0)->nodeValue) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';			
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_imageLayer2">'.$this->_getI18N('imageLayer').':</label></td><td><input id="inp_imageLayer2" name="imageLayer2" type="text" value="';
			if($previewImage) $ret.= $PIpreview->getElementsByTagName("ImageLayer")->item(0)->nodeValue;
			else $ret.= "0";
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_pdfGenerate2">'.$this->_getI18N('pdfGenerate').':</label></td><td>';
			$ret.= '<select id="inp_pdfGenerate2" name="pdfGenerate2"><option value="N">'.$this->_getI18N("no").'</option>';
			if($previewImage && $PIpreview->getElementsByTagName("PDFGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
			else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfType2">'.$this->_getI18N('pdfType').':</label></td><td>';
			$ret.= '<select id="inp_pdfType2" name="pdfType2">';
			$imageTypesArr = $MISConfig->getAllImageTypes();
			foreach($imageTypesArr as $key => $imageType) {
				if($previewImage && $key == $PIpreview->getElementsByTagName("PDFImageType")->item(0)->nodeValue) $ret.= '<option selected="selected" value="'.$key.'">'.$imageType.'</option>';
				else $ret.= '<option value="'.$key.'">'.$imageType.'</option>';			
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pdfLayer2">'.$this->_getI18N('pdfLayer').':</label></td><td><input id="inp_pdfLayer2" name="pdfLayer1" type="text" value="';
			if($previewImage) $ret.= $PIpreview->getElementsByTagName("PDFImageLayer")->item(0)->nodeValue;
			else $ret.= "0";
		$ret.= '"></td></tr>';
		$ret.= '<tr><td><label for="inp_xlsGenerate2">'.$this->_getI18N('xlsGenerate').':</label></td><td>';
			$ret.= '<select id="inp_xlsGenerate2" name="xlsGenerate2"><option value="N">'.$this->_getI18N("no").'</option>';
				if($previewImage && $PIpreview->getElementsByTagName("XLSGenerate")->item(0)->nodeValue == 'J') $ret.= '<option selected="selected" value="J">'.$this->_getI18N("yes").'</option>';
				else $ret.= '<option value="J">'.$this->_getI18N("yes").'</option>';
			$ret.= '</select>';
		$ret.= '</td></tr>';
		
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveEditReport($p_ID,$p_reportName,$p_reportDescription,$p_pprReport,$p_ppxFile,$p_gifGenerate,$p_jpgGenerate,$p_imageType1,$p_imageLayer1,$p_pdfGenerate1,$p_pdfType1,$p_pdfLayer1,$p_xlsGenerate1,$p_sendEmail,$p_email,$p_view,$p_previewReport,$p_imageGenerate,$p_imageType2,$p_imageLayer2,$p_pdfGenerate2,$p_pdfType2,$p_pdfLayer2,$p_xlsGenerate2) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		$ID = explode("_",array_shift($IDArr));
		$ID = $ID[0];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'"]');
		$PI = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="J"]')->item(0);
		$PP = $PI->parentNode->parentNode;

		if($PIList->length == 2) {
			$previewImage = true;
			$PIpreview = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'" and ./Active="N"]')->item(0);
		}else{
			$previewImage = false;
			$PIpreview = null;
		}
		
		$dataDir = $projectXpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;
		
		$p_gifGenerate = ($p_gifGenerate == "true") ? "J" : "N";
		$p_jpgGenerate = ($p_jpgGenerate == "true") ? "J" : "N";
		$p_ppxFile = ($p_ppxFile == "true") ? "J" : "N";
		
		$MISConfig->setNodeValue("Name",$p_reportName,$projectDOM,$PI);
		$MISConfig->setNodeValue("Description",$p_reportDescription,$projectDOM,$PI);
		$MISConfig->setNodeValue("Report",$p_pprReport,$projectDOM,$PI);
		$MISConfig->setNodeValue("GIFGenerate",$p_gifGenerate,$projectDOM,$PI);
		$MISConfig->setNodeValue("JPGGenerate",$p_jpgGenerate,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFGenerate",$p_pdfGenerate1,$projectDOM,$PI);
		$MISConfig->setNodeValue("XLSGenerate",$p_xlsGenerate1,$projectDOM,$PI);
		$MISConfig->setNodeValue("SendEmail",$p_sendEmail,$projectDOM,$PI);
		$MISConfig->setNodeValue("ImageType",$p_imageType1,$projectDOM,$PI);
		$MISConfig->setNodeValue("ImageLayer",$p_imageLayer1,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFImageType",$p_pdfType1,$projectDOM,$PI);
		$MISConfig->setNodeValue("PDFImageLayer",$p_pdfLayer1,$projectDOM,$PI);
		if($this->isRole("master")){
		  $MISConfig->setNodeValue("Ansicht",$p_view,$projectDOM,$PI);
		}
		$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PI);
		$MISConfig->setNodeValue("ppx",$p_ppxFile,$projectDOM,$PI);
		
		
		if($previewImage && $p_previewReport == "N") {
			@unlink(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".gif"));
			@unlink(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".jpg"));
			@unlink(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".pdf"));
			@unlink(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".xls"));
			$PIpreview->parentNode->removeChild($PIpreview);
		} else if($previewImage && $p_previewReport == "J") {
			@rename(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".gif"),
				utf8_decode($dataDir.$PP->getAttribute("User")."\\"
				.$PP->getAttribute("Name"))."\\".$p_reportName.".gif");
			@rename(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".jpg"),
				utf8_decode($dataDir.$PP->getAttribute("User")."\\"
				.$PP->getAttribute("Name"))."\\".$p_reportName.".jpg");
			@rename(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".pdf"),
				utf8_decode($dataDir.$PP->getAttribute("User")."\\"
				.$PP->getAttribute("Name"))."\\".$p_reportName.".pdf");
			@rename(utf8_decode($dataDir.$PP->getAttribute("User")."\\"
					.$PP->getAttribute("Name")."\\".$PIpreview->getElementsByTagName("Name")->item(0)->nodeValue.".xls"),
				utf8_decode($dataDir.$PP->getAttribute("User")."\\"
				.$PP->getAttribute("Name"))."\\".$p_reportName.".xls");
			$MISConfig->setNodeValue("Name",$p_reportName,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("Description",$p_reportDescription,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("Report",$p_pprReport."_Graf",$projectDOM,$PIpreview);
			if($p_imageGenerate == "GIF") {
				$MISConfig->setNodeValue("GIFGenerate","J",$projectDOM,$PIpreview);
				$MISConfig->setNodeValue("JPGGenerate","N",$projectDOM,$PIpreview);
			}else{
				$MISConfig->setNodeValue("GIFGenerate","N",$projectDOM,$PIpreview);
				$MISConfig->setNodeValue("JPGGenerate","J",$projectDOM,$PIpreview);
			}
			$MISConfig->setNodeValue("PDFGenerate",$p_pdfGenerate2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("XLSGenerate",$p_xlsGenerate2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("ImageType",$p_imageType2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("ImageLayer",$p_imageLayer2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("PDFImageType",$p_pdfType2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("PDFImageLayer",$p_pdfLayer2,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("Ansicht",$p_view,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("ppx",$p_ppxFile,$projectDOM,$PIpreview);
		} else if(!$previewImage && $p_previewReport == "J") {
			$PIpreview = $projectDOM->createElement("Image");
			$PIpreview->setAttribute("ID",$ID);
			$PIpreview->appendChild($projectDOM->createElement("Name"));
			$MISConfig->setNodeValue("Name",$p_reportName,$projectDOM,$PIpreview);
			$PIpreview->appendChild($projectDOM->createElement("Description"));
			$MISConfig->setNodeValue("Description",$p_reportDescription,$projectDOM,$PIpreview);
			$PIpreview->appendChild($projectDOM->createElement("Directory"));
			$MISConfig->setNodeValue("Directory",utf8_decode($PI->getElementsByTagName("Directory")->item(0)->nodeValue),$projectDOM,$PIpreview);
			$PIpreview->appendChild($projectDOM->createElement("Report"));
			$MISConfig->setNodeValue("Report",$p_pprReport."_Graf",$projectDOM,$PIpreview);			
			$PIpreview->appendChild($projectDOM->createElement("GIFGenerate"));
			$PIpreview->appendChild($projectDOM->createElement("JPGGenerate"));
			if($p_imageGenerate == "GIF") {
				$MISConfig->setNodeValue("GIFGenerate","J",$projectDOM,$PIpreview);
				$MISConfig->setNodeValue("JPGGenerate","N",$projectDOM,$PIpreview);
			}else{
				$MISConfig->setNodeValue("GIFGenerate","N",$projectDOM,$PIpreview);
				$MISConfig->setNodeValue("JPGGenerate","J",$projectDOM,$PIpreview);
			}
			$PIpreview->appendChild($projectDOM->createElement("PDFGenerate"));
			$MISConfig->setNodeValue("PDFGenerate",$p_pdfGenerate2,$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("XLSGenerate"));
			$MISConfig->setNodeValue("XLSGenerate",$p_xlsGenerate2,$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("Active"));
			$MISConfig->setNodeValue("Active","N",$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("SendEmail"));
			$MISConfig->setNodeValue("SendEmail","N",$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("ImageType"));
			$MISConfig->setNodeValue("ImageType",$p_imageType2,$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("ImageLayer"));
			$MISConfig->setNodeValue("ImageLayer",$p_imageLayer2,$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("PDFImageType"));
			$MISConfig->setNodeValue("PDFImageType",$p_pdfType2,$projectDOM,$PIpreview);	
			$PIpreview->appendChild($projectDOM->createElement("PDFImageLayer"));
			$MISConfig->setNodeValue("PDFImageLayer",$p_pdfLayer2,$projectDOM,$PIpreview);
			$PIpreview->appendChild($projectDOM->createElement("Ansicht"));
			$MISConfig->setNodeValue("Ansicht",$p_view,$projectDOM,$PIpreview);		
			$PIpreview->appendChild($projectDOM->createElement("Email"));
			$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PIpreview);
			$MISConfig->setNodeValue("ppx",$p_ppxFile,$projectDOM,$PIpreview);
			
			$PIs = $PI->parentNode;
			$PIs->appendChild($PIpreview);
		}
		
		$projectDOM->save($MISConfig->getConfigFile());
		

		
		$this->_registerEmails($p_email);
		if(count($IDArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editReport","'.implode("|",$IDArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configReportsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configReportsFormCb);';
		}
		return array($eval);
	}
	
	private function deleteReport($p_ID) {
		$MISConfig = new MISConfig();
		$IDArr = explode("|",$p_ID);
		$ID = explode("_",$IDArr[0]);
		$ID = $ID[0];
		
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
				
		$PPName = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image/Description[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/report.png">'.$PPName.' '.$this->_getI18N('deleteReport').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteReport"><input type="hidden" name="ID" value="'.utf8_encode($p_ID).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteReportInfoMsg1').' <i>'.$PPName.'</i> '.$this->_getI18N('deleteReportInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteReport($p_ID) {
		$MISConfig = new MISConfig();
		
		$IDArr = explode("|",$p_ID);

		
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		$dataDir = $projectXpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;
		foreach($IDArr as $ID) {
			$ID = explode("_",$ID);
			$ID = $ID[0];
			$PIList = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID="'.$ID.'"]');
			for($i=0;$i<$PIList->length;$i++) {
				@unlink(utf8_decode($dataDir.$PIList->item($i)->getElementsByTagName("Directory")->item(0)->nodeValue
					.$PIList->item($i)->parentNode->parentNode->getAttribute("Name")."\\"
					.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.".pdf"));
				@unlink(utf8_decode($dataDir.$PIList->item($i)->getElementsByTagName("Directory")->item(0)->nodeValue
					.$PIList->item($i)->parentNode->parentNode->getAttribute("Name")."\\"
					.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.".xls"));
				@unlink(utf8_decode($dataDir.$PIList->item($i)->getElementsByTagName("Directory")->item(0)->nodeValue
					.$PIList->item($i)->parentNode->parentNode->getAttribute("Name")."\\"
					.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.".gif"));
				@unlink(utf8_decode($dataDir.$PIList->item($i)->getElementsByTagName("Directory")->item(0)->nodeValue
					.$PIList->item($i)->parentNode->parentNode->getAttribute("Name")."\\"
					.$PIList->item($i)->getElementsByTagName("Name")->item(0)->nodeValue.".jpg"));
				$PIList->item($i)->parentNode->removeChild($PIList->item($i));
			}
		}
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configReportsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configReportsFormCb);');
	}
	
	private function createScorecard($p_sectionID,$p_username) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
				
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/scorecard.png">'.$this->_getI18N('createScorecard').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateScorecard"><input type="hidden" name="ID" value="'.$p_sectionID.'"><input type="hidden" name="username" value="'.utf8_encode($p_username).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createScorecardInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td><label for="inp_name">'.$this->_getI18N('scorecardName').':</label></td><td><input id="inp_name" name="name" type="text" value=""></td></tr>';
		$ret.= '<tr><td><label for="inp_description">'.$this->_getI18N('scorecardDescription').':</label></td><td><textarea id="inp_description" name="description"></textarea></td></tr>';
		$ret.= '<tr><td><label for="inp_active">'.$this->_getI18N('active').':</label></td><td>';
			$ret.= '<select id="inp_active" name="active"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('pprName').':</label></td><td>';
		$ret.= '<select name="pprname">';
		$PPRArr = $MISConfig->getAllPPR();
		foreach($PPRArr as $PPRName) {
			$ret.= '<option value="'.$PPRName.'">'.$PPRName.'</option>';		
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_rowData">'.$this->_getI18N('rowData').':</label></td><td><input id="inp_rowData" name="rowData" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_colData">'.$this->_getI18N('colData').':</label></td><td><input id="inp_colData" name="colData" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_hoherZielwert">'.$this->_getI18N('hoherZielwert').':</label></td><td>';
			$ret.= '<select id="inp_hoherZielwert" name="hoherZielwert"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_lowValue">'.$this->_getI18N('lowValue').':</label></td><td><input id="inp_lowValue" name="lowValue" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_highValue">'.$this->_getI18N('highValue').':</label></td><td><input id="inp_highValue" name="highValue" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_tolerance">'.$this->_getI18N('tolerance').':</label></td><td><input id="inp_tolerance" name="tolerance" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_format">'.$this->_getI18N('format').':</label></td><td>';
		$ret.= '<select name="format">';
		$PSFormatsArr = $MISConfig->getAllScorcardFormats();
		foreach($PSFormatsArr as $key => $PSFormat) {
			$ret.= '<option value="'.$key.'">'.$PSFormat.'</option>';		
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_weight">'.$this->_getI18N('weight').':</label></td><td><input id="inp_weight" name="weight" type="text" value="0"></td></tr>';
		$ret.= '<tr><td><label for="inp_monthlyAccumulate">'.$this->_getI18N('monthlyAccumulate').':</label></td><td>';
			$ret.= '<select id="inp_monthlyAccumulate" name="monthlyAccumulate"><option value="N">'.$this->_getI18N("no").'</option><option value="J">'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';		
		$ret.= '<tr><td><label for="inp_email">'.$this->_getI18N('email').':</label></td><td><input id="inp_email" name="email" type="text" value=""></td></tr>';
		$ret.= '<tr><td><label for="inp_infoURL">'.$this->_getI18N('infoURL').':</label></td><td><input id="inp_infoURL" name="infoURL" type="text" value=""></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateScorecard($p_sectionID,$p_username,$p_name,$p_description,$p_active,$p_pprReport,$p_rowData,$p_colData,$p_hoherZielwert,$p_lowValue,$p_highValue,$p_tolerance,$p_format,$p_weight,$p_monthlyAccumulate,$p_email,$p_infoURL) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$newID = $this->_generateReportID();
		
		$PRsList = $projectXpath->query("/Configuration/Scorecards/Scorecard/Reports[./../@ID='".$p_sectionID."' and ./../@Directory='".utf8_encode($p_username)."\\']");
		$PPName = $projectXpath->query("/Configuration/Publishes/Publish[./@ID='".$p_sectionID."']")->item(0)->getAttribute("Name");
		if($PRsList->length > 0) {
			$PRs = $PRsList->item(0);
		}else{
			$PS = $projectDOM->createElement("Scorecard");
			$PS->setAttribute("Directory",utf8_encode($p_username)."\\");
			$PS->setAttribute("ID",$p_sectionID);
			$PS->setAttribute("Name",utf8_encode($PPName));
			$PRs = $projectDOM->createElement("Reports");
			$PS->appendChild($PRs);
			$PSs = $projectXpath->query("/Configuration/Scorecards")->item(0);
			$PSs->appendChild($PS);
		}
		
		switch($p_format) {
			case 0: $format = "Ganzzahlig";
				break;
			case 1: $format = "Zahl mit Trennz";
				break;
			case 2: $format = "Zahl ohne Trennz";
				break;
			case 3: $format = utf8_decode("Währung");
				break;
			case 4: $format = "Prozent";
				break;
		}
		
		$PR = $projectDOM->createElement("Report");
		$PR->setAttribute("ID",$newID);
		$MISConfig->setNodeValue("Name",$p_name,$projectDOM,$PR);
		$MISConfig->setNodeValue("Description",$p_description,$projectDOM,$PR);
		$MISConfig->setNodeValue("Active",$p_active,$projectDOM,$PR);
		$MISConfig->setNodeValue("ReportFile",$p_pprReport,$projectDOM,$PR);
		$MISConfig->setNodeValue("RowData",$p_rowData,$projectDOM,$PR);
		$MISConfig->setNodeValue("ColData",$p_colData,$projectDOM,$PR);
		$MISConfig->setNodeValue("HoherZielwert",$p_hoherZielwert,$projectDOM,$PR);
		$MISConfig->setNodeValue("LowValue",$p_lowValue,$projectDOM,$PR);
		$MISConfig->setNodeValue("HighValue",$p_highValue,$projectDOM,$PR);
		$MISConfig->setNodeValue("Tolerance",$p_tolerance,$projectDOM,$PR);
		$MISConfig->setNodeValue("Format",$format,$projectDOM,$PR);
		$MISConfig->setNodeValue("Weight",$p_weight,$projectDOM,$PR);
		$MISConfig->setNodeValue("MonthlyAccumulate",$p_monthlyAccumulate,$projectDOM,$PR);
		$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PR);
		$MISConfig->setNodeValue("InfoURL",$p_infoURL,$projectDOM,$PR);
		
		$PRs->appendChild($PR);
		
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configScorecardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configScorecardsFormCb);');
	}
	
	private function editScorecard($p_ID) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$ID = $IDArr[0];
		$username = $IDArr[1];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	

		$PR = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./@ID="'.$ID.'"]')->item(0);
		
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/scorecard.png">'.$PR->getElementsByTagName("Name")->item(0)->nodeValue.' '.$this->_getI18N('editScorecard').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveEditScorecard"><input type="hidden" name="ID" value="'.$p_ID.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editScorecardInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td><label for="inp_name">'.$this->_getI18N('scorecardName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.$PR->getElementsByTagName("Name")->item(0)->nodeValue.'"></td></tr>';
		$ret.= '<tr><td><label for="inp_description">'.$this->_getI18N('scorecardDescription').':</label></td><td><textarea id="inp_description" name="description">'.$PR->getElementsByTagName("Description")->item(0)->nodeValue.'</textarea></td></tr>';
		$ret.= '<tr><td><label for="inp_active">'.$this->_getI18N('active').':</label></td><td>';
			$ret.= '<select id="inp_active" name="active"><option value="N">'.$this->_getI18N("no").'</option><option value="J"';
			if($PR->getElementsByTagName("Active")->item(0)->nodeValue == "J") $ret.= " selected='selected'";
			$ret.= '>'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('pprName').':</label></td><td>';
		$ret.= '<select name="pprname">';
		$PPRArr = $MISConfig->getAllPPR();
		foreach($PPRArr as $PPRName) {
			$ret.= '<option';
			if(strtoupper($PPRName) == strtoupper($PR->getElementsByTagName("ReportFile")->item(0)->nodeValue)) $ret.= ' selected="selected"';
			$ret.= ' value="'.$PPRName.'">'.$PPRName.'</option>';		
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= "<tr><td><label for='inp_rowData'>".$this->_getI18N('rowData').":</label></td><td><input id='inp_rowData' name='rowData' type='text' value='".$PR->getElementsByTagName("RowData")->item(0)->nodeValue."'></td></tr>";
		$ret.= "<tr><td><label for='inp_colData'>".$this->_getI18N('colData').":</label></td><td><input id='inp_colData' name='colData' type='text' value='".$PR->getElementsByTagName("ColData")->item(0)->nodeValue."'></td></tr>";
		$ret.= '<tr><td><label for="inp_hoherZielwert">'.$this->_getI18N('hoherZielwert').':</label></td><td>';
			$ret.= '<select id="inp_hoherZielwert" name="hoherZielwert"><option value="N">'.$this->_getI18N("no").'</option><option value="J"';
			if($PR->getElementsByTagName("HoherZielwert")->item(0)->nodeValue == "J") $ret.= " selected='selected'";
			$ret.= '>'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';
		$ret.= "<tr><td><label for='inp_lowValue'>".$this->_getI18N('lowValue').":</label></td><td><input id='inp_lowValue' name='lowValue' type='text' value='".$PR->getElementsByTagName("LowValue")->item(0)->nodeValue."'></td></tr>";
		$ret.= "<tr><td><label for='inp_highValue'>".$this->_getI18N('highValue').":</label></td><td><input id='inp_highValue' name='highValue' type='text' value='".$PR->getElementsByTagName("HighValue")->item(0)->nodeValue."'></td></tr>";
		$ret.= "<tr><td><label for='inp_tolerance'>".$this->_getI18N('tolerance').":</label></td><td><input id='inp_tolerance' name='tolerance' type='text' value='".$PR->getElementsByTagName("Tolerance")->item(0)->nodeValue."'></td></tr>";
		$ret.= "<tr><td><label for='inp_format'>".$this->_getI18N('format').":</label></td><td>";
		$ret.= "<select name='format'>";
		$PSFormatsArr = $MISConfig->getAllScorcardFormats();
	      switch($PR->getElementsByTagName("Format")->item(0)->nodeValue) {
            case "Ganzzahlig":$sec_key = 0;
                break;
            case "Zahl mit Trennz": $sec_key = 1;
                break;
            case "Zahl ohne Trennz": $sec_key = 2;
                break;
            case "Währung":$sec_key = 3;
                break;
            case "Prozent":$sec_key = 4;
                break;
        }
		
		foreach($PSFormatsArr as $key => $PSFormat) {
			$ret.= '<option value="'.$key.'"';
			if($key == $sec_key)$ret.= ' selected="selected"';
			$ret.= '>'.$PSFormat.'</option>';		 
		}
		$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td><label for="inp_weight">'.$this->_getI18N('weight').':</label></td><td><input id="inp_weight" name="weight" type="text" value="'.$PR->getElementsByTagName("Weight")->item(0)->nodeValue.'"></td></tr>';
		$ret.= '<tr><td><label for="inp_monthlyAccumulate">'.$this->_getI18N('monthlyAccumulate').':</label></td><td>';
			$ret.= '<select id="inp_monthlyAccumulate" name="monthlyAccumulate"><option value="N">'.$this->_getI18N("no").'</option><option value="J"';
			if($PR->getElementsByTagName("MonthlyAccumulate")->item(0)->nodeValue == "J")$ret.= ' selected="selected"';
			$ret.= '>'.$this->_getI18N("yes").'</option></select>';
		$ret.= '</td></tr>';		
		$ret.= '<tr><td><label for="inp_email">'.$this->_getI18N('email').':</label></td><td><input id="inp_email" name="email" type="text" value="'.$PR->getElementsByTagName("Email")->item(0)->nodeValue.'"></td></tr>';
		$ret.= '<tr><td><label for="inp_infoURL">'.$this->_getI18N('infoURL').':</label></td><td><input id="inp_infoURL" name="infoURL" type="text" value="'.$PR->getElementsByTagName("InfoURL")->item(0)->nodeValue.'"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveEditScorecard($p_ID,$p_name,$p_description,$p_active,$p_pprReport,$p_rowData,$p_colData,$p_hoherZielwert,$p_lowValue,$p_highValue,$p_tolerance,$p_format,$p_weight,$p_monthlyAccumulate,$p_email,$p_infoURL) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",array_shift($IDsArr));
		$ID = $IDArr[0];
		$username = $IDArr[1];	
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$PR = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./@ID = "'.$ID.'"]')->item(0);
	        switch($p_format) {
            case 0: $format = "Ganzzahlig";
                break;
            case 1: $format = "Zahl mit Trennz";
                break;
            case 2: $format = "Zahl ohne Trennz";
                break;
            case 3: $format = utf8_decode("Währung");
                break;
            case 4: $format = "Prozent";
                break;
        }
		$MISConfig->setNodeValue("Name",$p_name,$projectDOM,$PR);
		$MISConfig->setNodeValue("Description",$p_description,$projectDOM,$PR);
		$MISConfig->setNodeValue("Active",$p_active,$projectDOM,$PR);
		$MISConfig->setNodeValue("ReportFile",$p_pprReport,$projectDOM,$PR);
		$MISConfig->setNodeValue("RowData",$p_rowData,$projectDOM,$PR);
		$MISConfig->setNodeValue("ColData",$p_colData,$projectDOM,$PR);
		$MISConfig->setNodeValue("HoherZielwert",$p_hoherZielwert,$projectDOM,$PR);
		$MISConfig->setNodeValue("LowValue",$p_lowValue,$projectDOM,$PR);
		$MISConfig->setNodeValue("HighValue",$p_highValue,$projectDOM,$PR);
		$MISConfig->setNodeValue("Tolerance",$p_tolerance,$projectDOM,$PR);
		$MISConfig->setNodeValue("Format",$format,$projectDOM,$PR);
		$MISConfig->setNodeValue("Weight",$p_weight,$projectDOM,$PR);
		$MISConfig->setNodeValue("MonthlyAccumulate",$p_monthlyAccumulate,$projectDOM,$PR);
		$MISConfig->setNodeValue("Email",$p_email,$projectDOM,$PR);
		$MISConfig->setNodeValue("InfoURL",$p_infoURL,$projectDOM,$PR);
		
		$projectDOM->save($MISConfig->getConfigFile());
		if(count($IDsArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editScorecard","'.implode("|",$IDsArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configScorecardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configScorecardsFormCb);';
		}
		return array($eval);		
	}
	
	private function deleteScorecard($p_ID) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$ID = $IDArr[0];
		$username = $IDArr[1];
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
				
		$PPName = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report/Name[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend>'.$this->_getI18N('deleteScorecard').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteScorecard"><input type="hidden" name="ID" value="'.$p_ID.'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteScorecardInfoMsg1').' <i>'.$PPName.'</i> '.$this->_getI18N('deleteScorecardInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteScorecard($p_ID) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		foreach($IDsArr as $IDStr) {
			$IDArr = explode("_",$IDStr);
			$ID = $IDArr[0];
			$PIList = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./@ID="'.$ID.'"]');
			for($i=0;$i<$PIList->length;$i++) {
				$PIList->item($i)->parentNode->removeChild($PIList->item($i));
			}
		}
		
		$projectDOM->save($MISConfig->getConfigFile());
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configScorecardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configScorecardsFormCb);');
	}
	
    private function editLanguage($p_app,$p_key="") {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load(Filesystem::standardDirFormat(Core::getAppsDir().$p_app).$p_app.".i18n.xml");
        $projectXpath = new DOMXpath($projectDOM);
            
        
        
                
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
        $ret.= '<fieldset>';
        $ret.= '<legend>'.$this->_getI18N('editLanguage').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveEditLanguage"><input type="hidden" id="save" name="save" value="save"><input type="hidden" name="app" value="'.$p_app.'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editLanguageInfoMsg1').' <i>'.$p_app.'</i>.<hr></td></tr>';
        $ret.= '<tr><td><select id="akey" size="20" onchange="MISConfigurator.loadTranslation(\''.$p_app.'\',this.value);">';
       // $ret.=$keys->item(0);
        $keys = $projectXpath->query("/i18n")->item(0)->childNodes;
        foreach($keys as $domNodeList) {
        	if($domNodeList->nodeName != "#text")
        	$ret.= '<option value="'.$domNodeList->nodeName.'">'.$domNodeList->nodeName.'</option>';
        }
        $ret.= '</select></td><td>';
        $langs = I18N::getLanguages();
        foreach($langs as $lang) {
            $ret.= '<p><div style="width:100px;float:left;">'.$lang.':</div> <input id="translation_'.$lang.'" type="text" style="width:250px"></input></p>';
        }
        $ret.= '</td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" onclick="Browser.getElementById(\'save\').value=\'apply\';" type="submit" value="'.$this->_getI18N('apply').'"><input class="btn" type="submit" onclick="Browser.getElementById(\'save\').value=\'save\';" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
    public function loadTranslation($p_app,$p_key) {

        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load(Filesystem::standardDirFormat(Core::getAppsDir().$p_app).$p_app.".i18n.xml");
        $projectXpath = new DOMXpath($projectDOM);
        
        $translation = $projectXpath->query("/i18n/".$p_key);
        $translation = $translation->item(0);
$childs = $translation->childNodes;
$langs = I18N::getLanguages();
foreach($langs as $lang) {
	$ret[] = $lang;
	$ret[] = "";
}
        foreach($childs as $node) {
        	if($node->nodeName != "#text") {
        	$ret[] = $node->nodeName;
        	$ret[] = $node->nodeValue;
        	}
        }
        return $ret;
    }
    
    private function saveEditLanguage($p_save,$p_app,$p_key,$p_value_de,$p_value_en,$p_value_fr,$p_value_it) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load(Filesystem::standardDirFormat(Core::getAppsDir().$p_app).$p_app.".i18n.xml");
        $projectXpath = new DOMXpath($projectDOM);
        $translation = $projectXpath->query("/i18n/".$p_key)->item(0);
        $MISConfig->setNodeValue("de",$p_value_de,$projectDOM,$translation);
        $MISConfig->setNodeValue("en",$p_value_en,$projectDOM,$translation);
        $MISConfig->setNodeValue("fr",$p_value_fr,$projectDOM,$translation);
        $MISConfig->setNodeValue("it",$p_value_it,$projectDOM,$translation);

        $projectDOM->save(Filesystem::standardDirFormat(Core::getAppsDir().$p_app).$p_app.".i18n.xml");
        if($p_save == "save") {
        return array('CMgr.getMODEL().__construct();');
        }else{
        	return "";
        }
    }
	
	private function createUser(){
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'username\',\'password\',\'password_repeat\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('createUser').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveCreateUser">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createUserInfoMsg').'<hr></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('username').':</label></td><td><input id="inp_name" name="username" type="text" value=""></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_pw">'.$this->_getI18N('password').':</label></td><td><input id="inp_pw" name="password" type="password" value=""></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_password_repeat">'.$this->_getI18N('passwordRepeat').':</label></td><td><input id="inp_password_repeat" name="password_repeat" type="password" value=""></td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_lang">'.$this->_getI18N('lang').':</label></td><td>';
			$ret.= '<select id="inp_lang" name="lang">';
			$allLangsArr = $MISConfig->getAllLangs();
			foreach($allLangsArr as $key => $lang) {
				$ret.= '<option value="'.$key.'">'.$lang.'</option>';
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_view">'.$this->_getI18N('view').':</label></td><td>';
			$ret.= '<select id="inp_view" name="view">';
			$allViewsArr = $MISConfig->getAllViews();
			foreach($allViewsArr as $key => $view) {
				$ret.= '<option value="'.$key.'">'.utf8_encode($view).'</option>';
			}
			$ret.= '</select>';
		$ret.= '</td></tr>';
		$ret.= '<tr><td class="label"><label for="inp_global">'.$this->_getI18N('global_user').':</label></td><td><input id="inp_global" name="global" type="checkbox"></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveCreateUser($p_username,$p_password,$p_passwordRepeat,$p_lang,$p_view,$p_global="false") {
		if($this->isRole("master")) {
		$MISConfig = new MISConfig();
		
		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
		$authDOM->load($MISConfig->authFile);
		$authXpath = new DOMXpath($authDOM);
		
		$userUnique = $authXpath->query("/auth/users/user[./@username='".utf8_encode($p_username)."' and (@setting='".basename($MISConfig->getConfigFile(),".xml")."' or @setting='')]");
		
		if($p_password != $p_passwordRepeat)
			return array('alert("'.$this->_getI18N("pw_not_equal").'");');
		if($userUnique->length > 0)
			return array('alert("'.$this->_getI18N("user_not_unique").'");');
		if(!strpbrk($p_username, "_") === false)
			return array('alert("'.$this->_getI18N("no_underscore_allowed").'");');
		if(!strpbrk($p_username, "|") === false)
			return array('alert("'.$this->_getI18N("no_vert_dash_allowed").'");');
		$UU = $authDOM->createElement('user');
		$UU->setAttribute('username',utf8_encode($p_username));
		$UU->setAttribute('password',md5($p_password));
		$UU->setAttribute('global',$p_global);
		$UU->setAttribute('lang',$p_lang);
		$UU->setAttribute('view',$p_view);
		$UU->setAttribute('setting',basename($MISConfig->getConfigFile(),".xml"));
		
		$users = $authXpath->query("/auth/users")->item(0);
		$users->appendChild($UU);

		$authDOM->save($MISConfig->authFile);
		}
		return array('CMgr.getMODEL().__construct();');
	}
	
	private function editUser($p_ID) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$username = $IDsArr[0];
		$ret="";
		$eval="";
		if(count($IDArr)==1) {
			$authDOM = new DOMDocument('1.0', 'iso-8859-1');
			$authDOM->load($MISConfig->authFile);
			$authXpath = new DOMXpath($authDOM);
		
			$AU = $authXpath->query("/auth/users/user[@username='".utf8_encode($username)."']")->item(0);
		
			$ret.= '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'username\',\'password\',\'password_repeat\');">';
			$ret.= '<fieldset>';
	
			$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('editUser').'</legend>';
			$ret.= '<input type="hidden" name="saveMethod" value="saveEditUser"><input type="hidden" name="name" value="'.utf8_encode($p_ID).'">';
			$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editUserInfoMsg').'<hr></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('username').':</label></td><td><input id="inp_name" name="username" type="text" value="'.$AU->getAttribute("username").'"></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_pw">'.$this->_getI18N('password').':</label></td><td><input id="inp_pw" name="password" type="password" value="     "></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_pw_repeat">'.$this->_getI18N('passwordRepeat').':</label></td><td><input id="inp_pw_repeat" name="password_repeat" type="password" value="     "></td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_lang">'.$this->_getI18N('lang').':</label></td><td>';
				$ret.= '<select id="inp_lang" name="lang">';
				$allLangsArr = $MISConfig->getAllLangs();
				foreach($allLangsArr as $key => $lang) {
					if($AU->getAttribute("lang") == $key)
					$ret.= '<option value="'.$key.'" selected="selected">'.$lang.'</option>';
					else
					$ret.= '<option value="'.$key.'">'.$lang.'</option>';
				}
				$ret.= '</select>';
			$ret.= '</td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_view">'.$this->_getI18N('view').':</label></td><td>';
				$ret.= '<select id="inp_view" name="view"';
				if(!$this->isRole("master")){
					$ret.= ' disabled="disabled" ';
				}
				$ret.='>';
				$allViewsArr = $MISConfig->getAllViews();
				foreach($allViewsArr as $key => $view) {
					if($AU->getAttribute("view") == $key)
					$ret.= '<option value="'.$key.'" selected="selected">'.utf8_encode($view).'</option>';
					else
					$ret.= '<option value="'.$key.'">'.utf8_encode($view).'</option>';
				}
				$ret.= '</select>';
			$ret.= '</td></tr>';
			$ret.= '<tr><td class="label"><label for="inp_global">'.$this->_getI18N('global_user').':</label></td><td><input id="inp_global" name="global" type="checkbox"';
				if(!$this->isRole("master")){
					$ret.= ' disabled="disabled" ';
				}	
				if($AU->getAttribute("global") == "true") $ret.=' checked="checked"';
			$ret.='></td></tr>';
			$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
			$ret.= '</table>';
			
			$ret.= '</fieldset>';
			$ret.= '</form>';
		}else{
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editSection","'.$p_ID.'");';
		}
		return array($ret,$eval);
	}
	
	private function saveEditUser($p_ID,$p_newUsername,$p_password,$p_passwordRepeat,$p_lang,$p_view="Info-User",$p_global="false") {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
		
		$IDsArr = explode("|",$p_ID);
		
		$dataDir = $projectXpath->query('/Configuration/General/PublishImagePath')->item(0)->nodeValue;
		

		
		$username = utf8_encode(array_shift($IDsArr));

		$newUsername = utf8_encode($p_newUsername);
		
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	

		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
		$authDOM->load($MISConfig->authFile);
		$authXpath = new DOMXpath($authDOM);

		$userUnique = $authXpath->query("/auth/users/user[./@username='".$newUsername."' and (@setting='".basename($MISConfig->getConfigFile(),".xml")."' or @setting='')]");
		
		if($p_password != $p_passwordRepeat)
			return array('alert("'.$this->_getI18N("pw_not_equal").'");');
		if($newUsername != $username && $userUnique->length > 0)
			return array('alert("'.$this->_getI18N("user_not_unique").'");');
		if(!strpbrk($p_newUsername, "_") === false)
			return array('alert("'.$this->_getI18N("no_underscore_allowed").'");');
		if(!strpbrk($p_newUsername, "|") === false)
			return array('alert("'.$this->_getI18N("no_vert_dash_allowed").'");');
		$UU = $authXpath->query("/auth/users/user[@username='".$username."' and (@setting='".basename($MISConfig->getConfigFile(),".xml")."' or @setting='')]")->item(0);
		$UU->setAttribute("username",$newUsername);
		$UU->setAttribute('lang',$p_lang);
		if($this->isRole("master")) {
		  $UU->setAttribute('view',$p_view);
		  $UU->setAttribute('global',$p_global);
		}

		if($p_password != "     ") $UU->setAttribute('password',md5($p_password));
		
		$PIList = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Directory='".$username."\\']");
		for($i=0;$i<$PIList->length;$i++) {
			$PI = $PIList->item($i);
			$MISConfig->setNodeValue("Directory",utf8_decode($newUsername)."\\",$projectDOM,$PI);
		}
	    $PIList = $projectXpath->query("/Configuration/Publishes/Publish[./@User='".$username."']");
        for($i=0;$i<$PIList->length;$i++) {
            $PI = $PIList->item($i);
            $PI->setAttribute("User",$newUsername);
        }
		$PSList = $projectXpath->query("/Configuration/Scorecards/Scorecard[./@Directory='".$username."\\']");
		for($i=0;$i<$PSList->length;$i++){
			$PS = $PSList->item($i);
			$PS->setAttribute("Directory",$newUsername."\\");
		}
	    $PSList = $projectXpath->query("/Configuration/Dashboards/Dashboard[./@Directory='".$username."\\']");
        for($i=0;$i<$PSList->length;$i++){
            $PS = $PSList->item($i);
            $PS->setAttribute("Directory",$newUsername."\\");
        }
		$projectDOM->save($MISConfig->getConfigFile());
		$authDOM->save($MISConfig->authFile);
		@rename(utf8_decode($dataDir.$username)."\\",
				utf8_decode($dataDir.$newUsername)."\\");
	    if(count($IDsArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editUser","'.implode("|",$IDsArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().__construct();';
		}
		
		return array($eval);
	}
	
	private function deleteUser($p_ID) {
		$usernames = array();	
		$IDsArr = explode("|",$p_ID);
		$deleteSections = false;
		$newIDsArr = array();
		foreach($IDsArr as $IDStr){
			$IDArr = explode("_",$IDStr);
			if(count($IDArr)==1) {
				$username = $IDArr[0];
				array_push($usernames, utf8_encode($username));
			}else{
				$deleteSections = true;
				array_push($newIDsArr,$IDStr);
			}
		}	
		$ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		$ret.= '<legend><img src="img/personal.png">'.$this->_getI18N('deleteUser').'</legend>';
		$ret.= '<input type="hidden" name="saveMethod" value="saveDeleteUser"><input type="hidden" name="username" value="'.utf8_encode($p_ID).'">';
		$ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteUserInfoMsg1').' <i>'.implode(", ",$usernames).'</i> '.$this->_getI18N('deleteUserInfoMsg2').'<hr></td></tr>';
		$ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="';
		if($deleteSections) {
			$ret.='CMgr.getMODEL().getRetrieveInput(\'MISConfigurator\',\'deleteSection\',\''.implode("|",$newIDsArr).'\');';
		}else{
			$ret.='CMgr.getMODEL().abortRetrieveInput();';
		}
		$ret.= '"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
		$ret.= '</table>';
		
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
	private function saveDeleteUser($p_ID) {
		$MISConfig = new MISConfig();
		$IDsArr = explode("|",$p_ID);
		$newIDsArr = Array();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);	
		
		$authDOM = new DOMDocument('1.0', 'iso-8859-1');
		$authDOM->load($MISConfig->authFile);
		$authXpath = new DOMXpath($authDOM);
		foreach($IDsArr as $IDStr) {
			$IDArr = explode("_",$IDStr);
			if(count($IDArr)==1){
				$username = utf8_encode($IDArr[0]);
				$AU = $authXpath->query("/auth/users/user[@username='".$username."' and @setting='".basename($MISConfig->getConfigFile(),".xml")."']")->item(0);
				$AU->parentNode->removeChild($AU);
				
				$PIList = $projectXpath->query("/Configuration/Publishes/Publish[./@User='".$username."']");
				for($i=0;$i<$PIList->length;$i++) {
					$PI = $PIList->item($i);
					$PI->parentNode->removeChild($PI);
				}
				$PSList = $projectXpath->query("/Configuration/Scorecards/Scorecard[./@Directory='".$username."\\']");
				for($i=0;$i<$PSList->length;$i++){
					$PS = $PSList->item($i);
					$PS->parentNode->removeChild($PS);
				}
			    $PSList = $projectXpath->query("/Configuration/Dashboards/Dashboard[./@Directory='".$username."\\']");
		        for($i=0;$i<$PSList->length;$i++){
		            $PS = $PSList->item($i);
		            $PS->parentNode->removeChild($PS);
		        }
			}else{
				array_push($newIDsArr,$IDStr);
			}
		}
		$success = $this->deleteDir($projectXpath->query("/Configuration/General/PublishImagePath")->item(0)->nodeValue.$username."\\");
		$projectDOM->save($MISConfig->getConfigFile());
		$authDOM->save($MISConfig->authFile);
		$eval = "";
		if($success != 0 && $success != -1) {
			$eval.='alert("'.$this->_getI18N("deleteDataFolderManually").'");';
		}
		if(count($newIDsArr)>0){
			$eval.='CMgr.getMODEL().__construct();CMgr.getMODEL().getRetrieveInput("MISConfigurator","deleteSection","'.implode("|",$newIDsArr).'");';
		}else{
			$eval.='CMgr.getMODEL().__construct();';
		}
		return array($eval);
	}
	
	private function createDashboard($p_sectionID,$p_username) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);  
                
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/dashboard.png">'.$this->_getI18N('createDashboard').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveCreateDashboard"><input type="hidden" name="ID" value="'.$p_sectionID.'"><input type="hidden" name="username" value="'.utf8_encode($p_username).'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createDashboardInfoMsg').'<hr></td></tr>';
        $ret.= '<tr><td><label for="inp_name">'.$this->_getI18N('dashboardName').':</label></td><td><input id="inp_name" name="name" type="text" value=""></td></tr>';
        $ret.= '<tr><td><label for="inp_description">'.$this->_getI18N('dashboardDescription').':</label></td><td><textarea id="inp_description" name="description"></textarea></td></tr>';

        $ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('dashboardReport').':</label></td><td>';
        $ret.= '<select name="pprname">';
        $PPRArr = $this->_getAllDashboards();
        foreach($PPRArr as $PPRName) {
            $ret.= '<option value="'.$PPRName.'">'.$PPRName.'</option>';        
        }
        $ret.= '</select>';
        $ret.= '</td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
	}
	
	private function saveCreateDashboard($p_sectionID,$p_username,$p_name,$p_description,$p_xlsReport) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        $newID = $this->_generateReportID();
        
        $PRsList = $projectXpath->query("/Configuration/Dashboards/Dashboard[./@ID='".$p_sectionID."' and ./@Directory='".utf8_encode($p_username)."\\']");
        $PPName = $projectXpath->query("/Configuration/Publishes/Publish[./@ID='".$p_sectionID."']")->item(0)->getAttribute("Name");
        if($PRsList->length > 0) {
            $PRs = $PRsList->item(0);
        }else{
        	return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);');
        }
        
        $PR = $projectDOM->createElement("Review");
        $PR->setAttribute("ID",$newID);
        $MISConfig->setNodeValue("Name",$p_name,$projectDOM,$PR);
        $MISConfig->setNodeValue("Description",$p_description,$projectDOM,$PR);
        $MISConfig->setNodeValue("ReportFile",$p_xlsReport,$projectDOM,$PR);
        
        $PRs->getElementsByTagname("Reviews")->item(0)->appendChild($PR);
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);');
	}
	
    private function deleteDashboard($p_ID) {
        $MISConfig = new MISConfig();
        $IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$ID = $IDArr[0];
		$username = $IDArr[1];
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
                
        $PPName = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review/Name[./../@ID="'.$ID.'"]')->item(0)->nodeValue;
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/dashboard.png">'.$this->_getI18N('deleteDashboard').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveDeleteDashboard"><input type="hidden" name="ID" value="'.$p_ID.'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteDashboardInfoMsg1').' <i>'.$PPName.'</i> '.$this->_getI18N('deleteDashboardInfoMsg2').'<hr></td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
        $ret.= '</table>';
        
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
    
    private function saveDeleteDashboard($p_ID) {
        $MISConfig = new MISConfig();
        $IDsArr = explode("|",$p_ID);
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        foreach($IDsArr as $IDStr) {
			$IDArr = explode("_",$IDStr);
			$ID = $IDArr[0];
	        $PIList = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID="'.$ID.'"]');
	        for($i=0;$i<$PIList->length;$i++) {
	            $PIList->item($i)->parentNode->removeChild($PIList->item($i));
	        }
        }
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);');
    }
    
    private function editDashboard($p_ID) {
        $MISConfig = new MISConfig();
        $IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",$IDsArr[0]);
		$ID = $IDArr[0];
		$username = $IDArr[1];
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);  

        $PR = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID="'.$ID.'"]')->item(0);
        
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/dashboard.png">'.$PR->getElementsByTagName("Name")->item(0)->nodeValue.' '.$this->_getI18N('editDashboard').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveEditDashboard"><input type="hidden" name="ID" value="'.$p_ID.'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editDashboardInfoMsg').'<hr></td></tr>';
        $ret.= '<tr><td><label for="inp_name">'.$this->_getI18N('dashboardName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.$PR->getElementsByTagName("Name")->item(0)->nodeValue.'"></td></tr>';
        $ret.= '<tr><td><label for="inp_description">'.$this->_getI18N('dashboardDescription').':</label></td><td><textarea id="inp_description" name="description">'.$PR->getElementsByTagName("Description")->item(0)->nodeValue.'</textarea></td></tr>';
        $ret.= '<tr><td><label for="inp_pprname">'.$this->_getI18N('dashboardReport').':</label></td><td>';
        $ret.= '<select name="pprname">';
        $PPRArr = $this->_getAllDashboards();
        foreach($PPRArr as $PPRName) {
            $ret.= '<option';
            if(strtoupper($PPRName) == strtoupper($PR->getElementsByTagName("ReportFile")->item(0)->nodeValue)) $ret.= ' selected="selected"';
            $ret.= ' value="'.$PPRName.'">'.$PPRName.'</option>';       
        }
        $ret.= '</select>';
        $ret.= '</td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
    
    private function saveEditDashboard($p_ID,$p_name,$p_description,$p_pprReport) {
        $MISConfig = new MISConfig();
        $IDsArr = explode("|",$p_ID);
		$IDArr = explode("_",array_shift($IDsArr));
		$ID = $IDArr[0];
		$username = $IDArr[1];
		 
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        $PR = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID = "'.$ID.'"]')->item(0);

        $MISConfig->setNodeValue("Name",$p_name,$projectDOM,$PR);
        $MISConfig->setNodeValue("Description",$p_description,$projectDOM,$PR);
        $MISConfig->setNodeValue("ReportFile",$p_pprReport,$projectDOM,$PR);

        $projectDOM->save($MISConfig->getConfigFile());
    	if(count($IDsArr)>0){
			$eval = 'CMgr.getMODEL().getRetrieveInput("MISConfigurator","editDashboard","'.implode("|",$IDsArr).'");';
		}else{
			$eval = 'CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);';
		}
        return array($eval);     
    }
    
    private function createView() {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);  
                
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/view.png">'.$this->_getI18N('createView').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveCreateView">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('createViewInfoMsg').'<hr></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('viewName').':</label></td><td><input id="inp_name" name="name" type="text" value=""></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_description">'.$this->_getI18N('viewDescription').':</label></td><td><textarea id="inp_description" name="description"></textarea></td></tr>';

        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
    
    private function saveCreateView($p_name,$p_description) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        $newID = $this->_generateReportID();
        
        $Version = $projectXpath->query("/Configuration/Version")->item(0);
        
        $PR = $projectDOM->createElement("View");
        $PR->setAttribute("ID",$newID);
        $MISConfig->setNodeValue("Name",$p_name,$projectDOM,$PR);
        $MISConfig->setNodeValue("Description",$p_description,$projectDOM,$PR);
        
        $Version->getElementsByTagname("Views")->item(0)->appendChild($PR);
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().__construct();');
    }
    
    private function editView($p_ID){
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);  
        
        $PR = $projectXpath->query('/Configuration/Version/Views/View[./@ID="'.$p_ID.'"]')->item(0);
        
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\',\'name\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/view.png">'.$this->_getI18N('editView').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveEditView">';
        $ret.= '<input type="hidden" name="ID" value="'.$p_ID.'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('editViewInfoMsg').'<hr></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_name">'.$this->_getI18N('viewName').':</label></td><td><input id="inp_name" name="name" type="text" value="'.$PR->getElementsByTagName("Name")->item(0)->nodeValue.'"></td></tr>';
        $ret.= '<tr><td class="label"><label for="inp_description">'.$this->_getI18N('viewDescription').':</label></td><td><textarea id="inp_description" name="description">'.$PR->getElementsByTagName("Description")->item(0)->nodeValue.'</textarea></td></tr>';

        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="reset" value="'.$this->_getI18N("reset").'"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
        $ret.= '</table>';
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
    
    private function saveEditView($p_ID,$p_name,$p_description) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        $Version = $projectXpath->query("/Configuration/Version/Views/View[./@ID='".$p_ID."']")->item(0);
        

        $MISConfig->setNodeValue("Name",$p_name,$projectDOM,$Version);
        $MISConfig->setNodeValue("Description",$p_description,$projectDOM,$Version);
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().__construct();');
    }
    
    private function deleteView($p_ID) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
                
        $PPName = $projectXpath->query('/Configuration/Version/Views/View[./@ID="'.$p_ID.'"]/Name')->item(0)->nodeValue;
        $ret = '<form action="" encoding="utf-8" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
        $ret.= '<fieldset>';

        $ret.= '<legend><img src="img/dashboard.png">'.$this->_getI18N('deleteView').'</legend>';
        $ret.= '<input type="hidden" name="saveMethod" value="saveDeleteView"><input type="hidden" name="ID" value="'.$p_ID.'">';
        $ret.= '<table><tr><td colspan="2">'.$this->_getI18N('deleteViewInfoMsg1').' <i>'.$PPName.'</i> '.$this->_getI18N('deleteViewInfoMsg2').'<hr></td></tr>';
        $ret.= '<tr><td colspan="2"><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('delete').'"></td></tr>';
        $ret.= '</table>';
        
        $ret.= '</fieldset>';
        $ret.= '</form>';
        return array($ret,'');
    }
	
    private function saveDeleteView($p_ID){
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);
        
        $PIList = $projectXpath->query('/Configuration/Version/Views/View[./@ID="'.$p_ID.'"]');
        for($i=0;$i<$PIList->length;$i++) {
            $PIList->item($i)->parentNode->removeChild($PIList->item($i));
        }
        
        $projectDOM->save($MISConfig->getConfigFile());
        return array('CMgr.getMODEL().__construct();');
    }
    
	private function dragAndDrop($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		if($p_dragType == "emailReport" && ($p_dropType == "emailUser")) {
            return $this->createEmailReportForm2($p_dropID,$p_dragID);
        }
		if($p_dragType == "emailUser" && ($p_dropType == "emailUser")) {
			$ImageList = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active='J' and ./SendEmail='J' and ./Email!='']");
        
	        $emailArr = array();
	        for($i=0;$i < $ImageList->length;$i++) {
	        	$Image = $ImageList->item($i);
	        	$ImageEmailArr = explode(";",$Image->getElementsByTagName("Email")->item(0)->nodeValue);
	            
	            foreach($ImageEmailArr as $email) {
		            if(!array_key_exists(trim($email), $emailArr)) {
		            	$emailArr[trim($email)] = array();
		            }
		            $emailArr[trim($email)][trim($Image->getElementsByTagName("Name")->item(0)->nodeValue)] = $Image->getAttribute("ID");
	            }
	        }
	        
	        $ImageIDs = implode("|",$emailArr[$p_dragID]);
	        
            return $this->createEmailReportForm2($p_dropID,$ImageIDs);
        }
		
		$ret = '<form action="" method="post" onSubmit="return Form.submit(this,\'MISConfigurator\',\'saveRetrieveInput\');">';
		$ret.= '<fieldset>';

		if($p_dragType == "section" && $p_dropType == "section") {
			$p_dragIDArr = explode("_",$p_dragID);
			$p_dropIDArr = explode("_",$p_dropID);
			$dragPP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'"]')->item(0);
			$dropPP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_dropIDArr[0].'"]')->item(0);
			
			$dragUser = $dragPP->getAttribute("User");
			$dropUser = $dropPP->getAttribute("User");
			
			$parentID = $dropPP->getAttribute('parentID');
			$PPName = $dragPP->getAttribute('Name');
			
			$currentPP = $dropPP;
			$canReplace = true;
			while($parentID != "") {
				if($parentID == $p_dragID)
					$canReplace = false;
				$currentPP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$parentID.'"]')->item(0);
				$parentID = $currentPP->getAttribute('parentID');
			}
			$ret.= '<legend>'.$this->_getI18N('dragSection').'</legend>';
			$ret.= '<input type="hidden" name="saveMethod" value="saveDADSectionToSection"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
			$ret.= '<table><tr><td>'.$this->_getI18N('dragSectionInfoMsg1').' <i>'.str_replace("_"," ",trim($PPName,"_ ")).'</i> '.$this->_getI18N('dragSectionInfoMsg2').'<hr></td></tr>';
			if($this->_getView(utf8_decode($dragUser)) == "Client" && $this->_getView(utf8_decode($dropUser)) == "Info-User") {
				$ret.= '<tr><td style="color:#ee3333;"><img src="img/warning.png">'.$this->_getI18N("makeClientToInfoUser").'</td></tr>';
			}
			if($canReplace) {
				$ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
				$ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
			}else{
				$ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace" disabled="disabled"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
				$ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
			}
			$ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
			$ret.= '</table>';
        } else if($p_dragType == "user" && $p_dropType == "user") {
        	if($p_dropOrder == "before" || $p_dropOrder == "after") {
                $this->saveDADUserToUser($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder);
                return array('','CMgr.getMODEL().__construct();');
            }        
            $ret.= '<legend>'.$this->_getI18N('dragUser').'</legend>';
            $ret.= '<input type="hidden" name="saveMethod" value="saveDADUserToUser"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
            $ret.= '<table><tr><td>'.$this->_getI18N('dragUserInfoMsg1').' <i>'.utf8_encode($p_dragID).'</i> '.$this->_getI18N('dragUserInfoMsg2').' <i>'.utf8_encode($p_dropID).'</i> '.$this->_getI18N('dragUserInfoMsg3').'<hr></td></tr>';
            if($this->_getView($p_dragID) == "Client" && $this->_getView($p_dropID) == "Info-User") {
                $ret.= '<tr><td style="color:#ee3333;"><img src="img/warning.png">'.$this->_getI18N("makeClientToInfoUser").'</td></tr>';
            }
            $ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
            $ret.= '</table>';
        } else if($p_dragType == "section" && $p_dropType == "user") {
            $p_dragIDArr = explode("_",$p_dragID);
            $p_dropIDArr = explode("_",$p_dropID);
            $dragPP = $projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'"]')->item(0);
            
            $parentID = "";
            $PPName = $dragPP->getAttribute('Name');
            
            $ret.= '<legend>'.$this->_getI18N('dragSection').'</legend>';
            $ret.= '<input type="hidden" name="saveMethod" value="saveDADSectionToUser"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
            $ret.= '<table><tr><td>'.$this->_getI18N('dragSectionInfoMsg1').' <i>'.str_replace("_"," ",trim($PPName,"_ ")).'</i> '.$this->_getI18N('to').' '.utf8_encode($p_dropIDArr[0]).' '.$this->_getI18N('dragSectionInfoMsg2').'<hr></td></tr>';
            if($this->_getView($p_dragIDArr[1]) == "Client" && $this->_getView($p_dropID) == "Info-User") {
                $ret.= '<tr><td style="color:#ee3333;"><img src="img/warning.png">'.$this->_getI18N("makeClientToInfoUser").'</td></tr>';
            }
            $ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
            $ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
            $ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
            $ret.= '</table>';
		} else if($p_dragType == "report" && ($p_dropType == "section" || $p_dropType == "report")) {
		    if($p_dropType == "report") {
                $this->saveDADReportToSection($p_dragType,utf8_decode($p_dragID),$p_dropType,utf8_decode($p_dropID),$p_dropOrder,"replace");
                return array('','CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configReportsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configReportsFormCb);');
            }
			$p_dragIDArr = explode("_",$p_dragID);
			$dragPR = $projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID = "'.$p_dragIDArr[0].'"]')->item(0);
			$p_dropIDArr = explode("_",$p_dropID);
			
			$PRName = $dragPR->getElementsByTagName("Name")->item(0)->nodeValue;
			
			$ret.= '<legend>'.$this->_getI18N('dragReport').'</legend>';
			$ret.= '<input type="hidden" name="saveMethod" value="saveDADReportToSection"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
			$ret.= '<table><tr><td>'.$this->_getI18N('dragReportInfoMsg1').' <i>'.$PRName.'</i> '.$this->_getI18N('dragReportInfoMsg2').'<hr></td></tr>';
		    if($this->_getView($p_dragIDArr[1]) == "Client" && $this->_getView($p_dropIDArr[1]) == "Info-User") {
                $ret.= '<tr><td style="color:#ee3333;"><img src="img/warning.png">'.$this->_getI18N("makeClientToInfoUser").'</td></tr>';
            }
			$ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
			$ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
			$ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
			$ret.= '</table>';

		} else if($p_dragType == "scorecard" && ($p_dropType == "section" || $p_dropType == "scorecard")) {
		    if($p_dropType == "scorecard") {
                $this->saveDADScorecardToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,"replace");
                return array('','CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configScorecardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configScorecardsFormCb);');
            }
			$p_dragIDArr = explode("_",$p_dragID);
			$dragPR = $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./@ID = "'.$p_dragIDArr[0].'"]')->item(0);
			$p_dropIDArr = explode("_",$p_dropID);
			
			$PRName = $dragPR->getElementsByTagName("Name")->item(0)->nodeValue;
			
			$ret.= '<legend>'.$this->_getI18N('dragScorecard').'</legend>';
			$ret.= '<input type="hidden" name="saveMethod" value="saveDADScorecardToSection"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
			$ret.= '<table><tr><td>'.$this->_getI18N('dragScorecardInfoMsg1').' <i>'.$PRName.'</i> '.$this->_getI18N('dragScorecardInfoMsg2').'<hr></td></tr>';
			$ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
			$ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
			$ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
			$ret.= '</table>';
		} else if($p_dragType == "dashboard" && ($p_dropType == "section" || $p_dropType == "dashboard")) {
            if($p_dropType == "dashboard") {
                $this->saveDADDashboardToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,"replace");
                return array('','CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);');
            }
            $p_dragIDArr = explode("_",$p_dragID);
            $dragPR = $projectXpath->query('/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID = "'.$p_dragIDArr[0].'"]')->item(0);
            $p_dropIDArr = explode("_",$p_dropID);
            
            $PRName = $dragPR->getElementsByTagName("Name")->item(0)->nodeValue;
            
            $ret.= '<legend>'.$this->_getI18N('dragDashboard').'</legend>';
            $ret.= '<input type="hidden" name="saveMethod" value="saveDADDashboardToSection"><input type="hidden" name="dragType" value="'.$p_dragType.'"><input type="hidden" name="dragID" value="'.utf8_encode($p_dragID).'"><input type="hidden" name="dropType" value="'.$p_dropType.'"><input type="hidden" name="dropID" value="'.utf8_encode($p_dropID).'"><input type="hidden" name="dropOrder" value="'.$p_dropOrder.'">';
            $ret.= '<table><tr><td>'.$this->_getI18N('dragDashboardInfoMsg1').' <i>'.$PRName.'</i> '.$this->_getI18N('dragDashboardInfoMsg2').'<hr></td></tr>';
            $ret.= '<tr><td><input class="btn" id="inp_replace" name="action" type="radio" value="replace"><label for="inp_replace">'.$this->_getI18N('replace').'</label></td></tr>';
            $ret.= '<tr><td><input class="btn" id="inp_copy" name="action" type="radio" value="copy" checked="checked"><label for="inp_copy">'.$this->_getI18N('copy').'</label>';
            $ret.= '<tr><td><hr><input class="btn" type="button" value="'.$this->_getI18N('abort').'" onclick="CMgr.getMODEL().abortRetrieveInput();"><input class="btn" type="submit" value="'.$this->_getI18N('save').'"></td></tr>';
            $ret.= '</table>';
        }
		$ret.= '</fieldset>';
		$ret.= '</form>';
		return array($ret,'');
	}
	
    private function saveDADSectionToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,$p_action,$ProjectDOM=null,$ProjectXpath=null) {
        $MISConfig = new MISConfig();
    	if($ProjectDOM == null) {
	        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
	        $ProjectDOM->load($MISConfig->getConfigFile());
        }
        if($ProjectXpath == null) {
        	$ProjectXpath = new DOMXpath($ProjectDOM);      
        }  
        
        $Project = $ProjectXpath->query("/Configuration")->item(0);

        $p_dragIDArr = explode("_",$p_dragID);
        $p_dropIDArr = explode("_",$p_dropID);
        
        $dropPublish = $ProjectXpath->query('./Publishes/Publish[./@ID = "'.$p_dropIDArr[0].'" and ./@User="'.utf8_encode($p_dropIDArr[1]).'"]',$Project)->item(0);
        $dropScorecard = $ProjectXpath->query('./Scorecards/Scorecard[./@ID = "'.$p_dropIDArr[0].'" and ./@Directory="'.utf8_encode($p_dropIDArr[1]).'\\"]',$Project)->item(0);
        $dropDashboard = $ProjectXpath->query('./Dashboards/Dashboard[./@ID = "'.$p_dropIDArr[0].'" and ./@Directory="'.utf8_encode($p_dropIDArr[1]).'\\"]',$Project)->item(0);
        
        if($p_action == "replace") {
            $dragPublish = $ProjectXpath->query('./Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'" and ./@User="'.utf8_encode($p_dragIDArr[1]).'"]',$Project)->item(0);
            $dragPublish = $dragPublish->parentNode->removeChild($dragPublish);
            $dragPublish->setAttribute("User",utf8_encode($p_dropIDArr[1]));
            $ImageList = $dragPublish->getElementsByTagname("Image");
            for($i=0;$ImageList->length>$i;$i++) {
            	$Image = $ImageList->item($i);
            	$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
            	if($this->_getView($p_dropIDArr[1]) == "Info-User") {
            	   $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
            	   if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
            	       $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
            	   }
            	}
            }
            $dragScorecard = $ProjectXpath->query('./Scorecards/Scorecard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]',$Project)->item(0);
            $dragScorecard = $dragScorecard->parentNode->removeChild($dragScorecard);
            $dragScorecard->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");
            
            $dragDashboard = $ProjectXpath->query('./Dashboards/Dashboard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]',$Project)->item(0);
            $dragDashboard = $dragDashboard->parentNode->removeChild($dragDashboard);
            $dragDashboard->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");
        } elseif($p_action == "copy") {
            $newID = $this->_generateSectionID();
            
            $iDragPublish = $ProjectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'" and ./@User="'.utf8_encode($p_dragIDArr[1]).'"]')->item(0);
            $dragPublish = $iDragPublish->cloneNode(false);
            $dragPublish->appendChild($ProjectDOM->createElement("Images"));
            $dragPublish->setAttribute("ID",$newID);
            $dragPublish->setAttribute("User",utf8_encode($p_dropIDArr[1]));
            
            $iDragScorecard = $ProjectXpath->query('/Configuration/Scorecards/Scorecard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]')->item(0);
            $dragScorecard = $iDragScorecard->cloneNode(false);
            $dragScorecard->appendChild($ProjectDOM->createElement("Reports"));
            $dragScorecard->setAttribute("ID",$newID);
            $dragScorecard->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");
            
            $iDragDashboard = $ProjectXpath->query('/Configuration/Dashboards/Dashboard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]')->item(0);
            $dragDashboard = $iDragDashboard->cloneNode(false);
            $dragDashboard->appendChild($ProjectDOM->createElement("Reviews"));
            $dragDashboard->setAttribute("ID",$newID);
            $dragDashboard->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");

            $ImageIDs = array();
            $iImageList = $iDragPublish->getElementsByTagname("Image");     
            foreach($iImageList as $iImage) {
            	$Image = $iImage->cloneNode(true);
                $currentID = $Image->getAttribute("ID");
                if(!array_key_exists($currentID,$ImageIDs)) {
                	$newID = $this->_generateReportID();
                    $ImageIDs[$currentID] = $newID;
                }else{
                    $newID = $ImageIDs[$currentID];
                }
                $Image->setAttribute("ID",$newID);
                $MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
                if($this->_getView($p_dropIDArr[1]) == "Info-User") {
                   $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
                   if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                       $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                   }
                }
                $dragPublish->getElementsByTagName("Images")->item(0)->appendChild($Image);
            }
            
            //COPY SCORECARDS
            $iReportList = $iDragScorecard->getElementsByTagname("Report");     
            foreach($iReportList as $iReport) {
                $Report = $iReport->cloneNode(true);
                $Report->setAttribute("ID",$this->_generateReportID());
                $dragScorecard->getElementsByTagName("Reports")->item(0)->appendChild($Report);
            }
            
            $iReportList = $iDragDashboard->getElementsByTagname("Review");     
            foreach($iReportList as $iReport) {
                $Report = $iReport->cloneNode(true);
                $Report->setAttribute("ID",$this->_generateReportID());
                $dragDashboard->getElementsByTagName("Reviews")->item(0)->appendChild($Report);
            }
        }
        
        switch($p_dropOrder) {
            case "before":  $dropPublish->parentNode->insertBefore($dragPublish,$dropPublish);
                            $dragPublish->setAttribute("parentID",$dropPublish->getAttribute("parentID"));
                            $dropScorecard->parentNode->insertBefore($dragScorecard,$dropScorecard);
                            $dragScorecard->setAttribute("parentID",$dropScorecard->getAttribute("parentID"));
                            $dropDashboard->parentNode->insertBefore($dragDashboard,$dropDashboard);
                            $dragDashboard->setAttribute("parentID",$dropDashboard->getAttribute("parentID"));
                            break;
            case "under":   $dropPublish->parentNode->appendChild($dragPublish);
                            $dragPublish->setAttribute("parentID",$dropPublish->getAttribute("ID"));
                            $dropScorecard->parentNode->appendChild($dragScorecard);
                            $dragScorecard->setAttribute("parentID",$dropScorecard->getAttribute("ID"));
                            $dropDashboard->parentNode->appendChild($dragDashboard);
                            $dragDashboard->setAttribute("parentID",$dropDashboard->getAttribute("ID"));
                            break;
            
            case "after":   if($dropPublish->nextSibling != null && !$dropPublish->nextSibling->isSameNode($dragPublish)) {
                                $dropPublish->parentNode->insertBefore($dragPublish,$dropPublish->nextSibling);
                            } else {
                                $dropPublish->parentNode->appendChild($dragPublish);
                            }
                            $dragPublish->setAttribute("parentID",$dropPublish->getAttribute("parentID"));
                            if($dropScorecard->nextSibling != null && !$dropScorecard->nextSibling->isSameNode($dragScorecard)) {
                                $dropScorecard->parentNode->insertBefore($dragScorecard,$dropScorecard->nextSibling);
                            } else {
                                $dropScorecard->parentNode->appendChild($dragScorecard);
                            }
                            $dragScorecard->setAttribute("parentID",$dropScorecard->getAttribute("parentID"));
                            if($dropDashboard->nextSibling != null && !$dropDashboard->nextSibling->isSameNode($dragDashboard)) {
                                $dropDashboard->parentNode->insertBefore($dragDashboard,$dropDashboard->nextSibling);
                            } else {
                                $dropDashboard->parentNode->appendChild($dragDashboard);
                            }
                            $dragDashboard->setAttribute("parentID",$dropDashboard->getAttribute("parentID"));
                            break;
        }
        
        $subDragPublishes = $ProjectXpath->query("./Publishes/Publish[./@parentID = '".$p_dragIDArr[0]."' and ./@User='".utf8_encode($p_dragIDArr[1])."']");
        if($subDragPublishes->length>0) {
            for($i=0;$i<$subDragPublishes->length;$i++) {
               $this->saveDADSectionToSection($p_dragType,$subDragPublishes->item($i)->getAttribute("ID")."_".$p_dragIDArr[1],"section",$dragPublish->getAttribute("ID")."_".$p_dropIDArr[1],"under",$p_action,$ProjectDOM,$ProjectXpath);
            }
        }
        $ProjectDOM->save($MISConfig->getConfigFile());
        
        $this->saveRetrieveInput("dummy");
        return array('CMgr.getMODEL().__construct();');
    }
    
    private function saveDADSectionToUser($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,$p_action,$ProjectDOM=null,$ProjectXpath=null) {
        $MISConfig = new MISConfig();
	    if($ProjectDOM == null) {
	        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
	        $ProjectDOM->load($MISConfig->getConfigFile());
        }
        if($ProjectXpath == null) {
        	$ProjectXpath = new DOMXpath($ProjectDOM);      
        }
        $Project = $ProjectXpath->query("/Configuration")->item(0);

        $p_dragIDArr = explode("_",$p_dragID);
        
        if($p_action == "replace") {
            $dragPublish = $ProjectXpath->query('./Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'" and ./@User="'.utf8_encode($p_dragIDArr[1]).'"]',$Project)->item(0);
            $dragPublish = $dragPublish->parentNode->removeChild($dragPublish);
            $dragPublish->setAttribute("User",utf8_encode($p_dropID));
            $dragPublish->setAttribute("parentID","");
            $ImageList = $dragPublish->getElementsByTagname("Image");
            for($i=0;$ImageList->length>$i;$i++) {
                $Image = $ImageList->item($i);
                $MISConfig->setNodeValue("Directory",$p_dropID."\\",$ProjectDOM,$Image);
                if($this->_getView($p_dropID) == "Info-User") {
                   $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropID),$ProjectDOM,$Image);
                   if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                       $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                   }
                }
            }
            $dragScorecard = $ProjectXpath->query('./Scorecards/Scorecard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]',$Project)->item(0);
            $dragScorecard = $dragScorecard->parentNode->removeChild($dragScorecard);
            $dragScorecard->setAttribute("Directory",utf8_encode($p_dropID)."\\");
            
            $dragDashboard = $ProjectXpath->query('./Dashboards/Dashboard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]',$Project)->item(0);
            $dragDashboard = $dragDashboard->parentNode->removeChild($dragDashboard);
            $dragDashboard->setAttribute("Directory",utf8_encode($p_dropID)."\\");
        } elseif($p_action == "copy") {
            $newID = $this->_generateSectionID();
            
            $iDragPublish = $ProjectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$p_dragIDArr[0].'" and ./@User="'.utf8_encode($p_dragIDArr[1]).'"]')->item(0);
            $dragPublish = $iDragPublish->cloneNode(false);
            $dragPublish->appendChild($ProjectDOM->createElement("Images"));
            $dragPublish->setAttribute("ID",$newID);
            $dragPublish->setAttribute("parentID","");
            $dragPublish->setAttribute("User",utf8_encode($p_dropID));
            
            $iDragScorecard = $ProjectXpath->query('/Configuration/Scorecards/Scorecard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]')->item(0);
            $dragScorecard = $iDragScorecard->cloneNode(false);
            $dragScorecard->appendChild($ProjectDOM->createElement("Reports"));
            $dragScorecard->setAttribute("ID",$newID);
            $dragScorecard->setAttribute("Directory",utf8_encode($p_dropID)."\\");
            
            $iDragDashboard = $ProjectXpath->query('/Configuration/Dashboards/Dashboard[./@ID = "'.$p_dragIDArr[0].'" and ./@Directory="'.utf8_encode($p_dragIDArr[1]).'\\"]')->item(0);
            $dragDashboard = $iDragDashboard->cloneNode(false);
            $dragDashboard->appendChild($ProjectDOM->createElement("Reviews"));
            $dragDashboard->setAttribute("ID",$newID);
            $dragDashboard->setAttribute("Directory",utf8_encode($p_dropID)."\\");

            $ImageIDs = array();
            $iImageList = $iDragPublish->getElementsByTagname("Image");     
            foreach($iImageList as $iImage) {
                $Image = $iImage->cloneNode(true);
                $currentID = $Image->getAttribute("ID");
                if(!array_key_exists($currentID,$ImageIDs)) {
                    $newID = $this->_generateReportID();
                    $ImageIDs[$currentID] = $newID;
                }else{
                    $newID = $ImageIDs[$currentID];
                }
                $Image->setAttribute("ID",$newID);
                $MISConfig->setNodeValue("Directory",$p_dropID."\\",$ProjectDOM,$Image);
                if($this->_getView($p_dropID) == "Info-User") {
                   $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropID),$ProjectDOM,$Image);
                   if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                       $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                   }
                }
                $dragPublish->getElementsByTagName("Images")->item(0)->appendChild($Image);
            }
           
            //COPY SCORECARDS
            $iReportList = $iDragScorecard->getElementsByTagname("Report");     
            foreach($iReportList as $iReport) {
                $Report = $iReport->cloneNode(true);
                $Report->setAttribute("ID",$this->_generateReportID());
                $dragScorecard->getElementsByTagName("Reports")->item(0)->appendChild($Report);
            }
            
            $iReportList = $iDragDashboard->getElementsByTagname("Review");     
            foreach($iReportList as $iReport) {
                $Report = $iReport->cloneNode(true);
                $Report->setAttribute("ID",$this->_generateReportID());
                $dragDashboard->getElementsByTagName("Reviews")->item(0)->appendChild($Report);
            }
        }
        $dropPublishes = $ProjectXpath->query("./Publishes",$Project)->item(0);
        $dropScorecards = $ProjectXpath->query("./Scorecards",$Project)->item(0);
        $dropDashboards = $ProjectXpath->query("./Dashboards",$Project)->item(0);
        $dropPublishes->appendChild($dragPublish);
        $dropScorecards->appendChild($dragScorecard);
        $dropDashboards->appendChild($dragDashboard);

        $subDragPublishes = $ProjectXpath->query("./Publishes/Publish[./@parentID = '".$p_dragIDArr[0]."' and ./@User='".utf8_encode($p_dragIDArr[1])."']");
        if($subDragPublishes->length>0) {
            for($i=0;$i<$subDragPublishes->length;$i++) {
               $this->saveDADSectionToSection($p_dragType,$subDragPublishes->item($i)->getAttribute("ID")."_".$p_dragIDArr[1],"section",$dragPublish->getAttribute("ID")."_".$p_dropID,"under",$p_action,$ProjectDOM,$ProjectXpath);
            }
        }
        $ProjectDOM->save($MISConfig->getConfigFile());
        
        $this->saveRetrieveInput("dummy");
        return array('CMgr.getMODEL().__construct();');
    }
	
	private function saveDADUserToUser($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder) {
        $MISConfig = new MISConfig();
        if($p_dropOrder == "under") {
	        $ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
	        $ProjectDOM->load($MISConfig->getConfigFile());
	        $ProjectXpath = new DOMXpath($ProjectDOM);
	        $Project =  $ProjectXpath->query('/Configuration')->item(0); 
			$iDragPublishList = $ProjectXpath->query('./Publishes/Publish[./@User = "'.utf8_encode($p_dragID).'" and ./@parentID = ""]',$Project);
	   
	        $temp=$iDragPublishList->length;
		    for($i=0;$temp>$i;$i=$i+1) {
	            $dragID = $iDragPublishList->item($i)->getAttribute("ID");
	            $this->saveDADSectionToUser("section",$dragID."_".$p_dragID,"user",$p_dropID,"","copy",$ProjectDOM,$ProjectXpath);
	        }
	        $ProjectDOM->save($MISConfig->getConfigFile());
        	$this->saveRetrieveInput("dummy");
        }else {
        	$UserDOM = new DOMDocument('1.0', 'iso-8859-1');
        	$UserDOM->load($this->authFile);
        	$UserXpath = new DOMXpath($UserDOM);

        	$dragUser = $UserXpath->query("/auth/users/user[@username='".utf8_encode($p_dragID)."' and @setting='".basename($MISConfig->getConfigFile(),".xml")."']")->item(0);
        	$dropUser = $UserXpath->query("/auth/users/user[@username='".utf8_encode($p_dropID)."' and @setting='".basename($MISConfig->getConfigFile(),".xml")."']")->item(0);
        	switch($p_dropOrder) {
	            case "before":  $dropUser->parentNode->insertBefore($dragUser,$dropUser);
	                            break;
	            case "after":   if($dropUser->nextSibling != null && !$dropUser->nextSibling->isSameNode($dragUser)) {
	                                $dropUser->parentNode->insertBefore($dragUser,$dropUser->nextSibling);
	                            } else {
	                                $dropUser->parentNode->appendChild($dragUser);
	                            }
	                            break;
	        }
	        $UserDOM->save($MISConfig->authFile);
        }
        return array('CMgr.getMODEL().__construct();');
	}
	
	private function saveDADReportToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,$p_action) {
		$MISConfig = new MISConfig();
		$ProjectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$ProjectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($ProjectDOM);

		$p_dragIDArr = explode("_",$p_dragID);
		$p_dropIDArr = explode("_",$p_dropID);

		$dragPIList = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./@ID='".$p_dragIDArr[0]."']");
		if($p_dropType == "section") {
			$dropPP = $projectXpath->query("/Configuration/Publishes/Publish/Images[./../@ID='".$p_dropIDArr[0]."']")->item(0);
			$newID = $this->_generateReportID();
			for($i=0;$i<$dragPIList->length;$i++) {
				
				if($p_action == "replace") {
					$Image = $dragPIList->item($i);
					$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
				    if($this->_getView($p_dropIDArr[1]) == "Info-User") {
	                   $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
	                   if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
	                       $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
	                   }
	                }
					$dropPP->appendChild($Image);
				} else if($p_action == "copy") {
					$Image = $dragPIList->item($i)->cloneNode(true);
					$Image->setAttribute("ID",$newID);
					$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
				    if($this->_getView($p_dropIDArr[1]) == "Info-User") {
                       $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
                       if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                           $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                       }
                    }
					$dropPP->appendChild($Image);
				}
			}
		}else if($p_dropType == "report") {
			$dropPI = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./@ID='".$p_dropIDArr[0]."' and Active='J']")->item(0);
			$newID = $this->_generateReportID();
			for($i=0;$i<$dragPIList->length;$i++) {
				if($p_action == "replace") {
					$Image = $dragPIList->item($i);
//					$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
/*				    if($this->_getView($p_dropIDArr[1]) == "Info-User") {
                       $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
                       if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                           $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                       }
                    }
*/					$dragPIArr[] = $Image;
				} else if($p_action == "copy") {
					$Image = $dragPIList->item($i)->cloneNode(true);
					$newPI->setAttribute("ID",$newID);
//					$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$ProjectDOM,$Image);
/*				    if($this->_getView($p_dropIDArr[1]) == "Info-User") {
                       $MISConfig->setNodeValue("Ansicht",$this->_getView($p_dropIDArr[1]),$ProjectDOM,$Image);
                       if($Image->getElementsByTagname("Active")->item(0)->nodeValue == "J"){
                           $MISConfig->setNodeValue("PDFGenerate","J",$ProjectDOM,$Image);
                       }
                    }
*/                    $dragPIArr[] = $Image;
				}
			}
			foreach($dragPIArr as $key => $PI) {
				switch($p_dropOrder) {
					case "before":	$dropPI->parentNode->insertBefore($PI,$dropPI);
									break;				
					case "after":	if($dropPI->nextSibling != null && !$dropPI->nextSibling->isSameNode($PI)) {
										$dropPI->parentNode->insertBefore($PI,$dropPI->nextSibling);
									} else {
										$dropPI->parentNode->appendChild($PI);
									}
									break;
				}
			}
		}
		$ProjectDOM->save($MISConfig->getConfigFile());
		$this->saveRetrieveInput("dummy");
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configReportsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configReportsFormCb);');
	}
	
	private function saveDADScorecardToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,$p_action) {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);

		$p_dragIDArr = explode("_",$p_dragID);
		$p_dropIDArr = explode("_",$p_dropID);

		
		$dragPR = $projectXpath->query("/Configuration/Scorecards/Scorecard/Reports/Report[./@ID='".$p_dragIDArr[0]."']")->item(0);
		if($p_dropType == "section") {
			$PRsList = $projectXpath->query("/Configuration/Scorecards/Scorecard/Reports[./../@ID='".$p_dropIDArr[0]."' and ./../@Directory='".utf8_encode($p_dropIDArr[1])."\\']");
			$PPName = $projectXpath->query("/Configuration/Publishes/Publish[./@ID='".$p_dropIDArr[0]."']")->item(0)->getAttribute("Name");
			if($PRsList->length > 0) {
				$dropPRs = $PRsList->item(0);
			}else{
				$PS = $projectDOM->createElement("Scorecard");
				$PS->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");
				$PS->setAttribute("ID",$p_dropIDArr[0]);
				$PS->setAttribute("Name",$PPName);
				$dropPRs = $projectDOM->createElement("Reports");
				$PS->appendChild($dropPRs);
				$PSs = $projectXpath->query("/Configuration/Scorecards")->item(0);
				$PSs->appendChild($PS);
			}
			
			$newID = $this->_generateReportID();
			if($p_action == "replace") {
					$dropPRs->appendChild($dragPR);
			} else if($p_action == "copy") {
				$newPR = $dragPR->cloneNode(true);
				$newPR->setAttribute("ID",$newID);
				//$MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$projectDOM,$newPR);
				$dropPRs->appendChild($newPR);
			}
		}else if($p_dropType == "scorecard") {
			$dropPR = $projectXpath->query("/Configuration/Scorecards/Scorecard/Reports/Report[./@ID='".$p_dropIDArr[0]."']")->item(0);
			$newID = $this->_generateReportID();
			if($p_action == "replace") {
				$newPR = $dragPR;
			} else if($p_action == "copy") {
				$newPR = $dragPR->cloneNode(true);
				$newPR->setAttribute("ID",$newID);
			}
			switch($p_dropOrder) {
				case "before":	$dropPR->parentNode->insertBefore($newPR,$dropPR);
								break;				
				case "after":	if($dropPR->nextSibling != null && !$dropPR->nextSibling->isSameNode($newPR)) {
									$dropPR->parentNode->insertBefore($newPR,$dropPR->nextSibling);
								} else {
									$dropPR->parentNode->appendChild($newPR);
								}
								break;
			}
		}
		$projectDOM->save($MISConfig->getConfigFile());
		$this->saveRetrieveInput("dummy");
		return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configScorecardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configScorecardsFormCb);');
	}
	
    private function saveDADDashboardToSection($p_dragType,$p_dragID,$p_dropType,$p_dropID,$p_dropOrder,$p_action) {
        $MISConfig = new MISConfig();
        $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
        $projectDOM->load($MISConfig->getConfigFile());
        $projectXpath = new DOMXpath($projectDOM);

        $p_dragIDArr = explode("_",$p_dragID);
        $p_dropIDArr = explode("_",$p_dropID);

        
        $dragPR = $projectXpath->query("/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID='".$p_dragIDArr[0]."']")->item(0);
        if($p_dropType == "section") {
            $PRsList = $projectXpath->query("/Configuration/Dashboards/Dashboard/Reviews[./../@ID='".$p_dropIDArr[0]."' and ./../@Directory='".utf8_encode($p_dropIDArr[1])."\\']");
            $PPName = $projectXpath->query("/Configuration/Publishes/Publish[./@ID='".$p_dropIDArr[0]."']")->item(0)->getAttribute("Name");
            if($PRsList->length > 0) {
                $dropPRs = $PRsList->item(0);
            }else{
                $PS = $projectDOM->createElement("Dashboard");
                $PS->setAttribute("Directory",utf8_encode($p_dropIDArr[1])."\\");
                $PS->setAttribute("ID",$p_dropIDArr[0]);
                $PS->setAttribute("Name",$PPName);
                $dropPRs = $projectDOM->createElement("Reviews");
                $PS->appendChild($dropPRs);
                $PSs = $projectXpath->query("/Configuration/Dashboards")->item(0);
                $PSs->appendChild($PS);
            }
            
            $newID = $this->_generateReportID();
            if($p_action == "replace") {
                    $dropPRs->appendChild($dragPR);
            } else if($p_action == "copy") {
                $newPR = $dragPR->cloneNode(true);
                $newPR->setAttribute("ID",$newID);
                $MISConfig->setNodeValue("Directory",$p_dropIDArr[1]."\\",$projectDOM,$newPR);
                $dropPRs->appendChild($newPR);
            }
        }else if($p_dropType == "dashboard") {
            $dropPR = $projectXpath->query("/Configuration/Dashboards/Dashboard/Reviews/Review[./@ID='".$p_dropIDArr[0]."']")->item(0);
            $newID = $this->_generateReportID();
            if($p_action == "replace") {
                $newPR = $dragPR;
            } else if($p_action == "copy") {
                $newPR = $dragPR->cloneNode(true);
                $newPR->setAttribute("ID",$newID);
            }
            switch($p_dropOrder) {
                case "before":  $dropPR->parentNode->insertBefore($newPR,$dropPR);
                                break;              
                case "after":   if($dropPR->nextSibling != null && !$dropPR->nextSibling->isSameNode($newPR)) {
                                    $dropPR->parentNode->insertBefore($newPR,$dropPR->nextSibling);
                                } else {
                                    $dropPR->parentNode->appendChild($newPR);
                                }
                                break;
            }
        }
        $projectDOM->save($MISConfig->getConfigFile());
        $this->saveRetrieveInput("dummy");
        return array('CMgr.getMODEL().abortRetrieveInput();Ajax.request(MISConfigurator.__toString(),"configDashboardsForm","'.utf8_encode($_SESSION["configurator"]["publishes"]["section"]).'",MISConfigurator.configDashboardsFormCb);');
    }
	
	private function dummy(){}

	private function _generateSectionID() {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$ID = null;
		while($ID == null) {
			$temp = mt_rand(0,99999);
			if($projectXpath->query('/Configuration/Publishes/Publish[./@ID = "'.$temp.'"]')->length == 0
			&&  !in_array($temp,self::$generatedSectionIDs)) {
				self::$generatedSectionIDs[] = $temp;
				$ID = $temp;
			}
		}
		return $ID;
	}

	private function _generateReportID() {
		$MISConfig = new MISConfig();
		$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
		$projectDOM->load($MISConfig->getConfigFile());
		$projectXpath = new DOMXpath($projectDOM);
		
		$ID = null;
		while($ID == null) {
			$temp = mt_rand(0,99999);
			if($projectXpath->query('/Configuration/Publishes/Publish/Images/Image[./@ID = "'.$temp.'"]')->length == 0
			&& $projectXpath->query('/Configuration/Scorecards/Scorecard/Reports/Report[./@ID = "'.$temp.'"]')->length == 0
			&& $projectXpath->query('/Configuration/General/Dashboards/Dashboard/Review[./@ID = "'.$temp.'"]')->length == 0
			&&  !in_array($temp,self::$generatedReportIDs)) {
				self::$generatedReportIDs[] = $temp; 
				$ID = $temp;
			}
		}
		return $ID;
	}
	
	public function getReport($p_reportID) {
		if($this->getAuth() && $this->isRole("admin")) {
			$p_args = func_get_args();
			$MISConfig = new MISConfig();
			$projectDOM = new DOMDocument('1.0', 'iso-8859-1');
			$projectDOM->load($MISConfig->getConfigFile());
			$projectXpath = new DOMXpath($projectDOM);
			$report = $projectXpath->query("/Configuration/Publishes/Publish/Images/Image[./Active = 'J' and ./@ID = '".$p_reportID."']")->item(0);
			
		
			$name = $report->getElementsByTagName("Report")->item(0)->nodeValue;
								$reportPath = $projectXpath->query("/Configuration/General/ReportPath")->item(0)->nodeValue;
								$ppx = $report->getElementsByTagName("ppx")->item(0)->nodeValue;
                                if($ppx == "J" && file_exists($reportPath.$name.".ppx")) $filename = utf8_decode($reportPath.$name.".ppx"); 	
					            else $filename = utf8_decode($reportPath.$name.".ppr");

					            $file_extension = strtolower(substr(strrchr($filename,"."),1));
	
					            switch ($file_extension) {
					                case "pdf": $ctype="application/pdf"; break;
					                case "exe": $ctype="application/octet-stream"; break;
					                case "zip": $ctype="application/zip"; break;
					                case "doc": $ctype="application/msword"; break;
					                case "xls": $ctype="application/vnd.ms-excel"; break;
					                case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
					                case "gif": $ctype="image/gif"; break;
					                case "png": $ctype="image/png"; break;
					                case "jpe": case "jpeg":
					                case "jpg": $ctype="image/jpeg"; break;
					                case "ppr": $ctype="application/powerplay"; break;
					                case "ppx": $ctype="application/powerplay"; break;
					                default: $ctype="text";
					            }
			                    if (!file_exists($filename)) {
                                    die("<script type='text/javascript'>alert('" .$this->_getI18N("missingReportFile")."');window.history.back();</script>");
                                }					            
					
					            header("Pragma: public");
					            header("Expires: 0");
					            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
					            header("Cache-Control: private",false);
					            header("Content-Type: $ctype");
					            header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
					            header("Content-Transfer-Encoding: binary");
					            header("Content-Length: ".@filesize($filename));
					            set_time_limit(0);
					            readfile($filename) or die("File not found."); 

		
		}else{
			print "<script type='text/javascript'>window.history.back();</script>";
		}
	}
	
   public function getScorecard($p_reportID) {
        if($this->getAuth()) {
            $p_args = func_get_args();
            $MISConfig = new MISConfig();
            $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
            $projectDOM->load($MISConfig->getConfigFile());
            $projectXpath = new DOMXpath($projectDOM);
            $report = $projectXpath->query("/Configuration/Scorecards/Scorecard/Reports/Report[@ID = '".$p_reportID."']")->item(0);
            
            
            //$ansicht = $report->getElementsByTagName("Ansicht")->item(0)->nodeValue;
            
            $ansicht = $this->_getView();
    

                $name = $report->getElementsByTagName("ReportFile")->item(0)->nodeValue;
                                $reportPath = $projectXpath->query("/Configuration/General/ReportPath")->item(0)->nodeValue;    
                                $filename = $reportPath.$name.".ppr";
    
                                $file_extension = strtolower(substr(strrchr($filename,"."),1));
    
                                switch ($file_extension) {
                                    case "pdf": $ctype="application/pdf"; break;
                                    case "exe": $ctype="application/octet-stream"; break;
                                    case "zip": $ctype="application/zip"; break;
                                    case "doc": $ctype="application/msword"; break;
                                    case "xls": $ctype="application/vnd.ms-excel"; break;
                                    case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
                                    case "gif": $ctype="image/gif"; break;
                                    case "png": $ctype="image/png"; break;
                                    case "jpe": case "jpeg":
                                    case "jpg": $ctype="image/jpeg"; break;
                                    case "ppr": $ctype="application/powerplay"; break;
                                    default: $ctype="text";
                                }
        			            if (!file_exists($filename)) {
                                    die("<script type='text/javascript'>alert('" .$this->_getI18N("missingReportFile")."');window.history.back();</script>");
                                }                            
                    
                                header("Pragma: public");
                                header("Expires: 0");
                                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                                header("Cache-Control: private",false);
                                header("Content-Type: $ctype");
                                header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
                                header("Content-Transfer-Encoding: binary");
                                header("Content-Length: ".@filesize($filename));
                                set_time_limit(0);
                                readfile($filename) or die("File not found."); 
        }else{
			print "<script type='text/javascript'>window.history.back();</script>";
        }
    }
    
  public function getDashboard($p_reportID) {
        if($this->getAuth()) {
            $p_args = func_get_args();
            $MISConfig = new MISConfig();
            $projectDOM = new DOMDocument('1.0', 'iso-8859-1');
            $projectDOM->load($MISConfig->getConfigFile());
            $projectXpath = new DOMXpath($projectDOM);
            $report = $projectXpath->query("/Configuration/Dashboards/Dashboard/Reviews/Review[@ID = '".$p_reportID."']")->item(0);
            
            
            //$ansicht = $report->getElementsByTagName("Ansicht")->item(0)->nodeValue;
            
            $ansicht = $this->_getView();
    

                $name = $report->getElementsByTagName("ReportFile")->item(0)->nodeValue;
                                $reportPath = $projectXpath->query("/Configuration/General/DashboardPath")->item(0)->nodeValue;    
                                $filename = $reportPath.$name.".xls";
    
                                $file_extension = strtolower(substr(strrchr($filename,"."),1));
    
                                switch ($file_extension) {
                                    case "pdf": $ctype="application/pdf"; break;
                                    case "exe": $ctype="application/octet-stream"; break;
                                    case "zip": $ctype="application/zip"; break;
                                    case "doc": $ctype="application/msword"; break;
                                    case "xls": $ctype="application/vnd.ms-excel"; break;
                                    case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
                                    case "gif": $ctype="image/gif"; break;
                                    case "png": $ctype="image/png"; break;
                                    case "jpe": case "jpeg":
                                    case "jpg": $ctype="image/jpeg"; break;
                                    case "ppr": $ctype="application/powerplay"; break;
                                    default: $ctype="text";
                                }
        			            if (!file_exists($filename)) {
                                    die("<script type='text/javascript'>alert('" .$this->_getI18N("missingReportFile")."');window.history.back();</script>");
                                }                            
                    
                                header("Pragma: public");
                                header("Expires: 0");
                                header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                                header("Cache-Control: private",false);
                                header("Content-Type: $ctype");
                                header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
                                header("Content-Transfer-Encoding: binary");
                                header("Content-Length: ".@filesize($filename));
                                set_time_limit(0);
                                readfile($filename) or die("File not found."); 
        }else{
			print "<script type='text/javascript'>window.history.back();</script>";
        }
    }
}
?>