/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Session");
		
		$params = $this->_session->getParams();		
		uksort($params,"strnatcasecmp");
		$this->_xmlToolBox->startTag("params");
		foreach($params as $key => $value)
		{
			$type = "string";

			if (empty($value))
				$value = "null";
			if (is_object($value))
			{
				$value = str_replace("\t","    ", SLS_String::printObject(json_encode($value)));
				$type = "object";
			}
			else if (is_array($value))
			{
				$value = str_replace("\t","    ", SLS_String::printArray($value));
				$type = "array";
			}
			$this->_xmlToolBox->startTag("param", array("type" => $type));
			$this->_xmlToolBox->addFullTag("name",$key,true);
			$this->_xmlToolBox->addFullTag("value",$value,true);
			$this->_xmlToolBox->endTag("param");
		}
		$this->_xmlToolBox->endTag("params");
		
		$this->_xmlToolBox->endTag("Session");
	}	
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml	= $this->makeMenu($xml);
		$environments = $this->getEnvironments();
		$files = array("site","db","project","mail");
		$errors = array();
				
		if ($this->_http->getParam("reload") == "true")
		{
			$environment = $this->_http->getParam("environment");
			if (in_array($environment,$environments))			
				$errors[] = "Environment already exists.";
			else if (empty($environment))
				$errors[] = "You must fill your environment name.";
					
			if (empty($errors))
			{
				foreach($files as $file)
					file_put_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/".$file."_".SLS_String::stringToUrl($environment,"-").".xml",file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure").$file.".xml"));
					
				$this->_generic->forward("SLS_Bo","GlobalSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$environment)));
			}
			else
			{
				$xml->startTag("errors");
				foreach($errors as $error)
					$xml->addFullTag("error",$error,true);
				$xml->endTag("errors");
			}
		}
		
		$this->saveXML($xml);		
	}
	/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0.8
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Cookie");
		
		$cookies = $_COOKIE;		
		foreach($cookies as $name => $content)
		{			
			$cookie = new SLS_Cookie($name);
			$cookieParams = $cookie->getParams();
			if (!empty($cookieParams))
			{
				$this->_xmlToolBox->startTag("item",array("name" => $name));
					$this->_xmlToolBox->startTag("params");
					foreach($cookieParams as $key => $value)
					{
						if (empty($value))
							$value = "null";
						if (is_object($value))
							$value = SLS_String::printArray(SLS_String::objectToArray($value));
						else if (is_array($value))
							$value = SLS_String::printArray($value);
						
						$this->_xmlToolBox->startTag("param");
							$this->_xmlToolBox->addFullTag("name", $key, true);
							$this->_xmlToolBox->addFullTag("value", $value, true);
						$this->_xmlToolBox->endTag("param");
					}
					$this->_xmlToolBox->endTag("params");
				$this->_xmlToolBox->endTag("item");
			}
		}
		
		$this->_xmlToolBox->endTag("Cookie");
	}	
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		
		$table 		= SLS_String::substrAfterFirstDelimiter(SLS_String::trimSlashesFromString($this->_http->getParam("__table")),"_");
		$db			= SLS_String::substrBeforeFirstDelimiter(SLS_String::trimSlashesFromString($this->_http->getParam("__table")),"_");
		$columns 	= $this->_http->getParams();
		$class		= ucfirst($db)."_".SLS_String::tableToClass($table);
		$desc		= SLS_String::trimSlashesFromString($this->_http->getParam("description"));
		
		$this->_generic->useModel($table,$db,"user");
		$object = new $class();
		if (!empty($desc))
			$object->setTableComment($desc,$table,$db);
		
		// Descriptions
		foreach($columns as $key => $value)
		{
			if (SLS_String::startsWith($key,"col_"))
			{
				$column = SLS_String::substrAfterFirstDelimiter($key,"_");
				$object->setColumnComment($column,SLS_String::trimSlashesFromString($value),$table);
			}
		}
		
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","EditModel");
		$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]."/name/".$db."_".$table);
		
		$this->saveXML($xml);
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
		
		$param = $this->_http->getParam("name");
		$model = SLS_String::substrAfterFirstDelimiter($param,"_");
		$alias = SLS_String::substrBeforeFirstDelimiter($param,"_");
		
		if ($this->_http->getParam("type") == "")	
			$actionsTypes = array("list","add","modify","delete","clone");
		else
			$actionsTypes = array($this->_http->getParam("type"));
		foreach($actionsTypes as $actionType)
			$this->deleteActionBo($model,$actionType,$alias);
		
		# Node into bo.xml
		$boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($alias."_".$model)."']";
		$boExists = $xmlBo->getTag($boPath."/@type");
		if (empty($boExists))		
			$boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($alias."_".$model)."']";
		$boExists = $xmlBo->getTag($boPath);
		if (!empty($boExists))
		{
			$xmlBo->deleteTags($boPath, count($xmlBo->getTags($boPath)));
			$xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML());
			$xmlBo->refresh();	
		}
		# /Node into bo.xml
			
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","Bo");
		$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]);
	}
	/**
	 * Action Dir Rights
	 *
	 */
	public function action() 
	{
		$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"DirRights",1=>"Directories"));
		
		// Check files rights
		$pathsToCheck = array(
		"actionsControllers",			"models",		"modelsSql",			"views",				"viewsHeaders",
		"viewsBody",					"viewsGenerics","plugins",				"langs",				"actionLangs",			
		"css",							"scripts",		"js",					"jsStatics",			"jsDyn", 
		"configSecure", 				"configSls",	"genericLangs");
		
		$xmlToolBox = $this->getXML();
		$xmlToolBox->startTag("directories");
		$nextStep = true;
		foreach ($pathsToCheck as $path)
		{	$xmlToolBox->startTag("directory");		
			
			(!is_writable($this->_generic->getPathConfig($path))) ? $xmlToolBox->addFullTag("writable", 0) : $xmlToolBox->addFullTag("writable", 1);
			(!is_readable($this->_generic->getPathConfig($path))) ? $xmlToolBox->addFullTag("readable", 0) : $xmlToolBox->addFullTag("readable", 1);
			(is_dir($this->_generic->getPathConfig($path))) ? $xmlToolBox->addFullTag("path", realpath($this->_generic->getPathConfig($path)), true) : $xmlToolBox->addFullTag("path", SLS_String::substrBeforeLastDelimiter($_SERVER['SCRIPT_FILENAME'],'/').substr($this->_generic->getPathConfig($path), 0, (strlen($this->_generic->getPathConfig($path))-1)), true);
			(!is_writable($this->_generic->getPathConfig($path)) || !is_readable($this->_generic->getPathConfig($path))) ? $nextStep = false : "";
			$xmlToolBox->endTag("directory");		
		}		
		$xmlToolBox->endTag("directories"); 
		if (!$nextStep) 
			$xmlToolBox->addFullTag("next", 0); 
		else
		{
			$xmlToolBox->addFullTag("next", 1);
		}
		$this->_generic->registerLink('authentication', 'SLS_Init', 'Authentication');
		$this->saveXML($xmlToolBox);	
		($nextStep) ? $this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"Authentication",1=>"Authentication")) : false;		
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$actions = array("list","add","modify","delete","clone","email");
				
		// Get the table & class name
		$table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$class = ucfirst($db)."_".SLS_String::tableToClass($table);
		$file  = ucfirst($db).".".SLS_String::tableToClass($table);
		
		$sql = SLS_Sql::getInstance();
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		// If the table exists, delete the bo & model
		if ($sql->tableExists($table))
		{
			foreach($actions as $action)
				if($this->boActionExist($table,$db,$action))
					$this->deleteActionBo($table,$action,$db);
			
			@unlink($this->_generic->getPathConfig("models").$file.".model.php");
			@unlink($this->_generic->getPathConfig("modelsSql").$file.".sql.php");			
		}
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","Models");
		$this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']);
	}
	/**
	 * Constructor
	 *
	 * @access public
	 * @since 1.0
	 */
	public function __construct($xml,$db,$table,$forward=true)
	{
		parent::__construct();
		
		$this->_xml = $xml;
		$this->_db_alias = $db;
		$this->_table = $table;
		$this->_forward = $forward;
		
		# Objects
		$className = ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table);
		$this->_generic->useModel(SLS_String::tableToClass($this->_table),ucfirst(strtolower($this->_db_alias)),"user");
		$this->_object = new $className();
		$this->_table = $this->_object->getTable();
		$nbDelete = 0;
		# /Objects
				
		# Params
		$ids = $this->_http->getParam("id");
		$ids = (SLS_String::contains($ids,"|")) ? explode("|",$ids) : array($ids);
		# /Params
		
		# Perform delete
		foreach($ids as $id)
			if ($this->_object->getModel($id) === true)
				$nbDelete += $this->_object->delete(true);
		if ($this->_object->isMultilanguage() && is_numeric($nbDelete) && $nbDelete > 0)
			$nbDelete = floor($nbDelete / count($this->_lang->getSiteLangs()));
		# Perform delete
		
		if ($this->_async)
		{
			if ($nbDelete !== false && is_numeric($nbDelete) && $nbDelete > 0)
			{
				$this->_render["status"] = "OK";
				$this->_render["result"]["message"] = ($nbDelete==1) ? $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_DELETE'] : sprintf($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_DELETES'],$nbDelete);
			}
			echo json_encode($this->_render);
			die();
		}
		else
		{
			# Notif
			if ($nbDelete !== false && is_numeric($nbDelete) && $nbDelete > 0)
				$this->pushNotif("success",($nbDelete==1) ? $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_DELETE'] : sprintf($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_GENERIC_SUBMIT_SUCCESS_DELETES'],$nbDelete));
			# /Notif
			
			# Forward
			if ($this->_forward)
			{
				$rememberList = (is_array($this->_session->getParam("SLS_BO_LIST"))) ? $this->_session->getParam("SLS_BO_LIST") : array();
				if (array_key_exists($this->_db_alias."_".$this->_table,$rememberList) && !empty($rememberList[$this->_db_alias."_".$this->_table]))
					$this->_generic->redirect($rememberList[$this->_db_alias."_".$this->_table]);
				else
					$this->_generic->forward($this->_boController,"List".ucfirst(strtolower($this->_db_alias))."_".SLS_String::tableToClass($this->_table));
			}
		}
		# /Forward
	}
	/**
	 * Get the XML of the static controller
	 *
	 * @access public
	 * @return string $xml the xml
	 * @since 1.0
	 */
	public function getXML()
	{
		if ($this->_onSide == 'user')
		{
			$this->_xmlToolBox->endTag(SLS_String::substrBeforeLastDelimiter(get_class($this), "Controller"));
		}
		return $this->_xmlToolBox->getXML('noHeader');
	}	
	public function action()
	{
		// Objects
		$xml = $this->getXML();
		$xml->addFullTag("view_log",$this->_generic->getFullPath("SLS_Bo","LogsMonitoring",array(),false));
		
		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		
		// Get the existing logs
		$dates = array();
		$all = array();
		$handle = opendir($this->_generic->getPathConfig("logs")."monitoring");
		
		// Foreach directories 
		while (false !== ($dir = readdir($handle)))
		{
			if (is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir) && substr($dir, 0, 1) != ".") 
			{				
				$handle2 = opendir($this->_generic->getPathConfig("logs")."/monitoring/".$dir);				
				while (false !== ($file = readdir($handle2)))
				{					
					if (!is_dir($this->_generic->getPathConfig("logs")."/monitoring/".$dir."/".$file) && substr($file, 0, 1) != ".") 
					{
						$date = explode("-",substr($file,0,10));						
						if (!in_array(substr($file,0,10),$dates))
						{
							$array = array("year"=>$date[0],"month"=>$date[1],"day"=>$date[2]);
							array_push($all,$array);
							array_push($dates,substr($file,0,10));
						}
					}
				}
			}
		}
		if (!empty($all))
		{
			$all = SLS_String::arrayMultiSort($all,array(array('key'=>'year','sort'=>'desc'),array('key'=>'month','sort'=>'desc'),array('key'=>'day','sort'=>'desc')));
			
			$xml->startTag("logs");
			foreach($all as $allC)			
			{
				$dateL = new SLS_Date($allC["year"]."-".$allC["month"]."-".$allC["day"]);
				$xml->startTag("log");
				$xml->addFullTag("year",$allC["year"],true);
				$xml->addFullTag("month",$allC["month"],true);
				$xml->addFullTag("day",$allC["day"],true);
				$xml->addFullTag("litteral",ucwords($dateL->getDate("FULL_LITTERAL")));
				$xml->endTag("log");
			}
			$xml->endTag("logs");
		}
		
		$this->saveXML($xml);
	}
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$plugId = $this->_http->getParam('Plugin');
		$field 	= $this->_http->getParam('Field');
		$action = $this->_http->getParam('Action');
		$controllers = $this->_generic->getTranslatedController('SLS_Bo', 'EditPlugin');
		
		if (empty($plugId) || SLS_PluginsManager::isExists($plugId) === false)
			$this->dispatch('SLS_Bo', 'Plugins');
		
		$plugin = new SLS_PluginsManager($plugId);
		$xmlPlug = $plugin->getXML();
		
		if (empty($field) || empty($action))
			$this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls");
		
				
		$xpath = "//".str_replace("|||", "/", str_replace("|$|", "]", str_replace("$|$", "[", $field)));
		
		$clonable = array_shift($xmlPlug->getTags($xpath."/@clonable"));
		if ($clonable != 1)
			$this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls");
		
		$nodeName = SLS_String::substrBeforeLastDelimiter($xpath, "[");
			
		if ($action == "del" && count($xmlPlug->getTags($nodeName)) > 1)
		{
			$xmlPlug->deleteTags($xpath, 1);
		}
		if ($action == "add")
		{
			$node = new SLS_XMLToolbox($xmlPlug->getNode($xpath));
			$parent = SLS_String::substrBeforeLastDelimiter($xpath, "/");
			$xmlPlug->appendXMLNode($xpath, $node->getXml('noHeader'), 1, "after");
			$newIndex = SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($xpath, "["), "]");
			$newIndex++;
			$newNode = SLS_String::substrBeforeLastDelimiter($xpath, "[")."[".$newIndex."]";
			if ($xmlPlug->countChilds($newNode) == 0)
				$xmlPlug->setTag($newNode, "", false);
			else 
				$xmlPlug = $this->removeRecursiveValues($newNode, $xmlPlug);
			

			
			$xmlPlug->setTagAttributes($newNode, array("alias"=>uniqid()));
			
			
		}
		$plugin->saveXML($xmlPlug);		
		$this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls");
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		
		$xml->startTag("templates");
		$handle = opendir($this->_generic->getPathConfig("viewsTemplates"));
		while($file = readdir($handle))
		{
			if (is_file($this->_generic->getPathConfig("viewsTemplates").$file) && substr($file, 0, 1) != ".")
			{
				$fileName 	= SLS_String::substrBeforeLastDelimiter($file,".");
				$extension 	= SLS_String::substrAfterLastDelimiter($file,".");
				
				if ($extension == "xsl" && $fileName != "__default")
				{
					$xml->startTag("template");
					$xml->addFullTag("name",$fileName,true);					
					$xml->endTag("template");
				}
			}
		}
		closedir($handle);
		$xml->addFullTag("url_add",$this->_generic->getFullPath("SLS_Bo","AddTemplate"),true);
		$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","DeleteTemplate",array(),false),true);
		$xml->endTag("templates");		
		
		$xml->startTag("generics");
		$handle = opendir($this->_generic->getPathConfig("viewsGenerics"));
		while($file = readdir($handle))
		{
			if (is_file($this->_generic->getPathConfig("viewsGenerics").$file) && substr($file, 0, 1) != ".")
			{
				$fileName 	= SLS_String::substrBeforeLastDelimiter($file,".");
				$extension 	= SLS_String::substrAfterLastDelimiter($file,".");
				
				if ($extension == "xsl")
				{
					$xml->startTag("generic");
					$xml->addFullTag("name",$fileName,true);					
					$xml->endTag("generic");
				}
			}
		}
		closedir($handle);
		$xml->addFullTag("url_add",$this->_generic->getFullPath("SLS_Bo","AddGeneric"),true);
		$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","DeleteGeneric",array(),false),true);
		$xml->endTag("generics");		
		
		$this->saveXML($xml);		
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);

		$controller = SLS_String::trimSlashesFromString($this->_http->getParam('Controller'));
		if (is_file($this->_generic->getPathConfig("componentsControllers").$controller.".controller.php"))
		{
			unlink($this->_generic->getPathConfig("componentsControllers").$controller.".controller.php");
		}
		$this->_generic->dispatch('SLS_Bo', 'Controllers');
		$this->saveXML($xml);
	}
	/**
	 * Action Home
	 *
	 */
	public function action() 
	{
		$this->secureURL();
		
		$this->_generic->registerLink('authentication', 'SLS_Init', 'Authentication');
		$reload = $this->_http->getParam('authentication_reload');
		$login = SLS_String::trimSlashesFromString($this->_http->getParam('auth_login'));
		$pass1 =  SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass1'));
		$pass2 = SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass2'));
		$xml = $this->getXML();
		$errors = array();
		if ($reload == 'true')
		{
			if (strlen($login) < 6)
				array_push($errors, "The administrator username should have 6 caracters at least");
			if (strlen($pass1) < 6)
				array_push($errors, "The password should have 6 caracters at least");
			if ($pass1 != $pass2)
				array_push($errors, "Both password must be the same");
			
			if (empty($errors))
			{
				if (!is_file($this->_generic->getPathConfig('configSls')."sls.xml") && !touch($this->_generic->getPathConfig('configSls')."sls.xml"))
					$this->_generic->dispatch('SLS_Init', 'DirRights');
				else 
				{
					$coreXml = $this->_generic->getCoreXml('sls');
					$user = new SLS_XMLToolbox(false);
					$user->startTag("user", array("login"=>sha1($login),"pass"=>sha1($pass1),"level"=>"0"));
					$user->endTag("user");
					$coreXml->appendXMLNode("//sls_configs/auth/users", $user->getXML('noHeader'));
					file_put_contents($this->_generic->getPathConfig("configSls")."sls.xml", $coreXml->getXML());
					$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"GlobalSettings",1=>"Settings"));
					return $this->_generic->dispatch("SLS_Init", "GlobalSettings");
				}
			}
			else 
			{				
				$xml->startTag("errors");
				foreach ($errors as $error)
					$xml->addFullTag("error", $error, true);
				$xml->endTag("errors");
			}
		}
		$this->saveXML($xml);
	}
	public function action() 
	{		
		// Objects		
		$user = $this->hasAuthorative();		
			
		$name = SLS_String::trimSlashesFromString($this->_http->getParam("name"));						
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");
		$xmlRights = new SLS_XMLToolbox($pathsHandle);			
		$result = $xmlRights->getTags("//sls_configs/entry[@login='******']");
				
		if (!empty($result))
		{								
			$xmlRights->deleteTags('//sls_configs/entry[@login="******"]');
			$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());
		}
		$this->_generic->redirect("Manage/Rights");		
	}
	public function action()
	{
		// Params
		$name = SLS_String::trimSlashesFromString($this->_http->getParam("name"));
		
		// Objects
		$user = $this->hasAuthorative();
		$xmlRights = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"));
		$result = $xmlRights->getTags("//sls_configs/entry[@login='******']");
		
		if (!empty($result))
		{
			$xmlRights->setTagAttributes('//sls_configs/entry[@login="******"]', array("enabled" => ($xmlRights->getTag('//sls_configs/entry[@login="******"]/@enabled')=='false') ? 'true' : 'false'));
			$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml");
		}
		
		$this->_generic->forward("SLS_Bo","ManageRights");
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		$listing = true;
		$errors = array();
		$controller = SLS_String::trimSlashesFromString($this->_http->getParam('Controller'));
		$scontroller = SLS_String::trimSlashesFromString($this->_http->getParam('Action'));
		$controllersXML = $this->_generic->getControllersXML();
		
		if (($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $scontroller != 'Index') || ($controller == 'Default' && ($scontroller != 'UrlError' && $scontroller != 'BadRequestError' && $scontroller != 'TemporaryRedirectError' && $scontroller != 'MaintenanceError' && $scontroller != 'AuthorizationError' && $scontroller != 'ForbiddenError' && $scontroller != 'InternalServerError'))))
		{
			$countScontroller = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name = '".$scontroller."']");
			if (count($countScontroller) == 1)
			{
				// Delete Action Files
				if (is_file($this->_generic->getPathConfig("viewsHeaders").$controller."/".$scontroller.".xsl"))
					unlink($this->_generic->getPathConfig("viewsHeaders").$controller."/".$scontroller.".xsl");
				if (is_file($this->_generic->getPathConfig("viewsBody").$controller."/".$scontroller.".xsl"))
					unlink($this->_generic->getPathConfig("viewsBody").$controller."/".$scontroller.".xsl");
				if (is_file($this->_generic->getPathConfig("actionsControllers").$controller."/".$scontroller.".controller.php"))
					unlink($this->_generic->getPathConfig("actionsControllers").$controller."/".$scontroller.".controller.php");
				foreach ($langs as $lang)
				{
					if (is_file($this->_generic->getPathConfig("actionLangs").$controller."/".$scontroller.".".$lang.".lang.php"))
						unlink($this->_generic->getPathConfig("actionLangs").$controller."/".$scontroller.".".$lang.".lang.php");
				}
				// Delete XML Lines
				$actionID = array_shift($controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name='".$scontroller."']/@id"));
				$controllersXML->deleteTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name = '".$scontroller."']");
				file_put_contents($this->_generic->getPathConfig('configSecure')."controllers.xml", $controllersXML->getXML());
				
				$metasXML = $this->_generic->getCoreXML('metas');
				$metasXML->deleteTags("//sls_configs/action[@id='".$actionID."']");
				file_put_contents($this->_generic->getPathConfig('configSls')."metas.xml", $metasXML->getXML());
				
			}
		}
		
		$this->_generic->forward('SLS_Bo', 'Controllers');	
		$this->saveXML($xml);
	}
	public function action()
	{
		$user = $this->hasAuthorative();
				
		// Objects		
		$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
		$xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml"));
						
		// Get the table & class name
		$table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$class = ucfirst($db)."_".SLS_String::tableToClass($table);
		
		$result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1")));
		if (!empty($result))
			$xmlBearer->saveXML($this->_generic->getPathConfig("configSls")."/bearers.xml",$xmlBearer->deleteTags("//sls_configs/entry[@tableBearer='".$class."']"));
		
		$this->_generic->forward("SLS_Bo","EditModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));
	}
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml 	= $this->makeMenu($xml);		
		$errors = array();		
		$tpls 	= $this->getAppTpls();
		$siteXML = $this->_generic->getSiteXML();
		$ga = $siteXML->getTag("//configs/google/setting[@name='ua']");
		
		if ($this->_http->getParam("reload") == "true")
		{
			$tpl = SLS_String::trimSlashesFromString(SLS_String::stringToUrl($this->_http->getParam("tpl_name"),"_"));
			$doctype = $this->_http->getParam("doctype");
			
			if (empty($tpl))
				array_push($errors,"You must choose a name for your template");
			else if (in_array($tpl,$tpls))
				array_push($errors,"This template name already exists, please choose another one");
				
			if (empty($errors))
			{
				$this->createXslTemplate($tpl,$doctype,$ga);
				$this->_generic->goDirectTo("SLS_Bo","Templates");
			}
			else
			{
				$xml->startTag("errors");
				foreach($errors as $error)
					$xml->addFullTag("error",$error,true);
				$xml->endTag("errors");
				
				$xml->addFullTag("doctype",(empty($doctype)) ? $this->_generic->getSiteConfig("defaultDoctype") : $doctype,true);
			}
		}
		else
		{
			$xml->addFullTag("doctype",$this->_generic->getSiteConfig("defaultDoctype"),true);
		}
		
		$this->saveXML($xml);
	}	
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$tpls 	= $this->getAppTpls();
		
		$tpl = SLS_String::trimSlashesFromString($this->_http->getParam("name"),"_");
		
		if (in_array($tpl,$tpls))
		{
			try {
				unlink($this->_generic->getPathConfig("viewsTemplates").$tpl.".xsl");
			}
			catch (Exception $e)
			{
				SLS_Tracing::addTrace($e);
			}
		}
		
		$this->_generic->goDirectTo("SLS_Bo","Templates");
	}	
	public function action()
	{
		$user = $this->hasAuthorative();
		
		$redirect		= true;		
		$param	 		= $this->_http->getParam("name");		
		$model			= SLS_String::substrAfterFirstDelimiter($param,"_");
		$alias			= SLS_String::substrBeforeFirstDelimiter($param,"_");				
		$checkbox		= $this->_http->getParam("redirect");
		
		if (empty($checkbox))
			$redirect = false;
		
		$controllersXML = $this->_generic->getControllersXML();
		$controller 	= array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));
		
		$this->createActionBoAdd($controller,$model,$alias,$redirect);
		
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","EditBo");
		$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]."/name/".$param.".sls");
	}
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml 	= $this->makeMenu($xml);		
		$errors = array();		
		$generics 	= $this->getAppXsl();
		
		if ($this->_http->getParam("reload") == "true")
		{
			$generic = ucfirst(SLS_String::trimSlashesFromString(SLS_String::stringToUrl($this->_http->getParam("generic_name"),"_")));
			
			if (empty($generic))
				array_push($errors,"You must choose a name for your generic");
			else if (in_array(strtolower($generic),$generics))
				array_push($errors,"This generic name already exists, please choose another one");
				
			if (empty($errors))
			{
				$str =  '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
						t(1).'<xsl:template name="'.$generic.'">'."\n".
							t(2).''."\n".
						t(1).'</xsl:template>'."\n".
						'</xsl:stylesheet>';
				file_put_contents($this->_generic->getPathConfig("viewsGenerics").$generic.".xsl",$str);
				$this->_generic->goDirectTo("SLS_Bo","Templates");
			}
			else
			{
				$xml->startTag("errors");
				foreach($errors as $error)
					$xml->addFullTag("error",$error,true);
				$xml->endTag("errors");
			}
		}
		
		
		$this->saveXML($xml);
	}	
	public function action()
	{
		$user 		= $this->hasAuthorative();
		$xml 		= $this->getXML();
		$xml		= $this->makeMenu($xml);
		$mailXML 	= $this->_generic->getMailXML();
		$templates  = $mailXML->getTags("//mails/templates/item/@id");
		
		if ($this->_http->getParam("reload") == "true")
		{
			foreach($templates as $template)
			{
				$header = SLS_String::trimSlashesFromString($this->_http->getParam("template_".$template."_header"));
				$footer = SLS_String::trimSlashesFromString($this->_http->getParam("template_".$template."_footer"));
				
				$mailXML->setTag("//mails/templates/item[@id='".$template."']/header",$header);
				$mailXML->setTag("//mails/templates/item[@id='".$template."']/footer",$footer);
			}
			$mailXML->saveXML($this->_generic->getPathConfig("configSecure")."mail.xml");
		}
		
		$xml->startTag("templates");
		for($i=0 ; $i<$count=count($templates) ; $i++)
		{
			$id = $templates[$i];
			$xml->startTag("template");
				$xml->addFullTag("id",$id,true);
				$xml->addFullTag("header",($mailXML->getTag("//mails/templates/item[@id='".$id."']/header")),true);
				$xml->addFullTag("footer",($mailXML->getTag("//mails/templates/item[@id='".$id."']/footer")),true);
				$xml->addFullTag("url_preview",$this->_generic->getFullPath("SLS_Bo","MailTemplatesPreview",array(array("key"=>"TplId","value"=>$id))),true);
				$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","MailTemplatesDelete",array(array("key"=>"TplId","value"=>$id))),true);
			$xml->endTag("template");
		}
		$xml->endTag("templates");
		
		$xml->addFullTag("url_template_add",$this->_generic->getFullPath("SLS_Bo","MailTemplatesAdd"),true);
		
		$this->saveXML($xml);		
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		$listing = true;
		$errors = array();
		$controllersXML = $this->_generic->getControllersXML();
		$controller = SLS_String::trimSlashesFromString($this->_http->getParam('Controller'));
		
		if ($controller != 'Home' && $controller != 'Default')
		{
		// We want to delete the controller
		
			$controllers = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']");
			if (count($controllers) == 1)
			{
				$controllerId = array_shift($controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/@id"));
				// Delete all files
				// Views Header
				(is_dir($this->_generic->getPathConfig("viewsHeaders").$controller)) ? $this->_generic->rm_recursive($this->_generic->getPathConfig("viewsHeaders").$controller) : SLS_Tracing::addTrace(new Exception("Directory ".$this->_generic->getPathConfig("viewsHeaders").$controller." cannot be removed"));
				// Views Body
				(is_dir($this->_generic->getPathConfig("viewsBody").$controller)) ? $this->_generic->rm_recursive($this->_generic->getPathConfig("viewsBody").$controller) : SLS_Tracing::addTrace(new Exception("Directory ".$this->_generic->getPathConfig("viewsBody").$controller." cannot be removed"));
				// Langs
				(is_dir($this->_generic->getPathConfig("actionLangs").$controller)) ? $this->_generic->rm_recursive($this->_generic->getPathConfig("actionLangs").$controller) : SLS_Tracing::addTrace(new Exception("Directory ".$this->_generic->getPathConfig("actionLangs").$controller." cannot be removed"));
				// Delete controller Directory
				(is_dir($this->_generic->getPathConfig("actionsControllers").$controller)) ? $this->_generic->rm_recursive($this->_generic->getPathConfig("actionsControllers").$controller) : SLS_Tracing::addTrace(new Exception("Directory ".$this->_generic->getPathConfig("actionsControllers").$controller." cannot be removed"));
				// Delete XML Informations
				$controllersXML->deleteTags("//controllers/controller[@side='user' and @name='".$controller."']");
				file_put_contents($this->_generic->getPathConfig('configSecure')."controllers.xml", $controllersXML->getXML());
				$metasXML = $this->_generic->getCoreXML('metas');
				$metasXML->deleteTags("//sls_configs/action[@id='".$controllerId."']");
				file_put_contents($this->_generic->getPathConfig('configSls')."metas.xml", $metasXML->getXML());
			}
		}
		$this->_generic->forward('SLS_Bo', 'Controllers');
		$this->saveXML($xml);
	}
	public function action()
	{
		$user 		= $this->hasAuthorative();
		$xml 		= $this->getXML();
		$xml		= $this->makeMenu($xml);
		$mailXML 	= $this->_generic->getMailXML();
				
		if ($this->_http->getParam("reload") == "true")
		{
			$id = strtolower($this->_http->getParam("tpl_id"));
			$header = SLS_String::trimSlashesFromString($this->_http->getParam("tpl_header"));
			$footer = SLS_String::trimSlashesFromString($this->_http->getParam("tpl_footer"));
			
			$result = $mailXML->getTag("//mails/templates/item[@id='".$id."']/header");
			
			if (empty($result))
			{
				$str_xml = '<item id="'.$id.'" isSecure="false" js="false">
	      <header isSecure="false" js="false"><![CDATA['.$header.']]></header>
	      <footer isSecure="false" js="false"><![CDATA['.$footer.']]></footer>
	    </item>';
				$mailXML->appendXMLNode("//templates",$str_xml);
				$mailXML->saveXML($this->_generic->getPathConfig("configSecure")."mail.xml");
				$this->_generic->forward("SLS_Bo","MailTemplates");
			}
			else
			{
				$xml->addFullTag("error","This name is already use by another template",true);
				$xml->startTag("template");
					$xml->addFullTag("id",$id,true);
					$xml->addFullTag("header",$header,true);
					$xml->addFullTag("footer",$footer,true);					
				$xml->endTag("template");
			}
		}
				
		$this->saveXML($xml);		
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		
		$controllersXML = $this->_generic->getControllersXML();
		$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));
		
		if (!empty($controller))
		{
			$param = $this->_http->getParam("name");
			$model = SLS_String::substrAfterFirstDelimiter($param,"_");
			$alias = SLS_String::substrBeforeFirstDelimiter($param,"_");			
			$type = ucfirst($this->_http->getParam("type"));
			
			$actionTypes = array("List","Add","Modify","Delete","Clone","Email");
			
			if (in_array($type,$actionTypes))			
				$this->{createActionBo.$type}($controller,$model,$alias);			
		}
		
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","Bo");
		$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]);
	}
	/**
	 * Construct the XML
	 *
	 * @access public
	 * @since 1.0
	 */
	public function constructXML()
	{
		$this->_xmlToolBox->startTag("Http");
		
		$methods = array("GET","POST","FILES");		
		$this->_xmlToolBox->startTag("params");
			$params = $this->_http->getParams();
			uksort($params,"strnatcasecmp");
			foreach($params as $key => $value)
			{
				$this->_xmlToolBox->startTag("param",array("method"=>"NATIVE","type" => ((is_array($value)) ? "array" : "string")));
					$this->_xmlToolBox->addFullTag("name",$key,true);
					$this->_xmlToolBox->addFullTag("value",(is_array($value)) ? str_replace("\t","    ",  SLS_String::printArray($value)) : $value,true);
				$this->_xmlToolBox->endTag("param");
			}
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericmode",true);
				$this->_xmlToolBox->addFullTag("value",$this->_generic->getGenericControllerName(),true);
			$this->_xmlToolBox->endTag("param");
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericsmode",true);
				$this->_xmlToolBox->addFullTag("value",$this->_generic->getGenericScontrollerName(),true);
			$this->_xmlToolBox->endTag("param");
			$controllerBo = array_shift($this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo='true']/@name"));
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","genericmodebo",true);
				$this->_xmlToolBox->addFullTag("value",$controllerBo,true);
			$this->_xmlToolBox->endTag("param");
			$this->_xmlToolBox->startTag("param",array("method"=>"SLS","type"=>"string"));
				$this->_xmlToolBox->addFullTag("name","request_uri",true);
				$this->_xmlToolBox->addFullTag("value",str_replace("/","|",substr($_SERVER["REQUEST_URI"],1)),true);
			$this->_xmlToolBox->endTag("param");
		$this->_xmlToolBox->endTag("params");
		
		$this->_xmlToolBox->endTag("Http");
	}
	public function action() 
	{		
		// Objects
		$xml = $this->getXML();
		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		$this->_generic->registerLink('Add', 'SLS_Bo', 'AddRight');
		$xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteRight",array(),false));
		$xml->addFullTag("edit",$this->_generic->getFullPath("SLS_Bo","EditRight",array(),false));
		
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");		
		$xmlRights = new SLS_XMLToolbox($pathsHandle);
		$result = $xmlRights->getTagsAttributes("//sls_configs/entry",array("login","password","name","firstname","enabled"));
				
		$xml->startTag("accounts");
		for($i=0 ; $i<$count=count($result) ; $i++)
		{
			$xml->startTag("account");
			for($j=0 ; $j<$count2=count($result[$i]["attributes"]) ; $j++)
			{				
				if ($result[$i]["attributes"][$j]["key"] == "password")
					$xml->addFullTag($result[$i]["attributes"][$j]["key"],"******",true);
				else if (SLS_String::contains($result[$i]["attributes"][$j]["key"],"name"))
					$xml->addFullTag($result[$i]["attributes"][$j]["key"],ucwords(strtolower($result[$i]["attributes"][$j]["value"])),true);
				else
					$xml->addFullTag($result[$i]["attributes"][$j]["key"],$result[$i]["attributes"][$j]["value"],true);
			}
			$xml->addFullTag("color",$xmlRights->getTag("//sls_configs/entry[@login='******']/settings/setting[@key='color']"),true);
			$xml->endTag("account");
		}
		$xml->endTag("accounts");
		
		$xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ManageRightsStatus",array(),false));
		
		$this->saveXML($xml);
	}
	public function action()
	{
		// Objects
		$xml = $this->getXML();

		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		
		$date = $this->_http->getParam("date");
		$dateE = explode("-",$date);
		$dateL = new SLS_Date($date);
		
		if (is_array($dateE) && count($dateE) == 3 && is_dir($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]))
		{
			$content = "";
			$i = 0;
			
			while(file_exists($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log"))
			{
				$content .= file_get_contents($this->_generic->getPathConfig("logs")."monitoring/".$dateE[0]."-".$dateE[1]."/".$dateE[0]."-".$dateE[1]."-".$dateE[2]."_".$i.".log");
				$i++;
			}
			$batchs = explode("#|end|#",$content);
			
			$xml->startTag("batchs");
			$xml->addFullTag("date",$dateL->getDate("FULL_LITTERAL"));
			foreach($batchs as $batch)
			{
				if (!empty($batch))
				{
					$lines = explode("\n",$batch);
					
					$times = array ("Render"			=> 0,
									"XML/XSL Parsing"	=> 0,									
									"MySQL Query"		=> 0,
									"Controller Action"	=> 0,
									"Controller Front"	=> 0,
									"Controller Static" => 0);
					$msg = "";
					$totalTime = 0;
					$endTime = 0;
					
					$xml->startTag("batch");
						$xml->startTag("lines");
						foreach($lines as $line)
						{
							$infos = explode("||",$line);
							$infos = array_map('trim',$infos);
							
							if (count($infos) > 4)
							{
								$times[$infos[0]] += $infos[2];
								if ($infos[0] == "Render")
								{
									$totalTime = $infos[2];
									$endTime = SLS_String::substrAfterFirstDelimiter($infos[1]," ");
								}
								if ($infos[0] == "Controller Front")								
									$msg = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($infos[3],")"),"(");
								
								$xml->startTag("line");
									$xml->addFullTag("msg",$infos[3],true);
									$xml->addFullTag("type",$infos[0],true);
									$xml->addFullTag("more",str_replace(array("|n|","|t|","    "),array("<br />","&#160;&#160;","&#160;&#160;&#160;&#160;"),$infos[4]),true);
									$xml->addFullTag("time",SLS_String::substrAfterFirstDelimiter($infos[1]," "),true);
									$xml->addFullTag("duration",$infos[2],true);
								$xml->endTag("line");
							}
						}
						$xml->endTag("lines");
						$xml->startTag("infos");
							$xml->addFullTag("name",$endTime." - ".$msg,true);
							$xml->startTag("times");
								$xml->addFullTag("total",$totalTime,true);
								foreach($times as $key => $value)
									$xml->addFullTag(SLS_String::stringToUrl(trim($key),"_"),$value,true);
							$xml->endTag("times");
						$xml->endTag("infos");
						$sum = 0;
						$xml->startTag("ratios");
						foreach($times as $key => $value)
						{
							if ($key == "Render")
								continue;
							else
								$sum += $value;
								
							$xml->startTag("ratio");
								$xml->addFullTag("label",str_replace(" ","+",trim($key)),true);
								$xml->addFullTag("duration",$times[$key],true);								
								$xml->addFullTag("degree",($totalTime > 0) ? 360 * $value / $totalTime : "360",true);
							$xml->endTag("ratio");
						}
						if ($totalTime - $sum > 0)
						{
							$xml->startTag("ratio");
								$xml->addFullTag("label","Others",true);
								$xml->addFullTag("duration",$sum,true);	
								$xml->addFullTag("degree",($totalTime > 0) ? 360 * $sum / $totalTime : "360",true);
							$xml->endTag("ratio");
						}
						$xml->endTag("ratios");
					$xml->endTag("batch");
				}
			}
			$xml->endTag("batchs");			
		}
		
		$this->saveXML($xml);
	}
    /**
     * Calculate xPath of the given DOMNode
     * 
     * @access public static
     * @param DOMNode $node
     * @return string $xpath xPath
     * @since 1.1
     */
	public static function calculateXPath(DOMNode $node)
	{
		// Easy
		if (method_exists($node,'getNodePath'))
			return '/'.str_replace('/text()','',$node->getNodePath());
		
		// Let's go...
	    $q     = new DOMXPath($node->ownerDocument);
	    $xpath = '';
	    do
	    {
	    	$prevSibling = $q->query('preceding-sibling::*[name()="' . $node->nodeName . '"]', $node)->length;
	    	$nextSibling = $q->query('following-sibling::*[name()="' . $node->nodeName . '"]', $node)->length;
	        $position = 1 + $prevSibling;
	        if (!SLS_String::startsWith($node->nodeName,"#"))
	        {
	        	$xpathS    = '/' . $node->nodeName;
	        	if ($prevSibling > 0 || $nextSibling > 0)
	        		$xpathS .= '[' . $position . ']';
	        	$xpath = $xpathS.$xpath;
	        }
	        $node     = $node->parentNode;
	    }
	    while (!$node instanceof DOMDocument);
	    return '/'.$xpath;
	}