public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml	= $this->makeMenu($xml);
		
		$env = $this->_http->getParam("Env");
		if (empty($env))
			$env = "prod";
		
		if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml"))					
			$mailXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml"));
		else		
			$mailXML = $this->_generic->getMailXML();
		
		$errors = array();
		
		// Prod Deployment		
		$finalFile = ($this->_http->getParam("ProdDeployment") == "true") ? "mail_".$env.".xml" : "mail.xml";
		$isInBatch = ($this->_http->getParam("CompleteBatch") == "true") ? true : false;
		$xml->addFullTag("is_batch",($isInBatch) ? "true" : "false",true);
		$xml->addFullTag("is_prod",($this->_http->getParam("ProdDeployment") == "true") ? "true" : "false",true);
		
		// Get default values
		$defaultHost 		= $this->_generic->getMailConfig("host");
		$defaultPort		= $this->_generic->getMailConfig("port"); 
		$defaultUser 		= $this->_generic->getMailConfig("username");
		$defaultPass		= $this->_generic->getMailConfig("passsword"); 
		$defaultDomain 		= $this->_generic->getMailConfig("defaultDomain");
		$defaultReturn		= $this->_generic->getMailConfig("defaultReturn"); 
		$defaultNameReturn	= $this->_generic->getMailConfig("defaultNameReturn");
		$defaultReply		= $this->_generic->getMailConfig("defaultReply");
		$defaultNameReply	= $this->_generic->getMailConfig("defaultNameReply");
		$defaultSender		= $this->_generic->getMailConfig("defaultSender"); 
		$defaultNameSender	= $this->_generic->getMailConfig("defaultNameSender");
		$TemplatesHeader	= $mailXML->getTags("//mails/templates/item[@id='default']/header");
		$TemplatesFooter	= $mailXML->getTags("//mails/templates/item[@id='default']/footer");
		
		$reload 			= $this->_http->getParam("reload");
				
		if ($reload == "true")
		{
			// Get New Parameters
			$exportConfig	= $this->_http->getParam('export');
			
			$postHost 		= SLS_String::trimSlashesFromString($this->_http->getParam("host", "post"));
			$postPort		= SLS_String::trimSlashesFromString($this->_http->getParam("port", "post"));
			$postUser 		= SLS_String::trimSlashesFromString($this->_http->getParam("user", "post"));
			$postPass		= SLS_String::trimSlashesFromString($this->_http->getParam("pass", "post"));
			$postDomain		= SLS_String::trimSlashesFromString($this->_http->getParam("domain", "post"));
			$postReturn		= SLS_String::trimSlashesFromString($this->_http->getParam("return", "post")); 
			$postNameReturn	= SLS_String::trimSlashesFromString($this->_http->getParam("nameReturn", "post"));;
			$postReply		= SLS_String::trimSlashesFromString($this->_http->getParam("reply", "post"));
			$postNameReply	= SLS_String::trimSlashesFromString($this->_http->getParam("nameReply", "post"));
			$postSender		= SLS_String::trimSlashesFromString($this->_http->getParam("sender", "post")); 
			$postNameSender	= SLS_String::trimSlashesFromString($this->_http->getParam("nameSender", "post"));
			$postPassNeed	= SLS_String::trimSlashesFromString($this->_http->getParam("needpass", "post"));
			$postUserNeed	= SLS_String::trimSlashesFromString($this->_http->getParam("needuser", "post"));
			
			$varsPost = $this->_http->getParams("post");
			
			if ($postUserNeed != "on" && empty($postUser))
				array_push($errors, "You need to fill the username");
			if ($postPassNeed != "on" && empty($postPass))
				array_push($errors, "You need to fill the password");
			if (empty($errors) && $this->_http->getParam("ping") != "true")
			{			
				if ($defaultHost != $postHost)
					 $mailXML->setTag("//mails/host", SLS_Security::getInstance()->encrypt($postHost, $this->_generic->getSiteConfig("privateKey")), true);
				if ($defaultPort != $postPort)
					 $mailXML->setTag("//mails/port", SLS_Security::getInstance()->encrypt($postPort, $this->_generic->getSiteConfig("privateKey")), true);
				if ($defaultReturn != $postReturn)
					 $mailXML->setTag("//mails/defaultReturn", $postReturn, true);
				if ($defaultDomain != $postDomain)
					 $mailXML->setTag("//mails/defaultDomain", $postDomain, true);
				if ($defaultNameReturn != $postNameReturn)
					 $mailXML->setTag("//mails/defaultNameReturn", $postNameReturn, true);
				if ($defaultReply != $postReply)
					 $mailXML->setTag("//mails/defaultReply", $postReply, true);
				if ($defaultNameReply != $postNameReply)
					 $mailXML->setTag("//mails/defaultNameReply", $postNameReply, true);
				if ($defaultSender != $postSender)
					 $mailXML->setTag("//mails/defaultSender", $postSender, true);
				if ($defaultNameSender != $postNameSender)
					 $mailXML->setTag("//mails/defaultNameSender", $postNameSender, true);
				
				if ($postUserNeed == "on")
					$mailXML->setTag("//mails/username", "", true);
				else 
					$mailXML->setTag("//mails/username", SLS_Security::getInstance()->encrypt($postUser, $this->_generic->getSiteConfig("privateKey")), true); 
				if ($postPassNeed == "on")
					$mailXML->setTag("//mails/password", "", true);
				else 
					$mailXML->setTag("//mails/password", SLS_Security::getInstance()->encrypt($postPass, $this->_generic->getSiteConfig("privateKey")), true);
				
					
				if ($exportConfig == "on")
				{
					$date = gmdate('D, d M Y H:i:s');
					header("Content-Type: text/xml"); 
					header('Content-Disposition: attachment; filename='.$finalFile);
					header('Last-Modified: '.$date. ' GMT');
					header('Expires: ' .$date);
					// For This F**k'in Browser
					if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT']))
					{
						header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
						header('Pragma: public');
					}
					else
						header('Pragma: no-cache');
					
					print($mailXML->getXML());
					exit; 
				}
				else 
				{
					$mailXML->refresh();	
					@file_put_contents($this->_generic->getPathConfig("configSecure").$finalFile, $mailXML->getXML());
					if ($isInBatch)
						$this->_generic->forward("SLS_Bo","ProjectSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$env)));
					else if ($this->_http->getParam("ProdDeployment") == "true")
						$this->_generic->forward("SLS_Bo","ProductionDeployment");
				}
			}
			if (!empty($errors) && $this->_http->getParam("ping") != "true")
			{
				$xml->startTag('errors');
				foreach ($errors as $error)
				{
					$xml->addFullTag('error', $error);
				}
				$xml->endTag('errors');
			}
			if ($this->_http->getParam("ping") == "true")
			{
				$smtp = new SLS_Email("");
				$verdict = $smtp->pingConnection($postHost,$postPort,$postUser,$postPass);			
				$xml->addFullTag("ping",($verdict===true) ? "true" : $verdict,true);
			}
		}
		$this->_generic->eraseCache('Mail');
		$xml->startTag("current_values");
			$xml->addFullTag("host", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? SLS_Security::getInstance()->decrypt(array_shift($mailXML->getTags("//mails/host")), $this->_generic->getSiteConfig("privateKey")) : SLS_Security::getInstance()->decrypt($this->_generic->getMailConfig("host"), $this->_generic->getSiteConfig("privateKey")), true);
			$xml->addFullTag("port", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? SLS_Security::getInstance()->decrypt(array_shift($mailXML->getTags("//mails/port")), $this->_generic->getSiteConfig("privateKey")) : SLS_Security::getInstance()->decrypt($this->_generic->getMailConfig("port"), $this->_generic->getSiteConfig("privateKey")), true);
			$xml->addFullTag("user", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? SLS_Security::getInstance()->decrypt(array_shift($mailXML->getTags("//mails/username")), $this->_generic->getSiteConfig("privateKey")) : SLS_Security::getInstance()->decrypt($this->_generic->getMailConfig("username"), $this->_generic->getSiteConfig("privateKey")), true);
			$xml->addFullTag("pass", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/password")) : $this->_generic->getMailConfig("password"), true);
			$xml->addFullTag("domain", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultDomain")) : $this->_generic->getMailConfig("defaultDomain"), true);
			$xml->addFullTag("return", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultReturn")) : $this->_generic->getMailConfig("defaultReturn"), true);
			$xml->addFullTag("nameReturn", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultNameReturn")) : $this->_generic->getMailConfig("defaultNameReturn"), true);
			$xml->addFullTag("reply", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultReply")) : $this->_generic->getMailConfig("defaultReply"), true);
			$xml->addFullTag("nameReply", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultNameReply")) : $this->_generic->getMailConfig("defaultNameReply"), true);
			$xml->addFullTag("sender", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultSender")) : $this->_generic->getMailConfig("defaultSender"), true);
			$xml->addFullTag("nameSender", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/mail_".$env.".xml")) ? array_shift($mailXML->getTags("//mails/defaultNameSender")) : $this->_generic->getMailConfig("defaultNameSender"), true);
		$xml->endTag("current_values");
		
		$xml->addFullTag("url_mail_templates",$this->_generic->getFullPath("SLS_Bo","MailTemplates"),true);
		
		$this->saveXML($xml);		
	}
	/**
	 * Action Home
	 *
	 */
	public function action() 
	{
		$this->secureURL();
		$this->_generic->registerLink('MailSettings', 'SLS_Init', 'MailSettings');
		$step = 0;
		$xml = $this->getXML();
		$errors = array();
		if ($this->_http->getParam("mails_reload") == "1")
		{
			$useSmtp = $this->_http->getParam("mails_useSmtp");
			if (empty($useSmtp))
				array_push($errors, "Will you need SMTP connection?");
			else
			{
				if ($this->_http->getParam("mails_useSmtp") == "false")
				{
					$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"Final",1=>"Congratulations"));
					return $this->_generic->dispatch("SLS_Init", "Final");	
				}
				else
				{
					$step = 1;
					$domainName = $this->_generic->getSiteConfig("domainName");
					$port = 25;
					$xmlToolBox = $this->getXML();
					$xmlToolBox->addFullTag("defaultDomain",$domainName,true);
					$xmlToolBox->addFullTag("port",$port,true);
					$xmlToolBox->addFullTag("header",'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="FFFFFF" color="000000">',true);
					$xmlToolBox->addFullTag("footer",'</body></html>',true);
					$this->saveXML($xmlToolBox);
				}
			}
		}
		elseif ($this->_http->getParam("mails_reload") == "2")
		{			
			$host 				= SLS_String::trimSlashesFromString($this->_http->getParam("host"));
			$port 				= ($this->_http->getParam("port")=="") ? 25 : SLS_String::trimSlashesFromString($this->_http->getParam("port"));
			$username 			= SLS_String::trimSlashesFromString($this->_http->getParam("username"));
			$password			= SLS_String::trimSlashesFromString($this->_http->getParam("password"));
			$password2			= SLS_String::trimSlashesFromString($this->_http->getParam("password2"));
			$defaultDomain		= ($this->_http->getParam("defaultDomain") == "") ? $this->_generic->getSiteConfig("domainName") : SLS_String::trimSlashesFromString($this->_http->getParam("defaultDomain"));
			$defaultNameSender	= SLS_String::trimSlashesFromString($this->_http->getParam("defaultNameSender"));
			$defaultSender		= SLS_String::trimSlashesFromString($this->_http->getParam("defaultSender"));
			$defaultNameReply	= SLS_String::trimSlashesFromString($this->_http->getParam("defaultNameReply"));
			$defaultReply		= SLS_String::trimSlashesFromString($this->_http->getParam("defaultReply"));
			$defaultNameReturn	= SLS_String::trimSlashesFromString($this->_http->getParam("defaultNameReturn"));
			$defaultReturn		= SLS_String::trimSlashesFromString($this->_http->getParam("defaultReturn"));
			$header				= SLS_String::trimSlashesFromString($this->_http->getParam("header"));
			$footer				= SLS_String::trimSlashesFromString($this->_http->getParam("footer"));
			
			if (empty($host))
				array_push($errors, "You have to fill the SMTP Host");
			if (empty($port))
				array_push($errors, "You have to fill the SMTP Port");
			if (empty($username))
				array_push($errors, "You have to fill the SMTP Username");
			if (empty($password))
				array_push($errors, "You have to fill the SMTP Password");
			else if ($password != $password2)
				array_push($errors, "Both passwords don't match");
			if (empty($defaultDomain))
				array_push($errors, "You have to fill the SMTP Domain");			
			if (empty($defaultNameSender))
				array_push($errors, "You have to fill the `From`' name");
			if (empty($defaultSender))
				array_push($errors, "You have to fill the `From`' alias");
			if (empty($defaultNameReply))
				array_push($errors, "You have to fill the `Reply To`' name");
			if (empty($defaultReply))
				array_push($errors, "You have to fill the `Reply To`' alias");
			if (empty($defaultNameReturn))
				array_push($errors, "You have to fill the `Return-Path`' name");
			if (empty($defaultReturn))
				array_push($errors, "You have to fill the `Return-Path`' alias");
			
			if (empty($errors) && $this->_http->getParam("ping") != "true")
			{
				$dbXml = $this->_generic->getMailXML();
				$dbXml->setTag("host", SLS_Security::getInstance()->encrypt($this->_http->getParam("host"), $this->_generic->getSiteConfig("privateKey")));
				$dbXml->setTag("port", SLS_Security::getInstance()->encrypt($this->_http->getParam("port"), $this->_generic->getSiteConfig("privateKey")));
				$dbXml->setTag("username", SLS_Security::getInstance()->encrypt($this->_http->getParam("username"), $this->_generic->getSiteConfig("privateKey")));
				$dbXml->setTag("password", SLS_Security::getInstance()->encrypt($this->_http->getParam("password"), $this->_generic->getSiteConfig("privateKey")));
				$dbXml->setTag("defaultDomain",$defaultDomain);
				$dbXml->setTag("defaultSender",$defaultSender);
				$dbXml->setTag("defaultNameSender",$defaultNameSender);
				$dbXml->setTag("defaultReply",$defaultReply);
				$dbXml->setTag("defaultNameReply",$defaultNameReply);
				$dbXml->setTag("defaultReturn",$defaultReturn);
				$dbXml->setTag("defaultNameReturn",$defaultNameReturn);
				// Default Template
				$mailTpl = '<item id="default" isSecure="false" js="false" default="true">';
				$mailTpl .= '<header isSecure="false" js="false"><![CDATA['.$header.']]></header>';
				$mailTpl .= '<footer isSecure="false" js="false"><![CDATA['.$footer.']]></footer>';
				$mailTpl .= '</item>';
				$dbXml->appendXMLNode("//mails/templates",$mailTpl);
				file_put_contents($this->_generic->getPathConfig("configSecure")."mail.xml", $dbXml->getXML());
				
				$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"Final",1=>"Congratulations"));
				return $this->_generic->dispatch("SLS_Init", "Final");
			}
			else
			{
				$xmlToolBox = $this->getXML();
				$xmlToolBox->addFullTag("host",$host,true);
				$xmlToolBox->addFullTag("port",$port,true);
				$xmlToolBox->addFullTag("username",$username,true);
				$xmlToolBox->addFullTag("password",$password,true);
				$xmlToolBox->addFullTag("defaultDomain",$defaultDomain,true);
				$xmlToolBox->addFullTag("defaultSender",$defaultSender,true);
				$xmlToolBox->addFullTag("defaultNameSender",$defaultNameSender,true);
				$xmlToolBox->addFullTag("defaultReply",$defaultReply,true);
				$xmlToolBox->addFullTag("defaultNameReply",$defaultNameReply,true);
				$xmlToolBox->addFullTag("defaultReturn",$defaultReturn,true);
				$xmlToolBox->addFullTag("defaultNameReturn",$defaultNameReturn,true);
				$xmlToolBox->addFullTag("header",$header,true);
				$xmlToolBox->addFullTag("footer",$footer,true);
				$this->saveXML($xmlToolBox);
			}
			$step = 1;
		}
		if (!empty($errors) && $this->_http->getParam("ping") != "true")
		{
			$xml->startTag("errors");
			foreach($errors as $error)
				$xml->addFullTag("error", $error, true);
			$xml->endTag("errors");
		}
		if ($this->_http->getParam("ping") == "true")
		{
			$smtp = new SLS_Email("");
			$verdict = $smtp->pingConnection($host,$port,$username,$password);
			$xml->addFullTag("ping",($verdict===true) ? "true" : $verdict,true);
		}
					
		
		$xml->addFullTag("step", $step, true);
		$this->saveXML($xml);
	}