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']);
	}
Ejemplo n.º 2
0
	/**
	 * Constructor
	 *
	 * @access public
	 * @param string $table SQL table describing current child model
	 * @param string $primaryKey SQL primary key describing current child model
	 * @param bool $multilanguage true if the we have multilanguage content, else false
	 * @since 1.0
	 */
	public function __construct($table,$primaryKey,$multilanguage=false) 
	{
		$this->_isMultilanguage = ($multilanguage) ? true : false;
		
		$this->_db = SLS_Sql::getInstance();
		$this->_generic = SLS_Generic::getInstance();
		$this->_table = $table;
		$this->_primaryKey = $primaryKey;
	}
	public function action()
	{
		// Objects
		$this->useModel('Sls_graph',$this->defaultDb,"sls");
		$className = ucfirst($this->defaultDb)."_Sls_graph";
		$slsGraph = new $className();
		$db = SLS_Sql::getInstance();
		$user = $this->hasAuthorative();
		
		// Params
		$slsGraphId = $this->_http->getParam('id');
		
		// Get graph
		if ($slsGraph->getModel($slsGraphId) === true)
		{
			$sql = "DELETE
						g, 
						gq, 
						gqc, 
						gqj, 
						gqw, 
						gqg, 
						gqo, 
						gql 
					FROM
						sls_graph g LEFT JOIN 
						sls_graph_query gq ON (g.sls_graph_query_id = gq.sls_graph_query_id) LEFT JOIN 
						sls_graph_query_column gqc ON (gq.sls_graph_query_id = gqc.sls_graph_query_id) LEFT JOIN
						sls_graph_query_join gqj ON (gq.sls_graph_query_id = gqj.sls_graph_query_id) LEFT JOIN
						sls_graph_query_where gqw ON (gq.sls_graph_query_id = gqw.sls_graph_query_id) LEFT JOIN
						sls_graph_query_group gqg ON (gq.sls_graph_query_id = gqg.sls_graph_query_id) LEFT JOIN
						sls_graph_query_order gqo ON (gq.sls_graph_query_id = gqo.sls_graph_query_id) LEFT JOIN  
						sls_graph_query_limit gql ON (gq.sls_graph_query_id = gql.sls_graph_query_id) 
					WHERE
						g.sls_graph_id = ".$db->quote($slsGraphId)." ";
			$db->delete($sql);
		}
		
		$this->_generic->forward("SLS_Bo","ReportingBo");
	}
	public function action()
	{
		// Objects
		$this->useModel('Sls_graph',$this->defaultDb,"sls");
		$className = ucfirst($this->defaultDb)."_Sls_graph";
		$slsGraph = new $className();
		$db = SLS_Sql::getInstance();
		$user = $this->hasAuthorative();
		
		// Params
		$slsGraphId = $this->_http->getParam('id');
		
		// Get graph
		if ($slsGraph->getModel($slsGraphId) === true)
		{			
			$slsGraph->setSlsGraphVisible(($slsGraph->__get("sls_graph_visible") == "yes") ? "no" : "yes");
			$slsGraph->save();
		}
		
		if ($this->_http->getParam("from") == "view")
			$this->_generic->forward("SLS_Bo","ReportingBoView",array("id" => $slsGraphId));
		else
			$this->_generic->forward("SLS_Bo","ReportingBo");
	}
Ejemplo n.º 5
0
	public function constructXML()
	{
		$this->_boController = $this->_generic->getBo();
		
		if ($this->_generic->getGenericControllerName() == $this->_boController)
		{
			@include_once($this->_generic->getPathConfig("actionLangs").$this->_boController."/__".$this->_boController.".".$this->_lang->getLang().".lang.php");
			
			$db = SLS_Sql::getInstance();
			$dbsAlias = $db->getDbs();
			$comments = array();
			foreach($dbsAlias as $dbAlias)
			{
				$db->changeDb($dbAlias);
				$tables = $db->showTables();			
				for($i=0 ; $i<$count=count($tables) ; $i++)
				{
					$table = $tables[$i]->Name;
					$key = ucfirst(strtolower($dbAlias))."_".SLS_String::tableToClass($table);
					if (!array_key_exists($key,$comments))
					{
						$comment = $tables[$i]->Comment;
						if (SLS_String::startsWith($comment,"sls:lang:"))
						{
							$globalKey = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:"));
							$comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey];
						}
						$comments[$key] = (empty($comment)) ? $table : $comment;
					}
				}
			}
			$db->changeDb($db->connectToDefaultDb());
			
			# Nav
			if (SLS_BoRights::isLogged())
			{
				$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
				$entries = $xmlBo->getTagsAttributes("//sls_configs/entry",array("type","name"));		
				$this->_xmlToolBox->startTag("nav");
					if (!empty($entries))
					{
						# BOs
						$this->_xmlToolBox->startTag("section");
							$this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_SITE'],"true");
							$this->_xmlToolBox->addFullTag("href","#","true");
							$this->_xmlToolBox->startTag("categories");
							for($i=0 ; $i<$count=count($entries) ; $i++)
							{
								$position = ($i+1);
								$type = $entries[$i]["attributes"][0]["value"];
								$name = $entries[$i]["attributes"][1]["value"];
								
								if ($type == "category")
								{
									$childs = $xmlBo->getTagsAttributes("//sls_configs/entry[".$position."]/entry",array("type","name"));
									$comment = $name;
									if (SLS_String::startsWith($comment,"sls:lang:"))
									{
										$globalKey = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:"));
										$comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) ? $name : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$globalKey]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$globalKey];
									}
									$this->_xmlToolBox->startTag("category",array("type"=>"category"));
										$this->_xmlToolBox->addFullTag("title",$comment,"true");
										$this->_xmlToolBox->addFullTag("href","#","true");
										if (!empty($childs))
										{
											$this->_xmlToolBox->startTag("items");
											for($j=0 ; $j<$count=count($childs) ; $j++)
											{
												$type = $childs[$j]["attributes"][0]["value"];
												$name = $childs[$j]["attributes"][1]["value"];
												$dbAlias = ucfirst(strtolower(SLS_String::substrBeforeFirstDelimiter($name,"_")));
												$table = SLS_String::substrAfterFirstDelimiter($name,"_");							
												$right = SLS_BoRights::isAuthorized("read",$dbAlias."_".SLS_String::tableToClass($table));
												if ($right == 1)
												{
													$comment = $comments[$dbAlias."_".SLS_String::tableToClass($table)];
													if (SLS_String::startsWith($comment,"sls:lang:"))
													{
														$key = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:"));
														$comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key];
													}
													$actionIdsModel = array($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),
																			$this->_generic->getActionId($this->_boController,"Add".$dbAlias."_".SLS_String::tableToClass($table)),
																			$this->_generic->getActionId($this->_boController,"Modify".$dbAlias."_".SLS_String::tableToClass($table)),
																			$this->_generic->getActionId($this->_boController,"Clone".$dbAlias."_".SLS_String::tableToClass($table)),
																			$this->_generic->getActionId($this->_boController,"Delete".$dbAlias."_".SLS_String::tableToClass($table)));
													if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table))))
													{
														$this->_xmlToolBox->startTag("item");
															$this->_xmlToolBox->addFullTag("db",$dbAlias,true);
															$this->_xmlToolBox->addFullTag("model",SLS_String::tableToClass($table),true);
															$this->_xmlToolBox->addFullTag("title",$comment,"true");
															$this->_xmlToolBox->addFullTag("like",(SLS_BoRights::isLike("read",$dbAlias."_".SLS_String::tableToClass($table))) ? "true" : "false","true");												
															$this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionIdsModel)) ? "true" : "false","true");
															$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),"true");
														$this->_xmlToolBox->endTag("item");
													}
												}
											}
											$this->_xmlToolBox->endTag("items");
										}
									$this->_xmlToolBox->endTag("category");
								}
								else
								{
									$dbAlias = ucfirst(strtolower(SLS_String::substrBeforeFirstDelimiter($name,"_")));
									$table = SLS_String::substrAfterFirstDelimiter($name,"_");							
									$right = SLS_BoRights::isAuthorized("read",$dbAlias."_".SLS_String::tableToClass($table));
									if ($right == 1)
									{
										$comment = $comments[$dbAlias."_".SLS_String::tableToClass($table)];
										if (SLS_String::startsWith($comment,"sls:lang:"))
										{
											$key = strtoupper(SLS_String::substrAfterFirstDelimiter($comment,"sls:lang:"));
											$comment = (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key])) ? (empty($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) ? $table : $GLOBALS[$GLOBALS['PROJECT_NAME']]['JS'][$key]) : $GLOBALS[$GLOBALS['PROJECT_NAME']]['XSL'][$key];
										}
										$actionIdsModel = array($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),
																$this->_generic->getActionId($this->_boController,"Add".$dbAlias."_".SLS_String::tableToClass($table)),
																$this->_generic->getActionId($this->_boController,"Modify".$dbAlias."_".SLS_String::tableToClass($table)),
																$this->_generic->getActionId($this->_boController,"Clone".$dbAlias."_".SLS_String::tableToClass($table)),
																$this->_generic->getActionId($this->_boController,"Delete".$dbAlias."_".SLS_String::tableToClass($table)));
										if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table))))
										{
											$this->_xmlToolBox->startTag("category",array("type"=>"table"));
												$this->_xmlToolBox->addFullTag("db",$dbAlias,true);
												$this->_xmlToolBox->addFullTag("model",SLS_String::tableToClass($table),true);
												$this->_xmlToolBox->addFullTag("title",$comment,"true");
												$this->_xmlToolBox->addFullTag("like",(SLS_BoRights::isLike("read",$dbAlias."_".SLS_String::tableToClass($table))) ? "true" : "false","true");
												$this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionIdsModel)) ? "true" : "false","true");
												$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"List".$dbAlias."_".SLS_String::tableToClass($table)),"true");
											$this->_xmlToolBox->endTag("category");
										}
									}
								}
							}
							$this->_xmlToolBox->endTag("categories");
							
						$this->_xmlToolBox->endTag("section");
						# /BOs
					}
					
					# i18n
					if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "Boi18n")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "Boi18n")))
					{
						$file = $this->_http->getParam("File");
						$this->_xmlToolBox->startTag("section");
							$this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_I18N'],"true");
							$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n")) ? "true" : "false","true");
							$this->_xmlToolBox->addFullTag("href","#","true");
							$this->_xmlToolBox->startTag("categories");
								$controllers = $this->_generic->getControllersXML()->getTags("//controllers/controller[@side='user']/@name");
								sort($controllers,SORT_STRING);
								for($i=0 ; $i<$count=count($controllers) ; $i++)
								{
									$actions = $this->_generic->getControllersXML()->getTags("//controllers/controller[@name='".$controllers[$i]."' and @side='user']/scontrollers/scontroller/@name");
									sort($actions,SORT_STRING);
									$this->_xmlToolBox->startTag("category",array("type"=>"category"));
										$this->_xmlToolBox->addFullTag("title",$controllers[$i],"true");
										$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && SLS_String::startsWith($file, "Actions|".$controllers[$i]."|")) ? "true" : "false","true");
										$this->_xmlToolBox->addFullTag("href","#","true");
										$this->_xmlToolBox->startTag("items");
										if (file_exists($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/__".$controllers[$i].".".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/__".$controllers[$i].".".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS')))
										{
											$this->_xmlToolBox->startTag("item");
												$this->_xmlToolBox->addFullTag("title","__".$controllers[$i],"true");
												$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Actions|".$controllers[$i]."|__".$controllers[$i]) ? "true" : "false","true");
												$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Actions|".$controllers[$i]."|__".$controllers[$i])),"true");
											$this->_xmlToolBox->endTag("item");
										}
										for($j=0 ; $j<$countJ=count($actions) ; $j++)
										{
											if (file_exists($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/".$actions[$j].".".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("actionLangs").$controllers[$i]."/".$actions[$j].".".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS')))
											{
												$this->_xmlToolBox->startTag("item");
													$this->_xmlToolBox->addFullTag("title",$actions[$j],"true");
													$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Actions|".$controllers[$i]."|".$actions[$j]) ? "true" : "false","true");
													$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Actions|".$controllers[$i]."|".$actions[$j])),"true");
												$this->_xmlToolBox->endTag("item");
											}
										}
										$this->_xmlToolBox->endTag("items");
									$this->_xmlToolBox->endTag("category");
								}
								if (file_exists($this->_generic->getPathConfig("genericLangs")."site.".$this->_lang->getLang().".lang.php") && ($translations = file_get_contents($this->_generic->getPathConfig("genericLangs")."site.".$this->_lang->getLang().".lang.php")) && SLS_String::contains(str_replace("","",$translations),'*/'."\n".'$GLOBALS') || (!SLS_String::contains($translations,"/**") && SLS_String::contains($translations,'$GLOBALS')))
								{
									$this->_xmlToolBox->startTag("category",array("type"=>"table"));
										$this->_xmlToolBox->addFullTag("title","__".$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_I18N_SITE'],"true");
										$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, "Boi18n") && $file == "Generics|site") ? "true" : "false","true");
										$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController, "Boi18n", array("File" => "Generics|site")),"true");
									$this->_xmlToolBox->endTag("category");
								}
							$this->_xmlToolBox->endTag("categories");
						$this->_xmlToolBox->endTag("section");
					}
					# /i18n
					
					# CkFinder
					if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoFileUpload")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoFileUpload")))
					{
						$this->_xmlToolBox->startTag("section");
							$this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_FILE_MANAGER'],"true");
							$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoFileUpload")) ? "true" : "false","true");
							$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoFileUpload"),"true");
						$this->_xmlToolBox->endTag("section");
					}
					# /CkFinder
					
					# ProjectSettings
					if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoProjectSettings")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoProjectSettings")))
					{
						$this->_xmlToolBox->startTag("section");
							$this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_PROJECT_SETTINGS'],"true");
							$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoProjectSettings")) ? "true" : "false","true");
							$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoProjectSettings"),"true");
						$this->_xmlToolBox->endTag("section");
					}
					# /ProjectSettings
					
					# Users
					if ($this->_generic->actionIdExists($this->_generic->getActionId($this->_boController, "BoUserList")) && SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, "BoUserList")))
					{
						$actionsUser = array($this->_generic->getActionId($this->_boController, "BoUserList"),
											 $this->_generic->getActionId($this->_boController, "BoUserAdd"),
											 $this->_generic->getActionId($this->_boController, "BoUserModify"),
											 $this->_generic->getActionId($this->_boController, "BoUserDelete"),
											 $this->_generic->getActionId($this->_boController, "BoUserStatus"));
						$this->_xmlToolBox->startTag("section");
							$this->_xmlToolBox->addFullTag("title",$GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_BO_MENU_USERS'],"true");
							$this->_xmlToolBox->addFullTag("selected",(in_array($this->_generic->getActionId(),$actionsUser)) ? "true" : "false","true");
							$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,"BoUserList"),"true");
						$this->_xmlToolBox->endTag("section");
					}
					# /Users
					
					# Developer actions
					$boActions = $this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller/@name");
					for($i=0 ; $i<$count=count($boActions) ; $i++)
					{
						// If dev action & admin authorized
						if (!SLS_String::startsWith($boActions[$i],"Bo") && 	// Sls generated actions
							!SLS_String::startsWith($boActions[$i],"List") && 	// User action ListDb_Model
							!SLS_String::startsWith($boActions[$i],"Add") && 	// User action AddDb_Model
							!SLS_String::startsWith($boActions[$i],"Modify") && // User action ModifyDb_Model
							!SLS_String::startsWith($boActions[$i],"Delete") && // User action DeleteDb_Model
							!SLS_String::startsWith($boActions[$i],"Clone") && 	// User action CloneDb_Model
							!SLS_String::startsWith($boActions[$i],"Email") &&	// User action EmailDb_Model
							SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController, $boActions[$i])))
						{
							$this->_xmlToolBox->startTag("section");
								$this->_xmlToolBox->addFullTag("title",$this->_generic->getControllersXML()->getTag("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='".$boActions[$i]."']/scontrollerLangs/scontrollerLang[@lang='".$this->_lang->getLang()."']"),"true");
								$this->_xmlToolBox->addFullTag("selected",($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController, $boActions[$i])) ? "true" : "false", "true");
								$this->_xmlToolBox->addFullTag("href",$this->_generic->getFullPath($this->_boController,$boActions[$i]),"true");
							$this->_xmlToolBox->endTag("section");
						}
					}
					# /Developer actions
					
				$this->_xmlToolBox->endTag("nav");
			}
			# /Nav
			
			# Admin
			$xmlRight = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"));
			$adminName = $this->_session->getParam("SLS_BO_USER_NAME");
			$adminFirstname = $this->_session->getParam("SLS_BO_USER_FIRSTNAME");
			if (!empty($adminName) && !empty($adminFirstname))
				$imgPath = $this->_generic->getPathConfig("files")."__Uploads/images/bo/".SLS_String::stringToUrl($adminName."_".$adminFirstname,"_").".jpg";
			else
				$imgPath = $this->_generic->getPathConfig("coreImg")."BO-2014/Pictos/default_dev_account_small.jpg";
			$this->_xmlToolBox->startTag("admin");
				$this->_xmlToolBox->addFullTag("img",(file_exists($imgPath) && !is_dir($imgPath)) ? $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$imgPath : $this->_generic->getSiteConfig("protocol")."://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files")."__Uploads/images/bo/default_account.jpg",true);
				$this->_xmlToolBox->addFullTag("login",$this->_session->getParam("SLS_BO_USER"),true);
				$this->_xmlToolBox->addFullTag("name",ucwords(strtolower((!empty($adminName)) ? $adminName : "Developer")),true);
				$this->_xmlToolBox->addFullTag("firstname",((!empty($adminFirstname)) ? ucwords(strtolower($adminFirstname)) : "SillySmart"),true);
				$this->_xmlToolBox->addFullTag("type",SLS_BoRights::getAdminType(),true);			
				$nodeExists = $xmlRight->getTag("//sls_configs/entry[@login='******']/@login");
				if (!empty($nodeExists))
				{
					$settings = array_combine($xmlRight->getTags("//sls_configs/entry[@login='******']/settings/setting/@key"),$xmlRight->getTags("//sls_configs/entry[@login='******']/settings/setting"));
					$this->_xmlToolBox->startTag("settings");
					foreach($settings as $key => $value)
						$this->_xmlToolBox->addFullTag("setting",$value,true,array("key"=>$key));
					$this->_xmlToolBox->endTag("settings");
				}
				$xmlBoColors = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo_colors.xml"));
				$boColors = $xmlBoColors->getTagsAttributes("//sls_configs/template",array("name","hexa"));
				$this->_xmlToolBox->startTag("colors");
				for($i=0 ; $i<$count=count($boColors) ; $i++)
					$this->_xmlToolBox->addFullTag("color",$boColors[$i]["attributes"][0]["value"],true,array("hexa" => $boColors[$i]["attributes"][1]["value"]));
				$this->_xmlToolBox->endTag("colors");
			$this->_xmlToolBox->endTag("admin");
			# /Admin
			
			# URLs
			$this->_xmlToolBox->startTag("various");
				$this->_xmlToolBox->addFullTag("dashboard",$this->_generic->getFullPath($this->_boController,"BoDashBoard"),true,array("selected" => ($this->_generic->getActionId() == $this->_generic->getActionId($this->_boController,"BoDashBoard")) ? "true" : "false"));
				$this->_xmlToolBox->addFullTag("export",$this->_generic->getFullPath($this->_boController,"BoExport"),true);
				$this->_xmlToolBox->addFullTag("ac",$this->_generic->getFullPath($this->_boController,"BoFkAc"),true);
				$this->_xmlToolBox->addFullTag("like",$this->_generic->getFullPath($this->_boController,"BoLike"),true);
				$this->_xmlToolBox->addFullTag("setting",$this->_generic->getFullPath($this->_boController,"BoSetting"),true);
				$this->_xmlToolBox->addFullTag("unique",$this->_generic->getFullPath($this->_boController,"BoUnique"),true);
				$this->_xmlToolBox->addFullTag("upload",$this->_generic->getFullPath($this->_boController,"BoUpload"),true);
				$this->_xmlToolBox->addFullTag("upload_progress",$this->_generic->getFullPath($this->_boController,"BoUploadProgress"),true);
				$this->_xmlToolBox->addFullTag("delete_file",$this->_generic->getFullPath($this->_boController,"BoDeleteFile"),true);
				$this->_xmlToolBox->addFullTag("login",$this->_generic->getFullPath($this->_boController,"BoLogin"),true);
				$this->_xmlToolBox->addFullTag("logout",(SLS_BoRights::getAdminType() == "developer") ? $this->_generic->getFullPath("SLS_Bo","Logout",array("Redirect" => $this->_generic->getActionId($this->_boController,"BoLogin"), "Lang" => $this->_lang->getLang()),true,"en") : $this->_generic->getFullPath($this->_boController,"BoLogout"),true);
				$this->_xmlToolBox->addFullTag("forgotten_pwd",$this->_generic->getFullPath($this->_boController,"BoForgottenPwd"),true);
				$this->_xmlToolBox->addFullTag("renew_pwd",$this->_generic->getFullPath($this->_boController,"BoRenewPwd",array("Login"=>$this->_session->getParam("SLS_BO_USER"))),true);
				$this->_xmlToolBox->addFullTag("is_logged",$this->_generic->getFullPath($this->_boController,"BoIsLogged"),true);
				$this->_xmlToolBox->addFullTag("switch_lang",$this->_generic->getFullPath($this->_boController,"BoSwitchLang",array("Lang"=>""),false),true);
				$this->_xmlToolBox->addFullTag("user_add",$this->_generic->getFullPath($this->_boController,"BoUserAdd"),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserAdd"))) ? "true" : "false"));
				$this->_xmlToolBox->addFullTag("user_modify",$this->_generic->getFullPath($this->_boController,"BoUserModify",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserModify"))) ? "true" : "false"));
				$this->_xmlToolBox->addFullTag("user_delete",$this->_generic->getFullPath($this->_boController,"BoUserDelete",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserDelete"))) ? "true" : "false"));
				$this->_xmlToolBox->addFullTag("user_status",$this->_generic->getFullPath($this->_boController,"BoUserStatus",array("id" => ''),false),true,array("authorized" => (SLS_BoRights::isAuthorized("","",$this->_generic->getActionId($this->_boController,"BoUserStatus"))) ? "true" : "false"));
			$this->_xmlToolBox->endTag("various");
			# /URLs
			
			# Server
			$apcUpload = (in_array(ini_get("apc.rfc1867"),array(1,"1","On","on",true,"true"))) ? "true" : "false";
			$apcUploadKey = ini_get("apc.rfc1867_name");
			$uploadMaxFilesize = ini_get("upload_max_filesize");
			$unite = strtolower(substr(trim($uploadMaxFilesize), -1));
			switch ($unite)
		    {   
				case 'k': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024;					break;
		    	case 'm': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024 * 1024; 			break;
				case 'g': $uploadMaxFilesize = (int)$uploadMaxFilesize * 1024 * 1024 * 1024;	break;
				default: $uploadMaxFilesize = $uploadMaxFilesize;								break;
		    }
			$this->_xmlToolBox->startTag("server");
				$this->_xmlToolBox->addFullTag("apc_upload",$apcUpload,true);
				$this->_xmlToolBox->addFullTag("apc_upload_key",$apcUploadKey,true);
				$this->_xmlToolBox->addFullTag("upload_max_size",$uploadMaxFilesize,true);
			$this->_xmlToolBox->endTag("server");
			# /Server
		}
	}
Ejemplo n.º 6
0
	/**
	 * Check all the on delete constraints on all foreign keys of the current model
	 * 
	 * @access public
	 * @since 1.0.9
	 */
	public function onDeleteConstraints()
	{
		// Check fks
		$db = SLS_Sql::getInstance();
		$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));				
		$fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tablePk='".strtolower($this->getDatabase())."_".SLS_String::tableToClass($this->getTable())."' and @ondelete != 'no_action']",array("tableFk","columnFk","ondelete"));
		for($i=0 ; $i<$count=count($fks) ; $i++)
		{
			if (empty($fks) || (!empty($fks) && count($fks[0]["attributes"]) != 3))
				continue;
			
			$className = ucfirst(SLS_String::substrBeforeFirstDelimiter($fks[$i]["attributes"][0]["value"],"_"))."_".SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($fks[$i]["attributes"][0]["value"],"_"));
			$fk = $fks[$i]["attributes"][1]["value"];
			$onDelete = $fks[$i]["attributes"][2]["value"];			
			$this->_generic->useModel(SLS_String::substrAfterFirstDelimiter($className,"_"),SLS_String::substrBeforeFirstDelimiter($className,"_"),"user");							
			$object = new $className();			
			if ($object->getDatabase() != $db->getCurrentDb())
				$db->changeDb($object->getDatabase());
			
			switch ($onDelete)
			{
				case "set_null":					
					$db->update("UPDATE `".$object->getTable()."` SET `".$fk."` = NULL WHERE `".$fk."` = ".$db->quote($this->{__.$this->getPrimaryKey()})." ");
					break;
				case "cascade":					
					$objects = $db->select("SELECT * FROM `".$object->getTable()."` WHERE `".$fk."` = ".$db->quote($this->{__.$this->getPrimaryKey()})." ");
					for($j=0 ; $j<$countJ=count($objects) ; $j++)					
						if ($object->getModel($objects[$j]->{$object->getPrimaryKey()}) === true)
							$object->delete($object->isMultilanguage());
					break;
			}
		}
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);

		$sql = SLS_Sql::getInstance();

		$slsGraphId = $this->_http->getParam('id');
		
		$this->useModel('Sls_graph_query',$this->defaultDb,"sls");
		$this->useModel('Sls_graph',$this->defaultDb,"sls");
		$this->useModel('Sls_graph_query_column',$this->defaultDb,"sls");
		$this->useModel('Sls_graph_query_join',$this->defaultDb,"sls");
		$this->useModel('Sls_graph_query_group',$this->defaultDb,"sls");
		$this->useModel('Sls_graph_query_where',$this->defaultDb,"sls");

		$className = ucfirst($this->defaultDb)."_Sls_graph_query";
		$slsGraphQuery = new $className();
		$className = ucfirst($this->defaultDb)."_Sls_graph";
		$slsGraph = new $className();

		if($slsGraph->getModel($slsGraphId) === false || $slsGraphQuery->getModel($slsGraph->sls_graph_query_id) === false)
			$this->forward('SLS_Default', 'UrlError');

		$slsGraphQueryCurrent = $slsGraphQuery;

		$errors = array();
		$slsGraphTypes = array('pie', 'bar', 'pivot', 'list');
		$slsGraphAggregationTypes = array('sum', 'avg', 'count');
		$slsGraphAggregationTypesNeedField = array('sum', 'avg');
		$slsGraphQueryOperators = array('like','notlike','startwith','endwith','equal','notequal','in','notin','lt','lte','gt','gte','null','notnull');
		$this->queryOperatorsNeedField = array('like','notlike','startwith','endwith','equal','notequal','in','notin','lt','lte','gt','gte');

		$tableFieldsValues = array();
		$slsGraphQueryData = array(
			'sls_graph_query_where' => array(
				'sls_graph_query_where_type'      => 'group',
				'sls_graph_query_where_condition' => '',
				'sls_graph_query_where_column'    => '',
				'sls_graph_query_where_operator'  => '',
				'sls_graph_query_where_value'     => '',
				'sls_graph_query_where_children'  => array(),
				'sls_graph_query_where_root'      => 'true',
			)
		);
		$slsGraphData = array();
		$slsGraphQueryWheres = array();

		# reload
		if($this->_http->getParam('reload') == 'true')
		{
			$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
			$slsGraphQueryData = $this->_http->getParam('sls_graph_query');
			$slsGraphData = $this->_http->getParam('sls_graph');

			if(!$slsGraph->setSlsGraphTitle($slsGraphData['sls_graph_title']))
				$errors['sls_graph_title'] = 'Titre invalide';

			$tmp = explode('.', $slsGraphQueryData['sls_graph_query_table']);

			if(count($tmp) == 2)
			{
				$slsGraphQueryDbAlias = $tmp[0];
				$slsGraphQueryTable = $tmp[1];
				$slsGraphQueryTableAlias = $this->getTableAlias($slsGraphQueryTable);
				$sql->changeDb($slsGraphQueryDbAlias);
			}
			else
			{
				$slsGraphQueryTableAlias = $slsGraphQueryDbAlias = $slsGraphQueryTable = '';
			}

			if(!$slsGraphQuery->setSlsGraphQueryDbAlias($slsGraphQueryDbAlias) || !$slsGraphQuery->setSlsGraphQueryTable($slsGraphQueryTable) || !$slsGraphQuery->setSlsGraphQueryTableAlias($slsGraphQueryTableAlias) || !$sql->tableExists($slsGraphQueryTable))
				$errors['sls_graph_query_table'] = 'Table invalide';
			else
			{

				$tableFields = $sql->showColumns($slsGraphQueryTable);
				$tableFieldsValues = array_map(array($this,'filterFields'), $tableFields);
			}

			if(!$slsGraph->setSlsGraphType($slsGraphData['sls_graph_type']))
			{
				$errors['sls_graph_type'] = 'Type invalide';
			}
			else if($slsGraphData['sls_graph_type'] == 'pie')
			{
				# query columns
				$tmp = explode('.', $slsGraphData['sls_graph_pie_group_by']);
				$column = $tmp[1];
				$columnConcat = $column;

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				$slsGraphQueryColumn1 = new $className();
				$slsGraphQueryColumn1->setSlsGraphQueryColumnName($column);
				$slsGraphQueryColumn1->setSlsGraphQueryColumnAlias('legend_id');
				$slsGraphQueryColumn1->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				$slsGraphQueryColumn1->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);

				$columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk")));

				if(!empty($columnFk))
				{
					$tablePk = $columnFk['attributes'][0]['value'];
					$labelPk = $columnFk['attributes'][1]['value'];

					$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tablePk, '_');
					$tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_');

					$this->_generic->useModel($tablePk, $dbPk, "user");
					$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);
					$objectFk = new $classFk();
					$columns = array();
					$columnsLabel = array();
					$clause = array();
					$render = array();

					$columnTable = $objectFk->getTable();

					# add join
					$i = 1;
					# target
					$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
					${slsGraphQueryJoin.$i} = new $className();
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column);
					# /target

					# source
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable);
					$slsGraphQueryJoin = $this->getTableAlias($columnTable);
					/*$slsGraphQueryJoin = $columnTable.$aliasIndex;
					$aliasIndex++;*/
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey());
					# /source

					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left');
					$i++;
					# /add join

					foreach($objectFk->getParams() as $key => $value)
					{
						array_push($columns,"`".$key."`");
						if (SLS_String::contains($labelPk,$key))
							$columnsLabel[$key] = strpos($labelPk,$key);
					}
					array_multisort($columnsLabel);

					foreach($columnsLabel as $columnLabel => $offset)
						array_push($clause,$columnLabel);

					$pattern = str_replace("'","''",$labelPk);

					foreach($clause as $columnC)
						$pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern);

					$columnConcat = "CONCAT('".$pattern."')";
				}

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				$slsGraphQueryColumn2 = new $className();
				$slsGraphQueryColumn2->setSlsGraphQueryColumnName($columnConcat);
				$slsGraphQueryColumn2->setSlsGraphQueryColumnAlias('legend');
				$slsGraphQueryColumn2->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				$slsGraphQueryColumn2->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				$slsGraphQueryColumn3 = new $className();
				$slsGraphQueryColumn3->setSlsGraphQueryColumnAggregation('count');
				$slsGraphQueryColumn3->setSlsGraphQueryColumnAlias('count');
				$slsGraphQueryColumn3->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				$slsGraphQueryColumn3->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				# /query columns

				# query groups
				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup1 = new $className();
				if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($column)/* || !in_array($slsGraphData['sls_graph_pie_group_by'], $tableFieldsValues)*/)
					$errors['sls_graph_pie_group_by'] = 'Champ groupé invalide';
				# /query groups

				$sql->changeDb($slsGraphQueryDbAlias);
				$joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_pie_group_by']));
			}
			else if($slsGraphData['sls_graph_type'] == 'bar')
			{
				$i = 1;
				$j = 1;

				# query columns
				$tmp = explode('.', $slsGraphData['sls_graph_bar_aggregation_field']);
				if(count($tmp) == 2)
					$columnAggregationField = $tmp[1];
				else
					$columnAggregationField = '';

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				if(empty($slsGraphData['sls_graph_bar_aggregation'])
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAggregation($slsGraphData['sls_graph_bar_aggregation'])
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable)
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias)
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('value'))
					$errors['sls_graph_bar_aggregation'] = 'Aggrégation invalide';

				if(in_array($slsGraphData['sls_graph_bar_aggregation'], $slsGraphAggregationTypesNeedField) && (empty($columnAggregationField) ||  !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnAggregationField)))
					$errors['sls_graph_bar_aggregation_field'] = 'Champ aggrégation invalide';
				$j++;

				# query column group
				$tmp = explode('.', $slsGraphData['sls_graph_bar_group_by']);
				$column = $tmp[1];
				$columnConcat = $column;

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_group_id');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				$j++;

				$columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk")));

				if(!empty($columnFk))
				{
					$tablePk = $columnFk['attributes'][0]['value'];
					$labelPk = $columnFk['attributes'][1]['value'];

					$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tablePk, '_');
					$tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_');

					$this->_generic->useModel($tablePk, $dbPk, "user");
					$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);
					$objectFk = new $classFk();
					$columns = array();
					$columnsLabel = array();
					$clause = array();
					$render = array();

					$columnTable = $objectFk->getTable();

					# add join
					# target
					$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
					${slsGraphQueryJoin.$i} = new $className();
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column);
					# /target

					# source
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable);
					$slsGraphQueryJoin = $this->getTableAlias($columnTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey());
					# /source

					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left');
					$i++;
					# /add join

					foreach($objectFk->getParams() as $key => $value)
					{
						array_push($columns,"`".$key."`");
						if (SLS_String::contains($labelPk,$key))
							$columnsLabel[$key] = strpos($labelPk,$key);
					}
					array_multisort($columnsLabel);

					foreach($columnsLabel as $columnLabel => $offset)
						array_push($clause,$columnLabel);

					$pattern = str_replace("'","''",$labelPk);
					foreach($clause as $columnC)
						$pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern);

					$columnConcat = "CONCAT('".$pattern."')";
				}

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_group');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				$j++;
				# query column group

				# query column stacked
				if(!empty($slsGraphData['sls_graph_bar_stacked_field']))
				{
					$tmp = explode('.', $slsGraphData['sls_graph_bar_stacked_field']);
					$column = $tmp[1];
					$columnConcat = $column;

					$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
					${slsGraphQueryColumn.$j} = new $className();
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column);
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_stacked_id');
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
					$j++;

					$columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk")));
					if(!empty($columnFk))
					{
						$tablePk = $columnFk['attributes'][0]['value'];
						$labelPk = $columnFk['attributes'][1]['value'];

						$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tablePk, '_');
						$tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_');

						$this->_generic->useModel($tablePk, $dbPk, "user");
						$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);
						$objectFk = new $classFk();
						$columns = array();
						$columnsLabel = array();
						$clause = array();
						$render = array();

						$columnTable = $objectFk->getTable();

						# add join
						# target
						$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
						${slsGraphQueryJoin.$i} = new $className();
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable);
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias);
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column);
						# /target

						# source
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable);
						$slsGraphQueryJoin = $this->getTableAlias($columnTable);
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin);
						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey());
						# /source

						${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left');
						$i++;
						# /add join

						foreach($objectFk->getParams() as $key => $value)
						{
							array_push($columns,"`".$key."`");
							if (SLS_String::contains($labelPk,$key))
								$columnsLabel[$key] = strpos($labelPk,$key);
						}
						array_multisort($columnsLabel);

						foreach($columnsLabel as $columnLabel => $offset)
							array_push($clause,$columnLabel);

						$pattern = str_replace("'","''",$labelPk);
						foreach($clause as $columnC)
							$pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern);

						$columnConcat = "CONCAT('".$pattern."')";
					}

					$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
					${slsGraphQueryColumn.$j} = new $className();
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat);
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_stacked');
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
					${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				}
				# query column stacked
				# /query columns

				# query groups
				$tmp = explode('.', $slsGraphData['sls_graph_bar_group_by']);
				$columnGroupByField = $tmp[1];

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup1 = new $className();
				if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($columnGroupByField))
					$errors['sls_graph_bar_group_by'] = 'Champ groupé invalide';

				if(!empty($slsGraphData['sls_graph_bar_stacked_field']))
				{
					$tmp = explode('.', $slsGraphData['sls_graph_bar_stacked_field']);
					$columnStackedField = $tmp[1];

					$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
					$slsGraphQueryGroup2 = new $className();
					if(!$slsGraphQueryGroup2->setSlsGraphQueryGroupColumn($columnStackedField))
						$errors['sls_graph_bar_stacked_field'] = 'Champ réservé invalide';
				}
				# /query groups

				$joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_bar_group_by']));
			}
			else if($slsGraphData['sls_graph_type'] == 'pivot')
			{
				$i = 1;
				$j = 1;
				# query columns
				$tmp = explode('.', $slsGraphData['sls_graph_pivot_aggregation_field']);
				if(count($tmp) == 2)
					$columnAggregationField = $tmp[1];
				else
					$columnAggregationField = '';

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				if(empty($slsGraphData['sls_graph_pivot_aggregation'])
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAggregation($slsGraphData['sls_graph_pivot_aggregation'])
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable)
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias)
					|| !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('value'))
					$errors['sls_graph_pivot_aggregation'] = 'Aggrégation invalide';

				if(in_array($slsGraphData['sls_graph_pivot_aggregation'], $slsGraphAggregationTypesNeedField) && (empty($columnAggregationField) ||  !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnAggregationField)))
					$errors['sls_graph_pivot_aggregation_field'] = 'Champ aggrégation invalide';
				$j++;

				# query column line
				$tmp = explode('.', $slsGraphData['sls_graph_pivot_line']);
				$column = $tmp[1];
				$columnConcat = $tmp[1];

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_line_id');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				$j++;

				$columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk")));
				if(!empty($columnFk))
				{
					$tablePk = $columnFk['attributes'][0]['value'];
					$labelPk = $columnFk['attributes'][1]['value'];

					$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tablePk, '_');
					$tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_');

					$this->_generic->useModel($tablePk, $dbPk, "user");
					$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);
					$objectFk = new $classFk();
					$columns = array();
					$columnsLabel = array();
					$clause = array();
					$render = array();

					$columnTable = $objectFk->getTable();

					# add join
					# target
					$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
					${slsGraphQueryJoin.$i} = new $className();
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column);
					# /target

					# source
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable);
					$slsGraphQueryJoin = $this->getTableAlias($columnTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey());
					# /source

					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left');
					$i++;
					# /add join

					foreach($objectFk->getParams() as $key => $value)
					{
						array_push($columns,"`".$key."`");
						if (SLS_String::contains($labelPk,$key))
							$columnsLabel[$key] = strpos($labelPk,$key);
					}
					array_multisort($columnsLabel);

					foreach($columnsLabel as $columnLabel => $offset)
						array_push($clause,$columnLabel);

					$pattern = str_replace("'","''",$labelPk);
					foreach($clause as $columnC)
						$pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern);

					$columnConcat = "CONCAT('".$pattern."')";
				}

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_line');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				$j++;
				# query column line

				# query column column
				$tmp = explode('.', $slsGraphData['sls_graph_pivot_column']);
				$column = $tmp[1];
				$columnConcat = $column;

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_column_id');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				$j++;

				$columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk")));
				if(!empty($columnFk))
				{
					$tablePk = $columnFk['attributes'][0]['value'];
					$labelPk = $columnFk['attributes'][1]['value'];

					$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tablePk, '_');
					$tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_');

					$this->_generic->useModel($tablePk, $dbPk, "user");
					$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);
					$objectFk = new $classFk();
					$columns = array();
					$columnsLabel = array();
					$clause = array();
					$render = array();

					$columnTable = $objectFk->getTable();

					# add join
					# target
					$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
					${slsGraphQueryJoin.$i} = new $className();
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column);
					# /target

					# source
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable);
					$slsGraphQueryJoin = $this->getTableAlias($columnTable);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin);
					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey());
					# /source

					${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left');
					$i++;
					# /add join

					foreach($objectFk->getParams() as $key => $value)
					{
						array_push($columns,"`".$key."`");
						if (SLS_String::contains($labelPk,$key))
							$columnsLabel[$key] = strpos($labelPk,$key);
					}
					array_multisort($columnsLabel);

					foreach($columnsLabel as $columnLabel => $offset)
						array_push($clause,$columnLabel);

					$pattern = str_replace("'","''",$labelPk);
					foreach($clause as $columnC)
						$pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern);

					$columnConcat = "CONCAT('".$pattern."')";
				}

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
				${slsGraphQueryColumn.$j} = new $className();
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_column');
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable);
				${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias);
				# query column column

				# /query columns

				# query groups
				$tmp = explode('.', $slsGraphData['sls_graph_pivot_line']);
				$columnLine = $tmp[1];

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup1 = new $className();
				if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($columnLine))
					$errors['sls_graph_pivot_line'] = 'Champ Ligne invalide';

				$tmp = explode('.', $slsGraphData['sls_graph_pivot_column']);
				$columnColumn = $tmp[1];

				$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
				$slsGraphQueryGroup2 = new $className();
				if(!$slsGraphQueryGroup2->setSlsGraphQueryGroupColumn($columnColumn))
					$errors['sls_graph_pivot_column'] = 'Champ colonne invalide';
				# /query groups

				$joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_pivot_column']));
			}
			else if($slsGraphData['sls_graph_type'] == 'list')
			{
				# columns
				$i = 1;
				$j = 1;
				$joins = array();

				foreach($slsGraphQueryData['sls_graph_query_column'] as $col)
				{
					$column = $col['sls_graph_query_column_value'];
					$path = explode('|', $column);
					$nbJoins = count($path);

					$data = explode('.', $path[$nbJoins-1]);
					$table = $data[0];
					$column = $data[1];
					$joinBefore = null;

					# joins
					for($k = 0; $k<$nbJoins ; $k++)
					{
						if($k == 0)
						{

							$columns = $sql->showColumns($slsGraphQueryTable);
							$columnSource = array_shift(array_filter($columns, array($this,'filterPK')));
							$columnSourcePK = $columnSource->Field;

							$join = array(
								'sls_graph_query_join_table_source' => $slsGraphQueryTable,
								'sls_graph_query_join_column_source' => $columnSourcePK
							);
						}
						else
						{
							$dataSource = explode('.', $path[$k]);
							$dataTarget = explode('.', $path[$k-1]);

							$tableSource = $dataSource[0];
							$tableTarget = $dataTarget[0];
							$columnSource = $dataSource[1];
							$columnTarget = $dataTarget[1];

							$columns = $sql->showColumns($tableSource);
							$columnSourcePK = array_shift(array_filter($columns, array($this,'filterPK')))->Field;

							$columns = $sql->showColumns($tableTarget);
							$this->columnTarget = $columnTarget;
							$columnTargetComment = array_shift(array_filter($columns, array($this,'filterFieldTarget')))->Comment;
							
							$join = array(
								'sls_graph_query_join_table_target' => $tableTarget,
								'sls_graph_query_join_column_target' =>$columnTarget,
								'sls_graph_query_join_table_comment_target' => empty($columnTargetComment) ? $columnTarget : $columnTargetComment,
								'sls_graph_query_join_table_source' => $tableSource,
								'sls_graph_query_join_column_source' => $columnSourcePK
							);
						}

						$joinSearch = $this->array_search_multi($join, $joins);
						if(empty($joinSearch))
						{
							$join['sls_graph_query_join_table_alias_source'] = ($k == 0) ? $slsGraphQueryTableAlias : $this->getTableAlias($join['sls_graph_query_join_table_source']); /*$join['sls_graph_query_join_table_source'].$aliasIndex++*/;

							if($k > 0)
							{
								$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
								${slsGraphQueryJoin.$j} = new $className();
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableSource($join['sls_graph_query_join_table_source']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableAliasSource($join['sls_graph_query_join_table_alias_source']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinColumnSource($join['sls_graph_query_join_column_source']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableTarget($join['sls_graph_query_join_table_target']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableAliasTarget($joinBefore['sls_graph_query_join_table_alias_source']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinColumnTarget($join['sls_graph_query_join_column_target']);
								${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinMode('left');
								$j++;
							}

							array_push($joins, $join);
						}
						else
							$join = $joinSearch;

						$joinBefore = $join;
					}
					# /joins

					$columns = $sql->showColumns($table);
					$this->column = $column;
					$columnComment = array_shift(array_filter($columns, array($this,'filterColumnField')))->Comment;

					$tableComment = $join['sls_graph_query_join_table_comment_target'];

					if(empty($tableComment))
					{
						$tables = $sql->showTables();
						$this->table = $table;
						$tableComment = array_shift(array_filter($tables, array($this,'filterTable4')))->Comment;
					}

					$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
					${slsGraphQueryColumn.$i} = new $className();
					${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnTable($join['sls_graph_query_join_table_source']);
					${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnTableAlias($join['sls_graph_query_join_table_alias_source']);
					${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnName($column);
					${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnAlias($tableComment.' - '.$columnComment);
					$i++;
				}

				# /columns
			}

			# query where
			if(!empty($slsGraphQueryData['sls_graph_query_where']))
			{
				$i = 0; $j = 0;
				$this->iterateSetSlsGraphQueryWhere($slsGraphQueryData['sls_graph_query_where'], $i, $j, $slsGraphQueryWheres, $errors, $joins);
			}
			# /query where

			if (empty($errors))
			{
				$sql->changeDb($this->defaultDb);

				# query
				$this->deleteQuery($slsGraphQueryCurrent->sls_graph_query_id);
				$slsGraphQuery->create();
				# /query

				# graph
				$slsGraph->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id);
				$slsGraph->save();
				# /graph

				# query joins
				$i = 1;
				//$slsGraphQueryJoin1
				while(${slsGraphQueryJoin.$i})
				{
					${slsGraphQueryJoin.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id);
					${slsGraphQueryJoin.$i}->create();
					$i++;
				}
				# /query joins

				# query columns
				$i = 1;
				while(${slsGraphQueryColumn.$i})
				{
					${slsGraphQueryColumn.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id);
					${slsGraphQueryColumn.$i}->create();
					$i++;
				}
				# /query columns

				# query groups
				$i = 1;
				while(${slsGraphQueryGroup.$i})
				{
					${slsGraphQueryGroup.$i}->setSlsGraphQueryGroupTable($slsGraphQueryTable);
					${slsGraphQueryGroup.$i}->setSlsGraphQueryGroupTableAlias($slsGraphQueryTableAlias);
					${slsGraphQueryGroup.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id);
					${slsGraphQueryGroup.$i}->create();
					$i++;
				}
				# /query groups

				# query where
				if(!empty($slsGraphQueryData['sls_graph_query_where']))
				{
					$i = 0;
					$this->iterateCreateQueryWhere($slsGraphQueryData['sls_graph_query_where'], 0, $i, $slsGraphQueryWheres, $slsGraphQuery->sls_graph_query_id);
				}
				# /query where

				$this->forward('SLS_Bo', 'ReportingBo');
			}
			else
			{
				$xml->startTag("errors");
				foreach($errors as $key => $error)
				{
					if($key == 'sls_graph_query_where')
					{
						foreach($error as $slsGraphQueryWhereIndex => $slsGraphQueryWhereErrors)
						{
							foreach($slsGraphQueryWhereErrors as $slsGraphQueryWhereKey => $slsGraphQueryWhereError)
							{
								$xml->addFullTag("error", $slsGraphQueryWhereError, true, array("num" => $slsGraphQueryWhereIndex, "column" => $slsGraphQueryWhereKey));
							}
						}
					}
					else
						$xml->addFullTag("error", $error, true, array("column" => $key));
				}

				$xml->endTag("errors");
			}

			$slsGraphQueryData = $this->_http->getParam('sls_graph_query');
		}
		# /reload

		# load
		else
		{
			$this->useModel('Sls_graph_query',$this->defaultDb,"sls");
			$this->useModel('Sls_graph',$this->defaultDb,"sls");
			$this->useModel('Sls_graph_query_column',$this->defaultDb,"sls");
			$this->useModel('Sls_graph_query_join',$this->defaultDb,"sls");
			$this->useModel('Sls_graph_query_group',$this->defaultDb,"sls");
			$this->useModel('Sls_graph_query_where',$this->defaultDb,"sls");

			$className = ucfirst($this->defaultDb)."_Sls_graph_query_column";
			$slsGraphQueryColumn = new $className();
			$className = ucfirst($this->defaultDb)."_Sls_graph_query_join";
			$slsGraphQueryJoin = new $className();
			$className = ucfirst($this->defaultDb)."_Sls_graph_query_where";
			$slsGraphQueryWhere = new $className();
			$className = ucfirst($this->defaultDb)."_Sls_graph_query_group";
			$slsGraphQueryGroup = new $className();

			$slsGraphQueryId = $slsGraphQueryCurrent->sls_graph_query_id;
			$tables = array($slsGraphQueryCurrent->sls_graph_query_table => !empty($slsGraphQueryCurrent->sls_graph_query_alias) ? $slsGraphQuery->sls_graph_query_alias : $slsGraphQueryCurrent->sls_graph_query_table);
			$columns = $slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc")));
			$joins = $slsGraphQueryJoin->searchModels("sls_graph_query_join",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_join_id","order"=>"asc")));
			$wheres = $slsGraphQueryWhere->searchModels("sls_graph_query_where",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_where_id","order"=>"asc")));
			$groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc")));

			if($slsGraph->sls_graph_type == 'pie')
			{
				$slsGraphData['sls_graph_pie_group_by'] = !empty($groups) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : '';
			}
			else if($slsGraph->sls_graph_type == 'bar')
			{
				$slsGraphData['sls_graph_bar_aggregation'] = !empty($columns) ? $columns[0]->sls_graph_query_column_aggregation : '';
				$slsGraphData['sls_graph_bar_aggregation_field'] = !empty($columns) && !empty($columns[0]->sls_graph_query_column_name) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$columns[0]->sls_graph_query_column_name : '';
				$slsGraphData['sls_graph_bar_group_by'] = !empty($groups) && !empty($groups[0]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : '';
				$slsGraphData['sls_graph_bar_stacked_field'] = !empty($groups) && !empty($groups[1]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[1]->sls_graph_query_group_column : '';
			}
			else if($slsGraph->sls_graph_type == 'pivot')
			{
				$slsGraphData['sls_graph_pivot_aggregation'] = !empty($columns) ? $columns[0]->sls_graph_query_column_aggregation : '';
				$slsGraphData['sls_graph_pivot_aggregation_field'] = !empty($columns) && !empty($columns[0]->sls_graph_query_column_name) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$columns[0]->sls_graph_query_column_name : '';
				$slsGraphData['sls_graph_pivot_line'] = !empty($groups) && !empty($groups[0]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : '';
				$slsGraphData['sls_graph_pivot_column'] = !empty($groups) && !empty($groups[1]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[1]->sls_graph_query_group_column : '';
			}

			foreach($slsGraph->getParams() as $key => $value)
				$slsGraphData[$key] = $value;

			if ($slsGraphQueryCurrent->sls_graph_query_db_alias != $sql->getCurrentDb())
					$sql->changeDb($slsGraphQueryCurrent->sls_graph_query_db_alias);
			$tableFields = $sql->showColumns($slsGraphQueryCurrent->sls_graph_query_table);
			foreach($slsGraphQueryCurrent->getParams() as $key => $value)
			{
				if($key == 'sls_graph_query_table')
					$value = $slsGraphQueryCurrent->sls_graph_query_db_alias.'.'.$value;
				$slsGraphQueryData[$key] = $value;
			}

			$slsGraphQueryData['sls_graph_query_column'] = $this->iterateFormatQueryColumnToArray($columns, $joins);
			$slsGraphQueryData['sls_graph_query_where'] = $this->iterateFormatQueryWhereToArray($wheres, 0);
		}
		# /load

		# graph
		$xml->startTag('sls_graph');
		foreach($slsGraphData as $key => $value)
			$xml->addFullTag($key, $value, true);
		$xml->addFullTag('graph_table_fields_class', empty($tableFields) ? 'hide' : '', true);
		$xml->startTag('sls_graph_query');
		foreach($slsGraphQueryData as $key => $value)
		{
			if($key == 'sls_graph_query_where')
			{
				$i = 0; $j = 0;
				$this->iterateAddXmlQueryWhere($value, $i, $j, $xml);
			}
			else if($key == 'sls_graph_query_column')
			{
				$xml->startTag('sls_graph_query_columns');
				foreach($value as $column)
				{
					$xml->startTag('sls_graph_query_column');
					$xml->addFullTag('sls_graph_query_column_value', $column['sls_graph_query_column_value'], true);
					$xml->addFullTag('sls_graph_query_column_label', $column['sls_graph_query_column_label'], true);
					$xml->endTag('sls_graph_query_column');
				}
				$xml->endTag('sls_graph_query_columns');
			}
			else
				$xml->addFullTag($key, $value, true);
		}

		$xml->endTag('sls_graph_query');
		$xml->endTag('sls_graph');
		# /graph

		$labels = array(
			'SLS_GRAPH_TYPE_PIE' => "Pie Chart",
			'SLS_GRAPH_TYPE_BAR' => "Bar Chart",
			'SLS_GRAPH_TYPE_PIVOT' => "Pivot Table",
			'SLS_GRAPH_TYPE_LIST' => "List",
			'SLS_AGGREGATION_TYPE_SUM' => "SUM",
			'SLS_AGGREGATION_TYPE_AVG' => "AVG",
			'SLS_AGGREGATION_TYPE_COUNT' => "COUNT",
			'SLS_AGGREGATION_TYPE_SUM_LABEL' => "Sum",
			'SLS_AGGREGATION_TYPE_AVG_LABEL' => "Average",
			'SLS_AGGREGATION_TYPE_COUNT_LABEL' => "Total",
			'SLS_QUERY_OPERATOR_LIKE' => "LIKE",
			'SLS_QUERY_OPERATOR_NOTLIKE' => "NOT LIKE",
			'SLS_QUERY_OPERATOR_STARTWITH' => "START WITH",
			'SLS_QUERY_OPERATOR_ENDWITH' => "END WITH",
			'SLS_QUERY_OPERATOR_EQUAL' => "EQUAL",
			'SLS_QUERY_OPERATOR_NOTEQUAL' => "NOT EQUAL",
			'SLS_QUERY_OPERATOR_IN' => "IN",
			'SLS_QUERY_OPERATOR_NOTIN' => "NOT IN",
			'SLS_QUERY_OPERATOR_LT' => "LESS THAN",
			'SLS_QUERY_OPERATOR_LTE' => "LESS THAN EQUAL",
			'SLS_QUERY_OPERATOR_GT' => "GREATER THAN",
			'SLS_QUERY_OPERATOR_GTE' => "GREATER THAN EQUAL",
			'SLS_QUERY_OPERATOR_NULL' => "IS NULL",
			'SLS_QUERY_OPERATOR_NOTNULL' => "IS NOT NULL"
		);

		# graph types
		$xml->startTag('sls_graph_types');
		foreach($slsGraphTypes as $slsGraphType){
			$xml->startTag('sls_graph_type');
			$xml->addFullTag('sls_graph_type_value', $slsGraphType, true);
			$xml->addFullTag('sls_graph_type_label', $labels['SLS_GRAPH_TYPE_'.mb_strtoupper($slsGraphType, 'UTF-8')], true);
			$xml->endTag('sls_graph_type');
		}
		$xml->endTag('sls_graph_types');
		# /graph types

		# aggregation types
		$xml->startTag('sls_graph_aggregation_types');
		foreach($slsGraphAggregationTypes as $slsGraphAggregationType){
			$xml->startTag('sls_graph_aggregation_type');
			$xml->addFullTag('sls_graph_aggregation_type_value', $slsGraphAggregationType, true);
			$xml->addFullTag('sls_graph_aggregation_type_label', $labels['SLS_AGGREGATION_TYPE_'.mb_strtoupper($slsGraphAggregationType, 'UTF-8')], true);
			$xml->endTag('sls_graph_aggregation_type');
		}
		$xml->endTag('sls_graph_aggregation_types');
		# /aggregation types

		# query operators
		$xml->startTag('sls_graph_query_operators');
		foreach($slsGraphQueryOperators as $slsGraphQueryOperator){
			$xml->startTag('sls_graph_query_operator');
			$xml->addFullTag('sls_graph_query_operator_value', $slsGraphQueryOperator, true);
			$xml->addFullTag('sls_graph_query_operator_label', $labels['SLS_QUERY_OPERATOR_'.mb_strtoupper($slsGraphQueryOperator, 'UTF-8')], true);
			$xml->endTag('sls_graph_query_operator');
		}
		$xml->endTag('sls_graph_query_operators');
		# /query operators

		# tables
		$xml->startTag('tables');
		$dbs = $sql->getDbs();
		foreach($dbs as $db)
		{
			$sql->changeDb($db);
			$tables = $sql->showTables();
			usort($tables, array($this,'cmpTables'));

			foreach($tables as $table)
			{
				$xml->startTag('table');
					$xml->addFullTag('table_name', $db.'.'.$table->Name, true);
					$xml->addFullTag('table_label', $db.' - '.$table->Name, true);
				$xml->endTag('table');
			}
		}
		$xml->endTag('tables');
		# /tables

		$xml->addFullTag("url_reporting_getfields",$this->_generic->getFullPath("SLS_Bo","ReportingBoGetFields"),true);
		$xml->addFullTag("url_reporting_getfieldsfrommutipletables",$this->_generic->getFullPath("SLS_Bo","ReportingBoGetFieldsFromMultipleTables"),true);
		$xml->addFullTag("url_report",$this->_generic->getFullPath("SLS_Bo","ReportingBo"),true);
		$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","ReportingBoDelete",array("id" => $slsGraphId)),true);
		$xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ReportingBoStatus",array("id" => $slsGraphId)),true);
		
		$this->saveXML($xml);
	}
	public function getSlsGraphQueryWheres($parentId,$tab,$tables,$queryId)
	{
		$db = SLS_Sql::getInstance();

		$this->_generic->useModel("Sls_graph_query_where",$this->defaultDb,"sls");
		$className = ucfirst($this->defaultDb)."_Sls_graph_query_where";
		$slsGraphQueryWhere = new $className();
		$sql = "";
		$wheres = $slsGraphQueryWhere->searchModels("sls_graph_query_where",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$queryId,"mode"=>"equal"),1=>array("column"=>"parent_sls_graph_query_where_id","value"=>$parentId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_where_id","order"=>"asc")));
		for($j=0 ; $j<$countJ=count($wheres) ; $j++)
		{
			if ($j>0)
				$sql .= str_repeat("\t",$tab).strtoupper($wheres[$j]->sls_graph_query_where_condition)." "."\n";

			if ($wheres[$j]->sls_graph_query_where_type == "group")
			{
				$sql .= str_repeat("\t",$tab)."( "."\n";
				$sql .= $this->getSlsGraphQueryWheres($wheres[$j]->sls_graph_query_where_id,$tab+1,$tables,$queryId);
				$sql .= str_repeat("\t",$tab).") "."\n";
			}
			else
			{
				$sql .= str_repeat("\t",$tab).$wheres[$j]->sls_graph_query_where_table_alias."."."`".$wheres[$j]->sls_graph_query_where_column."`";
				switch ($wheres[$j]->sls_graph_query_where_operator)
				{
					case "like": 		$sql .= " LIKE ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "notlike": 	$sql .= " NOT LIKE ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n"; break;
					case "startwith": 	$sql .= " LIKE ".$db->quote("%".$wheres[$j]->sls_graph_query_where_value)." "."\n"; break;
					case "endwith": 	$sql .= " LIKE ".$db->quote($wheres[$j]->sls_graph_query_where_value."%")." "."\n"; break;
					case "equal": 		$sql .= " = ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "notequal": 	$sql .= " != ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "in": 			$sql .= " IN (".$db->quote($wheres[$j]->sls_graph_query_where_value).") "."\n";		break;
					case "notin": 		$sql .= " NOT IN (".$db->quote($wheres[$j]->sls_graph_query_where_value).") "."\n";	break;
					case "lt": 			$sql .= " < ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "lte": 		$sql .= " <= ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "gt": 			$sql .= " > ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "gte": 		$sql .= " >= ".$db->quote($wheres[$j]->sls_graph_query_where_value)." "."\n";		break;
					case "null": 		$sql .= " IS NULL "."\n";														break;
					case "notnull": 	$sql .= " IS NOT NULL "."\n";													break;
				}
			}
		}

		return $sql;
	}
	public function action() 
	{		
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$user = $this->hasAuthorative();
		
		// Objects
		$sql = SLS_Sql::getInstance();		
		$properties = array();
		$pathsHandleFk = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
		$pathsHandleType = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
		$pathsHandleFilter = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
		$xmlFk = new SLS_XMLToolbox($pathsHandleFk);
		$xmlType = new SLS_XMLToolbox($pathsHandleType);
		$xmlFilter = new SLS_XMLToolbox($pathsHandleFilter);
		
		// Foreach existing models 
		$models = scandir($this->_generic->getPathConfig("models"));
		foreach($models as $file)
		{
			if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") 
			{
				$fileExploded = explode(".",$file);
				if (is_array($fileExploded) && count($fileExploded) == 4)
				{ 
					$db = strtolower($fileExploded[0]);
					$class = $fileExploded[1];
					$className = $db."_".$class;
					$this->_generic->useModel($class,$db,"user");
					$object = new $className();
					$table = $object->getTable();
					
					$properties[$db][$table] = array("types" 	=> array(),
													 "filters" 	=> array(),
													 "fks" 		=> array());
					
					$types = $xmlType->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."']",array("column","type","rules"));
					for($i=0 ; $i<$count=count($types) ; $i++)
					{
						$column = $types[$i]["attributes"][0]["value"];
						$type 	= $types[$i]["attributes"][1]["value"];
						$rules 	= $types[$i]["attributes"][2]["value"];
						
						
						if ($type == "complexity" && !empty($rules))
							$type .= " (".$rules.")";
						
						$properties[$db][$table]["types"][$column][] = $type;
					}
					
					$filters = $xmlFilter->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."']",array("column","filter","hash"));
					for($i=0 ; $i<$count=count($filters) ; $i++)
					{
						$column = $filters[$i]["attributes"][0]["value"];
						$filter = $filters[$i]["attributes"][1]["value"];
						$hash 	= $filters[$i]["attributes"][2]["value"];
						
						if ($filter == "hash" && !empty($hash))
							$filter .= " (".$hash.")";
							
						$properties[$db][$table]["filters"][$column][] = $filter;
					}
					
					$fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$table."']",array("columnFk","tablePk","labelPk"));
					for($i=0 ; $i<$count=count($fks) ; $i++)
					{
						$column = $fks[$i]["attributes"][0]["value"];
						$classPk = ucfirst($fks[$i]["attributes"][1]["value"]);
						$labelPk = $fks[$i]["attributes"][2]["value"];
						$tablePk = SLS_String::substrAfterFirstDelimiter($classPk,"_");
						
						$this->_generic->useModel($tablePk,$db,"user");
						$objectPk = new $classPk();
							
						$properties[$db][$table]["fks"][$column][] = $objectPk->getTable();
					}
				}
			}
		}

		asort($properties,SORT_REGULAR);
		uksort($properties,array($this, 'unshiftDefaultDb'));

		$xml->startTag("dbs");
		foreach($properties as $db => $tables)
		{
			$xml->startTag("db");
				$xml->addFullTag("name",$db,true);
				$xml->startTag("tables");
				foreach($tables as $table => $infos)
				{
					$columns = array();
					$xml->startTag("table");
						$xml->addFullTag("name",$table,true);
						$xml->startTag("types");
						foreach($infos["types"] as $column => $type)
						{
							$xml->addFullTag("type",implode(", ",$type),true,array("column"=>$column));
							$columns[] = $column;
						}
						$xml->endTag("types");
						$xml->startTag("filters");
						foreach($infos["filters"] as $column =>  $filter)
						{
							$xml->addFullTag("filter",implode(", ",$filter),true,array("column"=>$column));
							$columns[] = $column;
						}
						$xml->endTag("filters");
						$xml->startTag("fks");
						foreach($infos["fks"] as $column =>  $fk)
						{
							$xml->addFullTag("fk",implode(", ",$fk),true,array("column"=>$column));
							$columns[] = $column;
						}
						$xml->endTag("fks");
						$xml->startTag("columns");
						foreach($columns as $column)
							$xml->addFullTag("column",$column,true);
						$xml->endTag("columns");
					$xml->endTag("table");
				}
				$xml->endTag("tables");
			$xml->endTag("db");
		}
		$xml->endTag("dbs");
		
		$xml->addFullTag("url_type",$this->_generic->getFullPath("SLS_Bo","EditType",array(),false),true);
		$xml->addFullTag("url_model",$this->_generic->getFullPath("SLS_Bo","EditModel",array(),false),true);
		$xml->addFullTag("url_fk",$this->_generic->getFullPath("SLS_Bo","EditForeignKey",array(),false),true);
		
		$this->saveXML($xml);
	}
Ejemplo n.º 10
0
	/**
	 * Singleton 
	 *
	 * @access public static
	 * @return SLS_Sql $instance SLS_Sql instance
	 * @since 1.0
	 */
	public static function getInstance() 
	{
		if (is_null(self::$_instance)) 		
			self::$_instance = new SLS_Sql();		
		return self::$_instance;
	}
Ejemplo n.º 11
0
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml	= $this->makeMenu($xml);
		$errors = array();
		$mysqlCharsets = array("armscii8","ascii","big5","binary","cp1250","cp1251","cp1256","cp1257","cp850","cp852","cp866","cp932","dec8","eucjpms","euckr","gb2312","gbk","geostd8","greek","hebrew","hp8","keybcs2","koi8u","koi8r","latin1","latin2","latin5","latin7","macce","macroman","sjis","swe7","tis620","ucs2","ujis","utf8");
		
		if ($this->_http->getParam("reload") == "true")
		{
			$dbXML = $this->_generic->getDbXML();
			
			$charset= SLS_String::trimSlashesFromString($this->_http->getParam("charset"));
			$alias 	= strtolower(SLS_String::sanitize(SLS_String::trimSlashesFromString($this->_http->getParam("alias")),""));
			$host 	= SLS_String::trimSlashesFromString($this->_http->getParam("host"));
			$db 	= SLS_String::trimSlashesFromString($this->_http->getParam("db"));
			$user 	= SLS_String::trimSlashesFromString($this->_http->getParam("user"));
			$pass 	= SLS_String::trimSlashesFromString($this->_http->getParam("pass"));
			$no_pas = SLS_String::trimSlashesFromString($this->_http->getParam("no_pass"));
			
			$result = $dbXML->getTagsAttribute("//dbs/db","alias");
			$dbs = array();
			for($i=0 ; $i<$count=count($result) ; $i++)
				array_push($dbs,$result[$i]["attribute"]);
			
			if (empty($charset) || !in_array($charset,$mysqlCharsets))
				array_push($errors, "You have to fill the charset of your database");
			if (empty($alias))
				array_push($errors,"You have to fill the alias of your database");
			if (in_array($alias,$dbs))
				array_push($errors,"This alias is already used by another database");
			if (empty($host))
				array_push($errors,"You have to fill the host of your database");
			if (empty($db))
				array_push($errors,"You have to fill the name of your database");
			if (empty($user))
				array_push($errors,"You have to fill the username of your database");
			if (empty($no_pas) && empty($pass))
				array_push($errors,"You have to fill the password of your database or to check the checkbox");
				
			if (empty($errors) && $this->_http->getParam("ping") != "true")
			{
				$host = SLS_Security::getInstance()->encrypt($host,$this->_generic->getSiteConfig("privateKey"));
				$db   = SLS_Security::getInstance()->encrypt($db,$this->_generic->getSiteConfig("privateKey"));
				$user = SLS_Security::getInstance()->encrypt($user,$this->_generic->getSiteConfig("privateKey"));
				$pass = (empty($no_pas)) ? SLS_Security::getInstance()->encrypt($pass,$this->_generic->getSiteConfig("privateKey")) : "";
				
				$str_xml = '<db alias="'.$alias.'" isDefault="'.((empty($dbs)) ? 'true' : 'false').'" isSecure="true" js="false" charset="'.$charset.'">'.
								'<host><![CDATA['.$host.']]></host>'.
								'<base><![CDATA['.$db.']]></base>'.
								'<user><![CDATA['.$user.']]></user>'.
								'<pass><![CDATA['.$pass.']]></pass>'.
							'</db>';
				$dbXML->appendXMLNode("//dbs",$str_xml);
				$dbXML->saveXML($this->_generic->getPathConfig("configSecure")."db.xml");
				$controllers = $this->_generic->getTranslatedController("SLS_Bo","DataBaseSettings");
				$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"].".sls");
			}			
			$xml->startTag("db");
			$xml->addFullTag("alias",$alias,true);
			$xml->addFullTag("charset",$charset,true);
			$xml->addFullTag("host",$host,true);
			$xml->addFullTag("db",$db,true);
			$xml->addFullTag("user",$user,true);
			$xml->endTag("db");			
		}
		$xml->startTag("charsets");
		foreach($mysqlCharsets as $key => $value)
			$xml->addFullTag("charset",$value,true);
		$xml->endTag("charsets");
		// Ping
		if ($this->_http->getParam("ping") == "true")
		{
			$sql = SLS_Sql::getInstance();
			$verdict = $sql->pingConnection($host,$db,$user,(empty($no_pas) ? $pass : ""));			
			$xml->addFullTag("ping",($verdict===true) ? "true" : $verdict,true);
		}
		if (!empty($errors) && $this->_http->getParam("ping") != "true")
		{
			$xml->startTag("errors");
			foreach($errors as $error)
				$xml->addFullTag("error",$error,true);
			$xml->endTag("errors");
		}		
		$this->saveXML($xml);
	}
Ejemplo n.º 12
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$sql = SLS_Sql::getInstance();		
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$errors = array();
		
		// Get the table 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);
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		if ($sql->tableExists($table))
		{
			if ($this->_http->getParam("reload") == "true")
			{
				$columnWanted = $this->_http->getParam("column");
				$typeWanted = $this->_http->getParam("type");
				
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
				$xmlFk = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
				$xmlType = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
				$xmlFilter = new SLS_XMLToolbox($pathsHandle);
				
				$result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']");
				
				// If an entry already exists in the XML, delete this record
				if (!empty($result))
				{
					$xmlTmp = $xmlType->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']");					
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlTmp);
					$xmlType->refresh();
					$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
					$xmlType = new SLS_XMLToolbox($pathsHandle);
				}
								
				// If file type, check possible thumbs
				if ($typeWanted == "file")
				{
					$typeFile = $this->_http->getParam("file");
					$file_thumb = $this->_http->getParam("file_thumb");
					$multilang = $this->_http->getParam("multilanguage");
					$thumbs = array();
										
					$typeWanted = $typeWanted."_".$typeFile;
					
					if ($typeFile == "img" && !empty($file_thumb))
					{
						for($i=0 ; $i<10 ; $i++)
						{
							$width = $this->_http->getParam("width".$i);
							$height = $this->_http->getParam("height".$i);
							$suffix = $this->_http->getParam("suffix".$i);
							
							if (!empty($suffix) && (!empty($width) || !empty($height)))
								array_push($thumbs,array('width' => $width, 'height' => $height, 'suffix' => $suffix));
						}
					}
					$rules = "*|*|*";
					if ($typeFile == "img")
					{
						$settings = $this->_http->getParam("imgSettings");
						$ratio = str_replace(",",".",$settings["ratio"]);
						$minWidth = str_replace(",",".",$settings["min-width"]);
						$minHeight = str_replace(",",".",$settings["min-height"]);
						$ratio = (!is_numeric($ratio) || (is_numeric($ratio) && $ratio <= 0)) ? "*" : round($ratio,2);
						$minWidth = (!is_numeric($minWidth) || (is_numeric($minWidth) && $minWidth < 0)) ? "*" : round($minWidth,0);
						$minHeight = (!is_numeric($minHeight) || (is_numeric($minHeight) && $minHeight < 0)) ? "*" : round($minHeight,0);
						$rules = $ratio."|".$minWidth."|".$minHeight;
					}
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$rules.'" thumbs="'.str_replace('"','||#||',serialize($thumbs)).'" multilanguage="'.$multilang.'" type="'.$typeWanted.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}				
				else if ($typeWanted == "ip")
				{
					$type = $this->_http->getParam("ip");
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				else if ($typeWanted == "complexity")
				{
					$complexity = $this->_http->getParam("complexity");
					$complexityMin = $this->_http->getParam("complexity_min");					
					$complexity = (empty($complexity)) ? array() : $complexity;
					if (!empty($complexityMin) && is_numeric($complexityMin) && $complexityMin >= 0)
						$complexity[] = "min".$complexityMin;
					$complexity = implode("|",$complexity);
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$complexity.'" type="complexity" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());					
				}			
				else if ($typeWanted == "num")
				{
					$type = $this->_http->getParam("num");
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				// Else, it's email, url, color, uniqid, position, address
				else
				{
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				
				// Disable UserBo quick-edit feature on this column
				if ($typeWanted == "file")
				{
					$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
					$boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']";
					$boExists = $xmlBo->getTag($boPath."/@allowEdit");
					if (empty($boExists))
						$boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']";
					$boExists = $xmlBo->getTag($boPath."/@allowEdit");
					if (!empty($boExists))
					{
						$xmlBo->setTagAttributes($boPath,array("allowEdit" => "false"));
						$xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML());
						$xmlBo->refresh();	
					}
				}
				
				// Update model
				$this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));			
			}
			
			// Get generic object
			$this->_generic->useModel($table,$db,"user");
			$object = new $class();
			
			// Get object's infos
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
			$xmlFk = new SLS_XMLToolbox($pathsHandle);
			$columnsP = $object->getParams();
			$pk = $object->getPrimaryKey();
			$multilanguage = $object->isMultilanguage();		
			$xml->startTag("model");
			$xml->addFullTag("table",$table,true);
			$xml->addFullTag("db",$db,true);
			$xml->addFullTag("class",$class,true);
			$xml->addFullTag("pk",$pk,true);
			$xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true);
			$xml->startTag("columns");
			foreach($columnsP as $column => $value)
			{
				$res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk");				
				if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res))			
					$xml->addFullTag("column",$column,true);
			}		
			$xml->endTag("columns");
			$xml->endTag("model");
			
			$plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml"));
			$pluginImg = array_shift($plugin->getTags("//plugins/plugin[@code='image']"));
			$xml->addFullTag("plugin_img",empty($pluginImg) ? 'false' : 'true',true);
			$xml->addFullTag("plugin_url",$this->_generic->getFullPath("SLS_Bo","Plugins"),true);
		}
		else
		{
			$xml->addFullTag("error","Sorry this table doesn't exist anymore",true);
		}
		
		$this->saveXML($xml);
	}
Ejemplo n.º 13
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$db = SLS_Sql::getInstance();
				
		// Check if we need to create sls_graph_* tables
		if (!$db->tableExists("sls_graph") || !file_exists($this->_generic->getPathConfig("coreSlsModels").ucfirst($this->defaultDb)."Sls_graph.model.php"))
		{
			// Create tables
			$queries = array($this->defaultDb.".sls_graph" 				=> "CREATE TABLE IF NOT EXISTS `sls_graph` (`sls_graph_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_title` varchar(255) NOT NULL COMMENT 'Title', `sls_graph_type` enum('pie','bar','pivot','list') NOT NULL COMMENT 'Type', `sls_graph_visible` enum('yes','no') NOT NULL DEFAULT 'yes' COMMENT 'Visible?', `sls_graph_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_id`), KEY `sls_graph_visible` (`sls_graph_visible`), KEY `sls_graph_query_id` (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query" 		=> "CREATE TABLE IF NOT EXISTS `sls_graph_query` (`sls_graph_query_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_db_alias` varchar(255) NOT NULL COMMENT 'Db alias', `sls_graph_query_table` varchar(255) NOT NULL COMMENT 'Table name', `sls_graph_query_table_alias` varchar(255) NOT NULL COMMENT 'Table alias', `sls_graph_query_date_add` datetime NOT NULL COMMENT 'Date add', PRIMARY KEY (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Query' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_column" => "CREATE TABLE IF NOT EXISTS `sls_graph_query_column` (`sls_graph_query_column_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_column_table` varchar(255) NOT NULL COMMENT 'Table name', `sls_graph_query_column_table_alias` varchar(255) NOT NULL COMMENT 'Table alias', `sls_graph_query_column_name` varchar(255) DEFAULT NULL COMMENT 'Column name', `sls_graph_query_column_alias` varchar(255) DEFAULT NULL COMMENT 'Column alias', `sls_graph_query_column_aggregation` enum('sum','avg','count') DEFAULT NULL COMMENT 'Aggregation function', `sls_graph_query_column_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_query_column_id`), KEY `sls_graph_query_id` (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Column' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_group" 	=> "CREATE TABLE IF NOT EXISTS `sls_graph_query_group` (`sls_graph_query_group_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_group_table` varchar(255) NOT NULL COMMENT 'Table name', `sls_graph_query_group_table_alias` varchar(255) NOT NULL COMMENT 'Table alias', `sls_graph_query_group_column` varchar(255) NOT NULL COMMENT 'Column', `sls_graph_query_group_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_query_group_id`), KEY `sls_graph_query_id` (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Group' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_join" 	=> "CREATE TABLE IF NOT EXISTS `sls_graph_query_join` (`sls_graph_query_join_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_join_table_source` varchar(255) NOT NULL COMMENT 'Table name source', `sls_graph_query_join_table_alias_source` varchar(255) NOT NULL COMMENT 'Table alias source', `sls_graph_query_join_table_target` varchar(255) NOT NULL COMMENT 'Table name target', `sls_graph_query_join_table_alias_target` varchar(255) NOT NULL COMMENT 'Table alias target', `sls_graph_query_join_mode` enum('inner','left','right') NOT NULL COMMENT 'Join mode', `sls_graph_query_join_column_source` varchar(255) NOT NULL COMMENT 'Column PK', `sls_graph_query_join_column_target` varchar(255) NOT NULL COMMENT 'Column FK', `sls_graph_query_join_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_query_join_id`), KEY `sls_graph_query_id` (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Join' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_limit" 	=> "CREATE TABLE IF NOT EXISTS `sls_graph_query_limit` (`sls_graph_query_limit_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_limit_start` int(11) NOT NULL COMMENT 'Start', `sls_graph_query_limit_length` int(11) NOT NULL COMMENT 'Length', `sls_graph_query_limit_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_query_limit_id`), KEY `sls_graph_query_id` (`sls_graph_query_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Limit' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_order" 	=> "CREATE TABLE IF NOT EXISTS `sls_graph_query_order` (`sls_graph_query_order_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_order_table` varchar(255) NOT NULL COMMENT 'Table name', `sls_graph_query_order_table_alias` varchar(255) NOT NULL COMMENT 'Table alias', `sls_graph_query_order_column` varchar(255) NOT NULL COMMENT 'Column', `sls_graph_query_order_way` enum('asc','desc') NOT NULL COMMENT 'Order', `sls_graph_query_order_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', PRIMARY KEY (`sls_graph_query_order_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Order' AUTO_INCREMENT=1;",
							 $this->defaultDb.".sls_graph_query_where" 	=> "CREATE TABLE IF NOT EXISTS `sls_graph_query_where` (`sls_graph_query_where_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id', `sls_graph_query_where_type` enum('group','clause') NOT NULL COMMENT 'Type', `sls_graph_query_where_condition` enum('and','or') DEFAULT NULL COMMENT 'Condition', `sls_graph_query_where_table` varchar(255) DEFAULT NULL COMMENT 'Table name', `sls_graph_query_where_table_alias` varchar(255) DEFAULT NULL COMMENT 'Table alias', `sls_graph_query_where_column` varchar(255) DEFAULT NULL COMMENT 'Column', `sls_graph_query_where_operator` enum('like','notlike','startwith','endwith','equal','notequal','in','notin','lt','lte','gt','gte','null','notnull') DEFAULT NULL COMMENT 'Operator', `sls_graph_query_where_value` varchar(255) DEFAULT NULL COMMENT 'Value', `sls_graph_query_where_date_add` datetime NOT NULL COMMENT 'Date add', `sls_graph_query_id` bigint(20) NOT NULL COMMENT 'Query', `parent_sls_graph_query_where_id` bigint(20) DEFAULT '0' COMMENT 'Where Parent', PRIMARY KEY (`sls_graph_query_where_id`), KEY `sls_graph_query_id` (`sls_graph_query_id`), KEY `parent_sls_graph_query_where_id` (`parent_sls_graph_query_where_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reporting - Graph - Where' AUTO_INCREMENT=1;");
			foreach($queries as $table => $query)
				$db->exec($query);
			
			// Create models
			$url = $this->_generic->getFullPath("SLS_Bo",
											    "GenerateModels",
											    array("reload" => "true",
											   		  "token"  => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
											    false);
			$tables = array_keys($queries);
			foreach($tables as $table)
				$url .= "/tables[]/".$table;
			$url .= ".".$this->_generic->getSiteConfig("defaultExtension");
			file_get_contents($url);
			
			// Move to sls side
			foreach(array_keys($queries) as $model)
			{
				$modelDb = SLS_String::substrBeforeFirstDelimiter($model,".");
				$modelTable = SLS_String::substrAfterFirstDelimiter($model,".");
				$modelClass = ucfirst($modelDb).".".SLS_String::tableToClass($modelTable);
				
				// Move object
				if (file_exists($this->_generic->getPathConfig("models").$modelClass.".model.php"))
					rename($this->_generic->getPathConfig("models").$modelClass.".model.php",$this->_generic->getPathConfig("coreSlsModels").$modelClass.".model.php");
				// Move sql
				if (file_exists($this->_generic->getPathConfig("modelsSql").$modelClass.".sql.php"))
					rename($this->_generic->getPathConfig("modelsSql").$modelClass.".sql.php",$this->_generic->getPathConfig("coreSlsModelsSql").$modelClass.".sql.php");
			}
		}
		
		// Objects
		$this->_generic->useModel('Sls_graph',$this->defaultDb,'sls');
		$className = ucfirst($this->defaultDb)."_Sls_graph";
		$graph = new $className();
		
		$graphs = $graph->searchModels("sls_graph",array(),array(),array(),array("sls_graph_date_add" => "desc"));
		$xml = $graph->pdoToXML($xml,$graphs);
		
		// Actions
		$this->_generic->registerLink('Add', 'SLS_Bo', 'ReportingBoAdd');
		$xml->addFullTag("url_view",$this->_generic->getFullPath("SLS_Bo","ReportingBoView",array(),false));
		$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","ReportingBoDelete",array(),false));
		$xml->addFullTag("url_edit",$this->_generic->getFullPath("SLS_Bo","ReportingBoEdit",array(),false));
		$xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ReportingBoStatus",array(),false));
		
		$this->saveXML($xml);
	}
Ejemplo n.º 14
0
	/**
	 * Include a model	 
	 *
	 * @access public
	 * @param string $modelName the model to use
	 * @param string $db the alias of the db on which we can find the model
	 * @param string $side force the side
	 * @return bool true if succes, else false
	 * @since 1.0
	 */
	public function useModel($modelName,$db="",$side="") 
	{
		// Check default side
		if (!empty($side))
		{
			if ($side=="sls")
				$path = "coreSls";
			else if ($side=="user")
				$path = "";
		}
		else
			$path = ($this->getSide()=='sls') ?	"coreSls" :"";
		
		// Check default db
		if (empty($db))
		{
			$result = array_shift($this->_configDb->getTagsAttribute("//dbs/db[@isDefault='true']","alias"));
			$db = $result["attribute"];
		}
		// Include model files
		if (is_file($this->getPathConfig($path.((empty($path)) ? "models" : "Models")).ucfirst($db).".".ucfirst($modelName).".model.php") and is_file($this->getPathConfig($path.((empty($path)) ? "modelsSql" : "ModelsSql")).ucfirst($db).".".ucfirst($modelName).".sql.php")) 
		{
			include_once($this->getPathConfig($path.((empty($path)) ? "models" : "Models")).ucfirst($db).".".ucfirst($modelName).".model.php");
			include_once($this->getPathConfig($path.((empty($path)) ? "modelsSql" : "ModelsSql")).ucfirst($db).".".ucfirst($modelName).".sql.php");
			
			// Check if the correct database is already set
			$sql = SLS_Sql::getInstance();			
			if (strtolower($db) != strtolower($sql->getCurrentDb()))
				$sql->changeDb($db);
			
			return true;
		}
		else 
		{
			return false;	
		}
	}
Ejemplo n.º 15
0
	public function action()
	{
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$user = $this->hasAuthorative();
				
		// Objects
		$sql = SLS_Sql::getInstance();
		$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
		$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
		$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));
		
		// Get the table & class name
		$tableName 	= SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   		= SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$className 	= ucfirst($db)."_".SLS_String::tableToClass($tableName);
		$file 		= ucfirst($db).".".SLS_String::tableToClass($tableName);
		$fileName 	= ucfirst($db).".".SLS_String::tableToClass($tableName).".model.php";
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		// Remind old properties
		$this->_generic->useModel(SLS_String::tableToClass($tableName),ucfirst(strtolower($db)), "user");
		$object = new $className();
		$oldColumns = $object->getColumns();
		
		// Update Model
		$contentM = $this->getModelSource($tableName,$db);
		file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM);
		
		// Check Bo
		$controllerBo = $this->_generic->getBo();
		if (!empty($controllerBo))
		{
			$boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($className)."']";
			$boExists = $xmlBo->getTag($boPath."/@type");
			if (empty($boExists))
			{
				$boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($className)."']";
				$boExists = $xmlBo->getTag($boPath);
			}
			if (!empty($boExists))
			{
				$columns = $sql->showColumns($tableName);
				$newColumns = array();
				for($i=0 ; $i<$count=count($columns) ; $i++)
					$newColumns[] = $columns[$i]->Field;
				
				$xmlNodes = '';
				foreach($newColumns as $column)
				{
					$columnExists = $xmlBo->getTag($boPath."/columns/column[@table='".strtolower($className)."' and @name='".$column."']/@name");
					if (empty($columnExists))
					{
						// Avoid pk
						$isPk = ($column == $object->getPrimaryKey() || $column == 'pk_lang') ? true : false;
						// Avoid fk
						$fkExist = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($db."_".$tableName)."' and @columnFk='".$column."']/@tablePk");
						$isFk = (!empty($fkExist)) ? true : false;
						// Avoid quick edit on type file
						$fileExist = $xmlType->getTag("//sls_configs/entry[@table='".strtolower($db."_".$tableName)."' and @column='".$column."' and (@type='file_all' or @type='file_img')]/@column");
						$isFile = (!empty($fileExist)) ? true : false;
						
						$xmlNodes .= '            <column table="'.strtolower($db."_".$tableName).'" name="'.$column.'" multilanguage="'.(($object->isMultilanguage() && !$isPk) ? "true" : "false").'" displayFilter="true" displayList="'.(($isFk) ? "false" : "true").'" allowEdit="'.(($isPk || $isFk || $isFile) ? "false" : "true").'" allowHtml="false" />'."\n";
					}
				}
				if (!empty($xmlNodes))
				{
					$xmlBo->appendXMLNode($boPath."/columns",$xmlNodes);
				}
				$deprecatedColumns = array_diff($oldColumns,$newColumns);
				foreach($deprecatedColumns as $column)
				{
					$xmlBo->deleteTags($boPath."/columns/column[@table='".strtolower($className)."' and @name='".$column."']",1);
				}
				$xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML());
				$xmlBo->refresh();
			}
		}
		
		$action_id = $this->_http->getParam("Redirect");
		if ($this->_generic->actionIdExists($action_id))
		{
			$infos = $this->_generic->translateActionId($action_id);			
			$this->_generic->redirect($infos['controller']."/".$infos['scontroller']);
		}
		else
		{
			$controllers = $this->_generic->getTranslatedController("SLS_Bo","EditModel");		
			$this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']."/name/".$db."_".$tableName);
		}
	}
Ejemplo n.º 16
0
	public function action()
	{
		$user = $this->hasAuthorative();
		
		// Objects
		$sql = SLS_Sql::getInstance();		
		$xml = $this->getXML();		
		$xml = $this->makeMenu($xml);
		
		// Actions
		$xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteModel",array(),false));
		$xml->addFullTag("delete_bearer",$this->_generic->getFullPath("SLS_Bo","DeleteBearerTable",array(),false));
		$xml->addFullTag("delete_type",$this->_generic->getFullPath("SLS_Bo","DeleteType",array(),false));
		$xml->addFullTag("edit_type",$this->_generic->getFullPath("SLS_Bo","EditType",array(),false));
		$xml->addFullTag("delete_fk",$this->_generic->getFullPath("SLS_Bo","DeleteForeignKey",array(),false));
		$xml->addFullTag("edit_fk",$this->_generic->getFullPath("SLS_Bo","EditForeignKey",array(),false));
		$xml->addFullTag("update",$this->_generic->getFullPath("SLS_Bo","UpdateModel",array(),false));		
		$xml->addFullTag("descriptions",$this->_generic->getFullPath("SLS_Bo","UpdateDescription",array(),false));
		
		// 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);
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		// Get generic object
		$this->_generic->useModel(SLS_String::tableToClass($table),$db,"user");
		$object = new $class();
		
		// Get description's table
		$description = $object->getTableComment($table);	
		$columnsInfos = $sql->showColumns($table);
		
		// Get object's infos
		$columns = array();
		$columnsP = $object->getParams();
		$pk = $object->getPrimaryKey();
		$multilanguage = $object->isMultilanguage();
		$xml->startTag("model");
		$xml->addFullTag("table",$table,true);
		$xml->addFullTag("description",(SLS_String::contains($description,"InnoDB free")) ? SLS_String::substrBeforeFirstDelimiter($description,"; InnoDB free") : $description,true);
		$xml->addFullTag("db",$db,true);
		$xml->addFullTag("class",$class,true);
		$xml->addFullTag("pk",$pk,true);
		$xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true);
		$xml->startTag("columns");
		$cursor = 0;
		foreach($columnsP as $column => $value)
		{
			$xml->startTag("column");
			$xml->addFullTag("name",$column,true);
			array_push($columns,$column);
			$fk = "";
			$sType = "";
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
			$xmlFk = new SLS_XMLToolbox($pathsHandle);			
			$res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$table,$column));
			if (!empty($res))
			{
				$tableTmp = substr($res,(strpos($res,'tablePk="')+9),(strpos($res,'"/>')-(strpos($res,'tablePk="')+9)));
				$fk = SLS_String::substrAfterFirstDelimiter($tableTmp,"_");				
			}
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
			$xmlType = new SLS_XMLToolbox($pathsHandle);						
			$res = $xmlType->getTagsByAttributes("//sls_configs/entry",array("table","column"),array($db."_".$table,$column));
			if (!empty($res))
			{
				$sType = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($res,'type="'),'"/>');
				// If specific type numeric and native type too
				if (SLS_String::startsWith($sType,"num_") && $this->containsRecursive($columnsInfos[$cursor]->Type,array("int","float","double","decimal","real")))
					$xml->addFullTag("allow_to_delete_type","false",true);
			}
			
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
			$xmlFilter = new SLS_XMLToolbox($pathsHandle);			
			$results = $xmlFilter->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$column."']",array("filter","hash"));			
			$xml->startTag("filters");
			for($i=0 ; $i<$count=count($results) ; $i++)
			{
				$filter = $results[$i]["attributes"][0]["value"];
				$result = $results[$i]["attributes"][1]["value"];
				
				$xml->startTag("filter");
					$xml->addFullTag("name",$filter.((!empty($result)) ? ' ['.$result.']' : ''),true);
					$xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","DeleteFilter",array(array("key"=>"table","value"=>$this->_http->getParam("name")),array("key"=>"column","value"=>$column),array("key"=>"filter","value"=>$filter))),true);
				$xml->endTag("filter");
			}
			$xml->endTag("filters");
			$xml->addFullTag("fk",$fk,true);
			$xml->addFullTag("type",ucfirst($sType),true);
			$xml->addFullTag("comment",$object->getColumnComment($column),true);
			$xml->endTag("column");
			
			$cursor++;
		}
		$xml->endTag("columns");
		$xml->addFullTag("url_add_type",$this->_generic->getFullPath("SLS_Bo","AddType",array(0=>array("key"=>"name","value"=>$db."_".$table))),true);
		$xml->addFullTag("url_add_filter",$this->_generic->getFullPath("SLS_Bo","AddFilter",array(0=>array("key"=>"name","value"=>$db."_".$table))),true);
		$xml->addFullTag("url_add_fk",$this->_generic->getFullPath("SLS_Bo","AddForeignKey",array(0=>array("key"=>"name","value"=>$db."_".$table))),true);
		
		// Get the source of the current model
		$xml->addFullTag("current_source",str_replace("\t","    ",file_get_contents($this->_generic->getPathConfig("models").$file.".model.php")),true);
		
		// Get the source of the current table
		if (!$sql->tableExists($table))
			$xml->addFullTag("current_table",-1,true);
		else
		{
			$columns = $sql->showColumns($table);					
			$tableName = $table;
			$currentTable = array("table"=>$db.".".$tableName,"errors"=>array());			
			$className = ucfirst($db)."_".SLS_String::tableToClass($tableName);
			$fileName = ucfirst($db).".".SLS_String::tableToClass($table).".model.php";
			$primaryKey = "";
			$multiLanguage = 'false';
			
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
			$xmlType = new SLS_XMLToolbox($pathsHandle);
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
			$xmlFk = new SLS_XMLToolbox($pathsHandle);
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
			$xmlFilter = new SLS_XMLToolbox($pathsHandle);
			
			// Get source
			$contentM = $this->getModelSource($tableName,$db);
			
			// Is data bearer
			$xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml"));
			$result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1")));
			$xml->addFullTag("is_data_bearer",(!empty($result)) ? $result["attributes"][0]["value"] : "false",true);
			
			// Save the new source
			$xml->addFullTag("current_table",str_replace("\t","    ",$contentM),true);
			$xml->addFullTag("url_data_bearer",$this->_generic->getFullPath("SLS_Bo","AddBearerTable",array(array("key"=>"name","value"=>$this->_http->getParam("name")))),true);
		}		
		$xml->endTag("model");
		$this->saveXML($xml);
	}
Ejemplo n.º 17
0
	public function action() 
	{		
		// Objects
		$xml = $this->getXML();
		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		$actions = array("read"   => array(),
						 "add" 	  => array(),
						 "edit"   => array(),
						 "delete" => array(),
						 "clone"  => array(),
						 "email"  => array(),
						 "custom" => array());
		$autoActions = array("BoDashBoard", "BoDeleteFile", "BoExport", "BoFkAc", "BoIsLogged", "BoLike", "BoSetting", "BoUnique", "BoUpload", "BoUploadProgress");
		$_publicActions = array("BoLogin",
								"BoLogout",
								"BoForgottenPwd",
								"BoMenu", 
								"BoRenewPwd",
								"BoSwitchLang");
		$_forbiddenActions = array("BoPopulate");
		$db = SLS_Sql::getInstance();
		$color = "pink";
		$xmlColors = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo_colors.xml"));
		$errors = array();
		
		if ($db->tableExists("sls_graph"))
		{
			$actions["dashboard"] = array();
			$dashboardId = $this->_generic->getControllersXML()->getTag("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoDashBoard']/@id");
			$this->_generic->useModel("Sls_graph",$this->defaultDb,"sls");
			$className = ucfirst($this->defaultDb)."_Sls_graph";
			$slsGraph = new $className;
			$slsGraphs = $slsGraph->searchModels("sls_graph",array(),array(),array(),array("sls_graph_title" => "asc"));
			for($i=0 ; $i<$count=count($slsGraphs) ; $i++)
				$actions["dashboard"][$dashboardId."_sls_graph_".$slsGraphs[$i]->sls_graph_id] = "_".$slsGraphs[$i]->sls_graph_title;
		}
		
		$results = $this->_generic->getControllersXML()->getTagsAttributes("//controllers/controller[@isBo='true']/scontrollers/scontroller",array("name","id"));
		for($i=0 ; $i<$count=count($results) ; $i++)
		{
			$name = $results[$i]["attributes"][0]["value"];
			$aid = $results[$i]["attributes"][1]["value"];
			switch($name)
			{
				case (SLS_String::startsWith($name,"List") && SLS_String::contains($name,"_")):
					$actions["read"][$aid] = $name;		
					break;
				case (SLS_String::startsWith($name,"Add") && SLS_String::contains($name,"_")):
					$actions["add"][$aid] = $name;		
					break;
				case (SLS_String::startsWith($name,"Modify") && SLS_String::contains($name,"_")):
					$actions["edit"][$aid] = $name;		
					break;
				case (SLS_String::startsWith($name,"Delete") && SLS_String::contains($name,"_")):
					$actions["delete"][$aid] = $name;		
					break;
				case (SLS_String::startsWith($name,"Clone") && SLS_String::contains($name,"_")):
					$actions["clone"][$aid] = $name;		
					break;
				case (SLS_String::startsWith($name,"Email") && SLS_String::contains($name,"_")):
					$actions["email"][$aid] = $name;		
					break;
				default:
					if (!in_array($name,$_publicActions) && !in_array($name,$_forbiddenActions) && !in_array($name,$autoActions))
					{
						$id = array_shift($this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='".$name."']/@id"));
						if (!empty($id))
							$actions["custom"][$id] = "_".$name;
					}
					break;
			}
		}
		$xml->startTag("bo_groups");
		foreach($actions as $action => $values)
		{
			$xml->startTag("bo_group");
			$xml->addFullTag("name",$action,true);
			foreach($values as $aid => $name)
			{
				$model = "";
				switch ($name)
				{
					case (SLS_String::startsWith($name,"List")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"List"),"_"); 	break;
					case (SLS_String::startsWith($name,"Add")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"Add"),"_"); 	break;
					case (SLS_String::startsWith($name,"Modify")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"Modify"),"_"); break;
					case (SLS_String::startsWith($name,"Delete")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"Delete"),"_"); break;
					case (SLS_String::startsWith($name,"Clone")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"Clone"),"_"); 	break;
					case (SLS_String::startsWith($name,"Email")): 	$model = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($name,"Email"),"_"); 	break;
					default:										$model = "";
				}
				$xml->startTag("action");
					$xml->addFullTag("name",SLS_String::substrAfterFirstDelimiter($name,"_"),true);
					$xml->addFullTag("model",$model,true);
					$xml->addFullTag("id",$aid,true);
				$xml->endTag("action");
			}
			$xml->endTag("bo_group");
		}
		$xml->endTag("bo_groups");
		
		$complexity_pwd_min_char_nb = 8;
		$renew_pwd_nb = 2;
		$renew_pwd_unite = "month";
		$renew_pwd_log_nb = 3;
		$complexity = array();
		$privilegeChoose = false;
		$minChars = "";
		$enabled = "true";
		
		if ($this->_http->getParam("reload") == "true")
		{
			$login 							= SLS_String::trimSlashesFromString($this->_http->getParam("login"));
			$name 							= SLS_String::trimSlashesFromString($this->_http->getParam("name"));
			$firstname						= SLS_String::trimSlashesFromString($this->_http->getParam("firstname"));
			$pwd 							= SLS_String::trimSlashesFromString($this->_http->getParam("password"));
			$enabled						= SLS_String::trimSlashesFromString($this->_http->getParam("enabled"));
			$complexity_pwd_lc 				= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_lc"));
			$complexity_pwd_uc 				= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_uc"));
			$complexity_pwd_digit 			= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_digit"));
			$complexity_pwd_special_char 	= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_special_char"));
			$complexity_pwd_min_char 		= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_min_char"));
			$complexity_pwd_min_char_nb 	= SLS_String::trimSlashesFromString($this->_http->getParam("complexity_pwd_min_char_nb"));
			$reset_pwd 						= SLS_String::trimSlashesFromString($this->_http->getParam("reset_pwd"));
			$renew_pwd 						= SLS_String::trimSlashesFromString($this->_http->getParam("renew_pwd"));
			$renew_pwd_nb 					= SLS_String::trimSlashesFromString($this->_http->getParam("renew_pwd_nb"));
			$renew_pwd_unite 				= SLS_String::trimSlashesFromString($this->_http->getParam("renew_pwd_unite"));
			$renew_pwd_log 					= SLS_String::trimSlashesFromString($this->_http->getParam("renew_pwd_log"));
			$renew_pwd_log_nb 				= SLS_String::trimSlashesFromString($this->_http->getParam("renew_pwd_log_nb"));
			$color 							= SLS_String::trimSlashesFromString($this->_http->getParam("color"));
			$params 						= $this->_http->getParams();
			
			$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))			
				array_push($errors,"This account already exists, please choose another login.");
			if (empty($name) || empty($firstname))
				array_push($errors,"You must fill name and firstname.");
			if (empty($login) || empty($pwd))
				array_push($errors,"You must choose username and password.");
			
			foreach($params as $key => $value)
			{				
				if (SLS_String::startsWith($key,"bo_action"))
				{
					$privilegeChoose = true;
					break;
				}
			}
			if (!$privilegeChoose)			
				array_push($errors,"You must choose at least 1 privilege.");
			
			if (empty($errors))
			{
				if ($complexity_pwd_lc == "true")
					array_push($complexity,"lc");
				if ($complexity_pwd_uc == "true")
					array_push($complexity,"uc");
				if ($complexity_pwd_digit == "true")
					array_push($complexity,"digit");
				if ($complexity_pwd_special_char == "true")
					array_push($complexity,"special_char");
					
				if ($complexity_pwd_min_char == "true")
					$minChars = $complexity_pwd_min_char_nb;
								
				$xmlNew = '<entry login="******" name="'.SLS_String::stringToUrl($name," ").'" firstname="'.SLS_String::stringToUrl($firstname," ").'" enabled="'.$enabled.'" password="******" password_old="" last_connection="" last_renew_pwd="'.date("Y-m-d").'" complexity_pwd="'.implode("|",$complexity).'" min_chars_pwd="'.$minChars.'" reset_pwd="'.(($reset_pwd=="true") ? "true" : "").'" renew_pwd="'.(($renew_pwd=="true") ? $renew_pwd_nb." ".$renew_pwd_unite : "").'" renew_pwd_nb="'.(($renew_pwd_log=="true") ? $renew_pwd_log_nb : "").'">'."\n";
				
				// Default settings
				$xmlNew .= '    <settings>'."\n".
							'      <setting key="nav_filter"><![CDATA[default]]></setting>'."\n".
							'      <setting key="list_view"><![CDATA[collapse]]></setting>'."\n".
							'      <setting key="list_nb_by_page"><![CDATA[20]]></setting>'."\n".
							'      <setting key="add_callback"><![CDATA[list]]></setting>'."\n".
							'      <setting key="edit_callback"><![CDATA[list]]></setting>'."\n".
							'      <setting key="export_format"><![CDATA[excel]]></setting>'."\n".
							'      <setting key="export_all_column"><![CDATA[true]]></setting>'."\n".
							'      <setting key="export_all_table"><![CDATA[true]]></setting>'."\n".
							'      <setting key="export_display_legend"><![CDATA[true]]></setting>'."\n".
							'      <setting key="quick_edit"><![CDATA[disabled]]></setting>'."\n".
							'      <setting key="dashboard_ga"><![CDATA[visible]]></setting>'."\n".
							'      <setting key="dashboard_metric"><![CDATA[visible]]></setting>'."\n".
							'      <setting key="dashboard_monitoring"><![CDATA[visible]]></setting>'."\n".
							'      <setting key="dashboard_graph"><![CDATA[visible]]></setting>'."\n".
							'      <setting key="dashboard_email"><![CDATA[visible]]></setting>'."\n".
							'      <setting key="color"><![CDATA['.((empty($color)) ? "pink" : $color).']]></setting>'."\n".
							'    </settings>'."\n";
				foreach($autoActions as $actionName)
				{
					$aid = $this->_generic->getControllersXML()->getTag("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='".$actionName."']/@id");
					$xmlNew .= '    <action id="'.$aid.'" role="custom" entity="" />'."\n";
				}
				foreach($params as $key => $value)
				{
					if (SLS_String::startsWith($key,"bo_action"))
					{
						$xmlNew .= '    <action id="'.$value.'" role="'.SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($key,"bo_action_"),"_").'" entity="'.((SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($key,"bo_action_"),"_") == "custom") ? "" : SLS_String::substrAfterFirstDelimiter(SLS_String::substrAfterFirstDelimiter($key,"bo_action_"),"_")).'" />'."\n";
					}
				}
				
				$xmlNew .= '  </entry>';				
				$xmlRights->appendXMLNode("//sls_configs",$xmlNew);
				$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());
				$this->_generic->redirect("Manage/Rights");				
			}
			else
			{
				$xml->startTag("errors");
				foreach($errors as $error)
					$xml->addFullTag("error",$error,true);
				$xml->endTag("errors");
			}
		}
		
		$xml->addFullTag("complexity_pwd_lc",$complexity_pwd_lc,true);
		$xml->addFullTag("complexity_pwd_uc",$complexity_pwd_uc,true);
		$xml->addFullTag("complexity_pwd_digit",$complexity_pwd_digit,true);
		$xml->addFullTag("complexity_pwd_special_char",$complexity_pwd_special_char,true);
		$xml->addFullTag("complexity_pwd_min_char",$complexity_pwd_min_char,true);
		$xml->addFullTag("complexity_pwd_min_char_nb",$complexity_pwd_min_char_nb,true);
		$xml->addFullTag("reset_pwd",$reset_pwd,true);
		$xml->addFullTag("renew_pwd",$renew_pwd,true);
		$xml->addFullTag("renew_pwd_nb",$renew_pwd_nb,true);
		$xml->addFullTag("renew_pwd_unite",$renew_pwd_unite,true);
		$xml->addFullTag("renew_pwd_log",$renew_pwd_log,true);
		$xml->addFullTag("renew_pwd_log_nb",$renew_pwd_log_nb,true);
		$xml->addFullTag("enabled",$enabled,true);
		$xml->addFullTag("color",(empty($color)) ? "pink" : $color,true);
		$colors = $xmlColors->getTagsAttributes("//sls_configs/template",array("name","hexa"));
		$xml->startTag("colors");
		for($i=0 ; $i<$count=count($colors) ; $i++)
			$xml->addFullTag("color",$colors[$i]["attributes"][0]["value"],true,array("hexa" => $colors[$i]["attributes"][1]["value"]));
		$xml->endTag("colors");
		
		$xml->addFullTag("url_generate_bo",$this->_generic->getFullPath("SLS_Bo","GenerateBo"),true);
		
		$this->saveXML($xml);
	}
Ejemplo n.º 18
0
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml 	= $this->makeMenu($xml);
		$langs 	= array();
		$appli_langs = array();
		$handle = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."international.xml"));
		$step = 0;
		$errors = array();
		$controllerXML = $this->_generic->getControllersXML();
		$metaXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."metas.xml"));
		$appli_langs = $this->_generic->getObjectLang()->getSiteLangs();
		$defaultLang = $this->_generic->getObjectLang()->getDefaultLang();
		
		// If lang have been choose
		if ($this->_http->getParam("step") == "1")
		{
			$lang1 = SLS_String::trimSlashesFromString($this->_http->getParam("lang"));
			$lang  = array_shift($handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[node()='".$lang1."']/@iso"));			
			
			if (!in_array($lang,$appli_langs))
			{
				$step = 2;
				$xml->addFullTag("step","2",true);
				$xml->addFullTag("lang_to_add",$lang,true);
			}
			else
			{
				$xml->addFullTag("lang_selected",$lang1,true);
				$xml->startTag("errors");
				$xml->addFullTag("error","This lang already exist in your application",true);
				$xml->endTag("errors");
			}		
		}
		if ($this->_http->getParam("step") == "2" || $step == 2)
		{			
			$lang = (empty($lang)) ? $this->_http->getParam("lang_to_add") : $lang;
			$xml->addFullTag("step","2",true);
			$xml->addFullTag("lang_to_add",$lang,true);
			
			$generics = array(	"MONDAY" 							=> "",
								"TUESDAY" 							=> "",
								"WEDNESDAY" 						=> "",
								"THURSDAY" 							=> "",
								"FRIDAY" 							=> "",
								"SATURDAY" 							=> "",
								"SUNDAY" 							=> "",
								"JANUARY" 							=> "",
								"FEBRUARY" 							=> "",
								"MARCH" 							=> "",
								"APRIL" 							=> "",
								"MAY" 								=> "",
								"JUNE" 								=> "",
								"JULY" 								=> "",
								"AUGUST" 							=> "",
								"SEPTEMBER" 						=> "",
								"OCTOBER" 							=> "",
								"NOVEMBER" 							=> "",
								"DECEMBER" 							=> "",
								"DATE_PATTERN_TIME" 				=> "",
								"DATE_PATTERN_FULL_TIME" 			=> "",
								"DATE_PATTERN_DATE" 				=> "",
								"DATE_PATTERN_MONTH_LITTERAL" 		=> "",
								"DATE_PATTERN_FULL_LITTERAL" 		=> "",
								"DATE_PATTERN_FULL_LITTERAL_TIME" 	=> "",
								"DATE_PATTERN_MONTH_LITTERAL_TIME" 	=> "",
								"DATE_DIFF_Y"						=> "",
								"DATE_DIFF_M"						=> "",
								"DATE_DIFF_W"						=> "",
								"DATE_DIFF_D"						=> "",
								"DATE_DIFF_H"						=> "",
								"DATE_DIFF_I"						=> "",
								"DATE_DIFF_S"						=> "",
								"E_CONTENT" 						=> "",
								"E_EMPTY" 							=> "",
								"E_KEY" 							=> "",
								"E_COMPLEXITY" 						=> "",
								"E_LENGTH" 							=> "",
								"E_NULL" 							=> "",
								"E_UNIQUE" 							=> "",
								"E_TYPE" 							=> "",
								"E_SIZE" 							=> "",
								"E_EXIST" 							=> "",
								"E_WRITE" 							=> "",
								"E_LOGGED" 							=> "",
								"E_AUTHORIZED" 						=> ""
							);									
			// Try to recover generic langs from Deployement
			if (file_exists($this->_generic->getPathConfig("installDeployement")."Langs/Generics/generic.".$lang.".lang.php"))
				include($this->_generic->getPathConfig("installDeployement")."Langs/Generics/generic.".$lang.".lang.php");			
			// Set the default value by english or current lang if has been found in Deployement
			foreach($generics as $key => $value)			
				$generics[$key] = SLS_String::trimSlashesFromString($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_'.$key]);
			
			$controllers = array();
				
			// Recover all controllers
			$controllersA = $controllerXML->getTags("//controllers/controller[@side='user']/@name");
			foreach($controllersA as $controller)
			{
				$id = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/@id"));
				
				$values = array();
				foreach($appli_langs as $appli_lang)				
					$values[$appli_lang] = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/controllerLangs/controllerLang[@lang='".$appli_lang."']"));					
				$values[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam($id."_".$lang));
				
				$result = array("id" => $id, "key" => $controller, "values" => $values, "actions" => array());
				array_push($controllers,$result);
			}
			
			// Foreach controllers, recover all actions
			for($i=0 ; $i<$count=count($controllers) ; $i++)
			{
				$controller = $controllers[$i]["key"];
				$actions = $controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller/@name");
				$actionsA = array();
				
				foreach($actions as $action)
				{
					$id = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."']/@id"));
					
					$values = array();
					foreach($appli_langs as $appli_lang)				
						$values[$appli_lang] = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."']/scontrollerLangs/scontrollerLang[@lang='".$appli_lang."']"));
					$values[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam($id."_".$lang));
					
					$metas = array("title" => array(), "description" => array(), "keywords" => array());
					$titles = array();
					$descriptions = array();
					$keywords = array();
					foreach($appli_langs as $appli_lang)
					{	
						$titles[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/title[@lang='".$appli_lang."']"));						
						$descriptions[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/description[@lang='".$appli_lang."']"));						
						$keywords[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/keywords[@lang='".$appli_lang."']"));										
					}
					$titles[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_title-".$id."_".$lang));
					$descriptions[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_description-".$id."_".$lang));
					$keywords[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_keywords-".$id."_".$lang));
					$metas["title"] = $titles;
					$metas["description"] = $descriptions;
					$metas["keywords"] = $keywords;
					
					$result = array("id" => $id,"key" => $action, "values" => $values, "metas" => $metas);
					array_push($actionsA,$result);
				}
				$controllers[$i]["actions"] = $actionsA;
			}
			
			// If informations have been sent, check if it's good
			if ($this->_http->getParam("reload") == "true")
			{
				$mods = array();
				$smods = array();
				
				// Get all controllers
				foreach($this->_http->getParams() as $key => $value)
				{
					// Controllers case
					if (SLS_String::startsWith($key,"c_"))
					{
						$id = SLS_String::substrBeforeLastDelimiter($key,"_".$lang);
						$mod = array_shift($controllerXML->getTags("//controllers/controller[@id='".$id."']/@name"));
						$mods[$id] = SLS_String::stringToUrl(SLS_String::trimSlashesFromString($value),"",false);						
						if (empty($mods[$id]))
							array_push($errors,"You have to fill the rewrite of the controller '".$mod."'.");
						$modsExisted = $controllerXML->getTags("//controllers/controller/controllerLangs/controllerLang");
						if (in_array($mods[$id],$modsExisted))
							array_push($errors,"The name for rewrite of the controller '".$mod."' is already used, please choose another one.");
					}
					// Actions case
					else if (SLS_String::startsWith($key,"a_"))
					{
						$id = SLS_String::substrBeforeLastDelimiter($key,"_".$lang);
						$smod = array_shift($controllerXML->getTags("//controllers/controller/scontrollers/scontroller[@id='".$id."']/@name"));
						$mod = array_shift($controllerXML->getTags("//controllers/controller[scontrollers/scontroller[@id='".$id."']]/@name"));
						$idC = array_shift($controllerXML->getTags("//controllers/controller[scontrollers/scontroller[@id='".$id."']]/@id"));
						$smods[$id] = SLS_String::stringToUrl(SLS_String::trimSlashesFromString($value),"",false);						
						if (empty($smods[$id]))
							array_push($errors,"You have to fill the rewrite of the action '".$smod."' (controller '".$mod."').");
						$smodsExisted = $controllerXML->getTags("//controllers/controller[@id='".$idC."']/scontrollers/scontroller/scontrollerLangs/scontrollerLang[@lang='".$lang."']");
						if (in_array($smods[$id],$smodsExisted))
							array_push($errors,"The name for rewrite of the action '".$smod."' (controller '".$mod."') is already used by another action of the same controller, please choose another one.");
					}
					// Generics case
					else if (SLS_String::startsWith($key,"generic_"))
					{
						$label = SLS_String::substrAfterFirstDelimiter($key,"generic_");
						if (empty($value))
							array_push($errors,"You have to fill the content of the variable '".$label."'");
						$generics[$label] = strtolower(SLS_String::trimSlashesFromString($value));
					}
				}
				
				// If all cool
				if (empty($errors))
				{
					// controllers.xml
					foreach($mods as $key => $value)
					{
						$str = '<controllerLang lang="'.$lang.'"><![CDATA['.$value.']]></controllerLang>';
						$controllerXML->appendXMLNode("//controllers/controller[@id='".$key."']/controllerLangs",$str);
					}
					foreach($smods as $key => $value)
					{
						$str = '<scontrollerLang lang="'.$lang.'"><![CDATA['.$value.']]></scontrollerLang>';
						$controllerXML->appendXMLNode("//controllers/controller/scontrollers/scontroller[@id='".$key."']/scontrollerLangs",$str);
						
						// metas.xml
						$title = SLS_String::trimSlashesFromString($this->_http->getParam("meta_title-".$key."_".$lang));
						if (empty($title))
							$str = '<title lang="'.$lang.'"/>';
						else 
							$str = '<title lang="'.$lang.'"><![CDATA['.$title.']]></title>';
						$metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str);
						$description = SLS_String::trimSlashesFromString($this->_http->getParam("meta_description-".$key."_".$lang));
						if (empty($description))
							$str = '<description lang="'.$lang.'"/>';
						else 
							$str = '<description lang="'.$lang.'"><![CDATA['.$description.']]></description>';
						$metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str);
						$keyword = SLS_String::trimSlashesFromString($this->_http->getParam("meta_keywords-".$key."_".$lang));
						if (empty($keyword))
							$str = '<keywords lang="'.$lang.'"/>';
						else 
							$str = '<keywords lang="'.$lang.'"><![CDATA['.$keyword.']]></keywords>';
						$metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str);
						// /metas.xml
					}
					$controllerXML->saveXML($this->_generic->getPathConfig("configSecure")."controllers.xml");
					$metaXML->saveXML($this->_generic->getPathConfig("configSls")."metas.xml");
					// /controllers.xml
					
					// site.xml
					$siteXML = $this->_generic->getSiteXML();
					$str = '<name isSecure="false" js="false" active="false"><![CDATA['.$lang.']]></name>';
					$siteXML->appendXMLNode("//configs/langs",$str);
					$siteXML->saveXML($this->_generic->getPathConfig("configSecure")."site.xml");
					// /site.xml
					
					// generic.iso.lang.php
					$fileContent = '<?php'."\n".
								   '/**'."\n".
								   ' * Generic Sls Vars'."\n".
								   ' */'."\n";
					foreach($generics as $key => $value)					
						$fileContent .= '$GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_'.$key.'\'] = "'.str_replace('"','\"',$value).'";'."\n";
					$fileContent .= '?>';
					file_put_contents($this->_generic->getPathConfig("coreGenericLangs")."generic.".$lang.".lang.php",$fileContent);
					// /generic.iso.lang.php
					
					// site.iso.lang.php
					$fileContent =  '<?php'."\n".
									'/**'."\n".
									' * SillySmart Translations'."\n".
									' * Language : '.array_shift($handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[node()='".$lang."']/@iso")).' ('.strtoupper($lang).')'."\n".
									' */'."\n\n".
									'?>';
					file_put_contents($this->_generic->getPathConfig("genericLangs")."site.".$lang.".lang.php",str_replace(array("Translations in '".strtoupper($defaultLang)."'","site.".$defaultLang.".lang.php","sentence in ".strtoupper($defaultLang)),array("Translations in '".strtoupper($lang)."'","site.".$lang.".lang.php","sentence in ".strtoupper($lang)),file_get_contents($this->_generic->getPathConfig("genericLangs")."site.".$defaultLang.".lang.php")));
					// /site.iso.lang.php
										
					// Actions langs files
					$directories = array();
					foreach($mods as $key => $value)					
						array_push($directories,array_shift($controllerXML->getTags("//controllers/controller[@id='".$key."']/@name")));
					$this->copyActionsLang($directories,$lang);
					// /Actions langs files
					
					// User_Bo langs
					$controllerBo = $controllerXML->getTag("//controllers/controller[@side='user' and @isBo='true']/@name");
					if (!empty($controllerBo))
					{
						if (file_exists($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.".$lang.".lang.php"))
							$langContent = str_replace(array("{{USER_BO}}"),array($controllerBo),file_get_contents($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.".$lang.".lang.php"));
						else
							$langContent = str_replace(array("{{USER_BO}}"),array($controllerBo),file_get_contents($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.en.lang.php"));
						if (!empty($langContent))
							file_put_contents($this->_generic->getPathConfig("actionLangs").$controllerBo."/__".$controllerBo.".".$lang.".lang.php",$langContent);
					}
					
					// MySQL multilanguage tables
					$handle = opendir($this->_generic->getPathConfig("models"));
					
					// Disable explain
					SLS_Sql::getInstance()->_explain = false;
					
					// Foreach models 
					while (false !== ($file = readdir($handle))) 
					{
						if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") 
						{
							$fileExploded = explode(".",$file);
							if (is_array($fileExploded) && count($fileExploded) == 4)
							{ 
								$db = $fileExploded[0];
								$class = $fileExploded[1];
								$className = $db."_".$class;
								$this->_generic->useModel($class,$db,"user");
								$object = new $className();								
								if ($object->isMultilanguage())
								{
									$results = $object->searchModels($object->getTable(),array(),array(0=>array("column"=>"pk_lang","value"=>$defaultLang,"mode"=>"equal")));
									
									for($i=0 ; $i<$count=count($results) ; $i++)
									{
										$object = new $className();
										$object->setModelLanguage($lang);
										foreach($results[$i] as $column => $col_value)
										{
											if ($column != "pk_lang" && $column != $object->getPrimaryKey())
											{													
												$object->__set($column,$col_value);
											}
										}
										try {
											$object->create($results[$i]->{$object->getPrimaryKey()});
										}
										catch (Exception $e){}
									}									
								}								
							}
						}
					}
					// /MySQL multilanguage tables
					
					// Redirect
					$controllers = $this->_generic->getTranslatedController("SLS_Bo","Langs");
					$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"].".sls");
				}
				// Else, form errors
				else
				{
					$xml->startTag("errors");
					foreach($errors as $error)
						$xml->addFullTag("error",$error,true);
					$xml->endTag("errors");
				}				
			}
			
			$xml->startTag("generic_langs");
			foreach($generics as $key => $value)
			{
				$xml->startTag("generic_lang");	
				$xml->addFullTag("key",$key,true);
				$xml->addFullTag("value",$value,true);
				$xml->endTag("generic_lang");
			}
			$xml->endTag("generic_langs");
						
			$xml->startTag("controllers");
			for($i=0 ; $i<$count=count($controllers) ; $i++)
			{
				$xml->startTag("controller");
				$xml->addFullTag("id",$controllers[$i]["id"],true);
				$xml->addFullTag("key",$controllers[$i]["key"],true);
				$xml->startTag("values");
				foreach($controllers[$i]["values"] as $key2 => $value2)
				{
					$xml->startTag("value");
					$xml->addFullTag("key",$key2,true);
					$xml->addFullTag("value",$value2,true);
					$xml->endTag("value");
				}
				$xml->endTag("values");
				$xml->startTag("actions");
				for($j=0 ; $j<$count2=count($controllers[$i]["actions"]) ; $j++)
				{
					$action = $controllers[$i]["actions"];
					$xml->startTag("action");
					$xml->addFullTag("id",$action[$j]["id"],true);
					$xml->addFullTag("key",$action[$j]["key"],true);
					$xml->startTag("values");
					foreach($action[$j]["values"] as $key3 => $value3)
					{
						$xml->startTag("value");
						$xml->addFullTag("key",$key3,true);
						$xml->addFullTag("value",$value3,true);
						$xml->endTag("value");
					}
					$xml->endTag("values");
					$xml->startTag("metas");
					foreach($action[$j]["metas"] as $key4 => $value4)
					{
						$xml->startTag("meta");
						$xml->addFullTag("key",$key4,true);
						$xml->startTag("values");
						foreach($value4 as $key5 => $value5)
						{
							$xml->startTag("value");
							$xml->addFullTag("key",$key5,true);
							$xml->addFullTag("value",$value5,true);
							$xml->endTag("value");
						}
						$xml->endTag("values");
						$xml->endTag("meta");
					}
					$xml->endTag("metas");
					$xml->endTag("action");
				}
				$xml->endTag("actions");
				$xml->endTag("controller");
			}
			$xml->endTag("controllers");
		}
		
		$xpathLangs = $handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[@iso != '']");
		foreach ($xpathLangs as $lang)
			if (!in_array(trim($lang), $langs))
				array_push($langs, trim($lang));
		array_multisort($langs, SORT_STRING, SORT_ASC);
		$xml->startTag("langs");
		foreach ($langs as $lang)
			$xml->addFullTag("lang", $lang, true);
		$xml->endTag("langs");
		
		$this->saveXML($xml);
	}	
Ejemplo n.º 19
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$sql = SLS_Sql::getInstance();		
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$errors = array();
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
		$xmlFk = new SLS_XMLToolbox($pathsHandle);
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
		$xmlType = new SLS_XMLToolbox($pathsHandle);
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
		$xmlFilter = new SLS_XMLToolbox($pathsHandle);
		
		// Get the table name
		$table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$column= $this->_http->getParam("column");
		$class = ucfirst($db)."_".SLS_String::tableToClass($table);
		$file  = ucfirst($db).".".SLS_String::tableToClass($table);
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		if ($sql->tableExists($table))
		{
			if ($this->_http->getParam("reload") == "true")
			{
				$columnWanted = $this->_http->getParam("column");
				$typeWanted = $this->_http->getParam("type");
				
				$result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']");
				
				// If an entry already exists in the XML, delete this record
				if (!empty($result))
				{
					$xmlTmp = $xmlType->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']");					
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlTmp);
					$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
					$xmlType = new SLS_XMLToolbox($pathsHandle);
				}
								
				// If file type, check possible thumbs
				if ($typeWanted == "file")
				{
					$typeFile = $this->_http->getParam("file");
					$file_thumb = $this->_http->getParam("file_thumb");
					$multilang = $this->_http->getParam("multilanguage");
					$thumbs = array();
										
					$typeWanted = $typeWanted."_".$typeFile;
					
					if ($typeFile == "img" && !empty($file_thumb))
					{
						for($i=0 ; $i<10 ; $i++)
						{
							$width = $this->_http->getParam("width".$i);
							$height = $this->_http->getParam("height".$i);
							$suffix = $this->_http->getParam("suffix".$i);
							
							if (!empty($suffix) && (!empty($width) || !empty($height)))
								array_push($thumbs,array('width' => $width, 'height' => $height, 'suffix' => $suffix));
						}
					}
					
					$rules = "*|*|*";
					if ($typeFile == "img")
					{
						$settings = $this->_http->getParam("imgSettings");
						$ratio = str_replace(",",".",$settings["ratio"]);
						$minWidth = str_replace(",",".",$settings["min-width"]);
						$minHeight = str_replace(",",".",$settings["min-height"]);
						$ratio = (!is_numeric($ratio) || (is_numeric($ratio) && $ratio <= 0)) ? "*" : round($ratio,2);
						$minWidth = (!is_numeric($minWidth) || (is_numeric($minWidth) && $minWidth < 0)) ? "*" : round($minWidth,0);
						$minHeight = (!is_numeric($minHeight) || (is_numeric($minHeight) && $minHeight < 0)) ? "*" : round($minHeight,0);
						$rules = $ratio."|".$minWidth."|".$minHeight;
					}
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$rules.'" thumbs="'.str_replace('"','||#||',serialize($thumbs)).'" multilanguage="'.$multilang.'" type="'.$typeWanted.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				else if ($typeWanted == "ip")
				{
					$type = $this->_http->getParam("ip");
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				else if ($typeWanted == "complexity")
				{
					$complexity = $this->_http->getParam("complexity");
					$complexityMin = $this->_http->getParam("complexity_min");					
					$complexity = (empty($complexity)) ? array() : $complexity;
					if (!empty($complexityMin) && is_numeric($complexityMin) && $complexityMin >= 0)
						$complexity[] = "min".$complexityMin;
					$complexity = implode("|",$complexity);
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$complexity.'" type="complexity" />';			
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());					
				}			
				else if ($typeWanted == "num")
				{
					$type = $this->_http->getParam("num");
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				// Else, it's email, url
				else
				{
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted.'" />';				
					$xmlType->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML());
				}
				
				// Update Model
				$fileName  = ucfirst($db).".".SLS_String::tableToClass($table).".model.php";
				$contentM = $this->getModelSource($table,$db);
				file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM);
				
				$controllers = $this->_generic->getTranslatedController("SLS_Bo","EditModel");
				$this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']."/name/".$db."_".$table);			
			}
			
			// Get generic object
			$this->_generic->useModel($table,$db,"user");
			$object = new $class();
			
			// Get current entry
			$attributes = array_shift($xmlType->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$column."']",array("type","thumbs","multilanguage","hash","rules")));					
						
			// Get object's infos			
			$columnsP = $object->getParams();
			$pk = $object->getPrimaryKey();
			$multilanguage = $object->isMultilanguage();		
			$xml->startTag("model");
			$xml->addFullTag("table",$table,true);
			$xml->addFullTag("db",$db,true);
			$xml->addFullTag("class",$class,true);
			$xml->addFullTag("pk",$pk,true);
			$xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true);
			$xml->addFullTag("column",$column,true);
			$xml->addFullTag("type",$attributes["attributes"][0]["value"],true);			
			$xml->startTag("thumbs");
			$thumbs = unserialize(str_replace("||#||",'"',$attributes["attributes"][1]["value"]));
			if (!empty($thumbs))
            {
	            for($i=0 ; $i<$count=count($thumbs) ; $i++)
	            {
	            	$xml->startTag("thumb");
	            	$xml->addFullTag("width",$thumbs[$i]["width"],true);
	            	$xml->addFullTag("height",$thumbs[$i]["height"],true);
	            	$xml->addFullTag("suffix",$thumbs[$i]["suffix"],true);	            	
	            	$xml->endTag("thumb");
	            }
            }
			$xml->endTag("thumbs");
			$xml->addFullTag("multilanguage",($attributes["attributes"][2]["value"] == "true") ? "true" : "false",true);
			$xml->addFullTag("hash",$attributes["attributes"][3]["value"],true);
			$xml->addFullTag("rules",$attributes["attributes"][4]["value"],true);
			$xml->endTag("model");
			
			$plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml"));
			$pluginImg = array_shift($plugin->getTags("//plugins/plugin[@code='image']"));
			$xml->addFullTag("plugin_img",empty($pluginImg) ? 'false' : 'true',true);
			$xml->addFullTag("plugin_url",$this->_generic->getFullPath("SLS_Bo","Plugins"),true);
		}
		else
		{
			$xml->addFullTag("error","Sorry this table doesn't exist anymore",true);
		} 
		
		$this->saveXML($xml);
	}
Ejemplo n.º 20
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$sql = SLS_Sql::getInstance();
		$dbs = $sql->getDbs();
		$results = array();
		$error = "";
		$success = "";
		
		$xml->startTag("dbs");
		foreach($dbs as $db)
			$xml->addFullTag("db",$db,true);
		$xml->endTag("dbs");		
		
		if ($this->_http->getParam("reload") == "true")
		{
			$db = $this->_http->getParam("db");
			$query = trim(SLS_String::trimSlashesFromString($this->_http->getParam("query")));
			
			$sql->changeDb($db);
			
			switch($query)
			{
				case (SLS_String::startsWith(strtolower($query),"select") || 
					  SLS_String::startsWith(strtolower($query),"show") ||
					  SLS_String::startsWith(strtolower($query),"explain") ||
					  SLS_String::startsWith(strtolower($query),"describe")):					
					$results = $sql->select($query);
					if ($results !== false)
						$success = count($results)." row(s) selected";
					break;
				case (SLS_String::startsWith(strtolower($query),"insert")):
					$results = $sql->exec($query);
					if ($results !== false)
						$success = $results." row(s) inserted";
					break;
				case (SLS_String::startsWith(strtolower($query),"update")):
					$results = $sql->update($query);
					if ($results !== false)
						$success = $results." row(s) updated";
					break;
				case (SLS_String::startsWith(strtolower($query),"delete")):
					$results = $sql->delete($query);
					if ($results !== false)
						$success = $results." row(s) deleted";
					break;
				default:
					$results = $sql->query($query);
					if ($results !== false)
						$success = $results;
					break;
			}
			
			if (!empty($success))
				$xml->addFullTag("success",$success,true);
			if ($results === false)
				$xml->addFullTag("error","SQL syntax error",true);
			else if (!empty($results) && is_array($results))
			{
				$xml->startTag("legends");
				foreach($results[0] as $key => $value)
					$xml->addFullTag("legend",strtolower($key),true);
				$xml->endTag("legends");
				
				$xml->startTag("results");
				for($i=0 ; $i<$count=count($results) ; $i++)
				{
					$xml->startTag("result");
					foreach($results[$i] as $key => $value)
						$xml->addFullTag(strtolower($key),$value,true);
					$xml->endTag("result");
				}
				$xml->endTag("results");
			}
			
			$xml->addFullTag("query",$query,true);
		}
		
		$this->saveXML($xml);
	}
Ejemplo n.º 21
0
	/**
	 * Constructor
	 * 
	 * @access public
	 * @since 1.0.7
	 */
	public function __construct() 
	{
		$this->_db = SLS_Sql::getInstance();
		$this->_expr = new SLS_ExprBuilder();
	}
Ejemplo n.º 22
0
	public function deleteQuery($queryId)
	{
		$sql = new SLS_Sql();
		$req = '
			DELETE
			        gq,
			        gqc,
			        gqj,
			        gqw,
			        gqg,
			        gqo,
			        gql
			FROM
			        sls_graph_query gq LEFT JOIN
			        sls_graph_query_column gqc ON (gq.sls_graph_query_id = gqc.sls_graph_query_id) LEFT JOIN
			        sls_graph_query_join gqj ON (gq.sls_graph_query_id = gqj.sls_graph_query_id) LEFT JOIN
			        sls_graph_query_where gqw ON (gq.sls_graph_query_id = gqw.sls_graph_query_id) LEFT JOIN
			        sls_graph_query_group gqg ON (gq.sls_graph_query_id = gqg.sls_graph_query_id) LEFT JOIN
			        sls_graph_query_order gqo ON (gq.sls_graph_query_id = gqo.sls_graph_query_id) LEFT JOIN
			        sls_graph_query_limit gql ON (gq.sls_graph_query_id = gql.sls_graph_query_id)
			WHERE
			        gq.sls_graph_query_id = '.$queryId;
		$sql->delete($req);
	}
Ejemplo n.º 23
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$sql = SLS_Sql::getInstance();		
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$errors = array();
		
		// Get the table 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);
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		if ($sql->tableExists($table))
		{
			if ($this->_http->getParam("reload") == "true")
			{
				$columnWanted = $this->_http->getParam("column");
				$filterWanted = $this->_http->getParam("filter");
				
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
				$xmlFk = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
				$xmlType = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
				$xmlFilter = new SLS_XMLToolbox($pathsHandle);
				
				$result = $xmlFilter->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."' and @filter='".$filterWanted."']");
				
				// If an entry already exists in the XML, delete this record
				if (!empty($result))
				{
					$xmlTmp = $xmlFilter->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."' and @filter='".$filterWanted."']");					
					$xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlTmp);
					$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
					$xmlFilter = new SLS_XMLToolbox($pathsHandle);
				}
				
				if ($filterWanted == "hash")
				{
					$passwordHash = $this->_http->getParam("hash");
					
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" hash="'.$passwordHash.'" filter="'.$filterWanted.'" />';				
					$xmlFilter->appendXMLNode("//sls_configs",$xmlNode);
					$xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlFilter->getXML());
				}				
				else
				{
					// Save it into the XML
					$xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" filter="'.$filterWanted.'" />';				
					$xmlFilter->appendXMLNode("//sls_configs",$xmlNode); 
					$xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlFilter->getXML());
				}
				
				// Update model
				$this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));		
			}
			
			// Get generic object
			$this->_generic->useModel($table,$db,"user");
			$object = new $class();
			
			// Get object's infos
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
			$xmlFk = new SLS_XMLToolbox($pathsHandle);
			$columnsP = $object->getParams();
			$pk = $object->getPrimaryKey();
			$multilanguage = $object->isMultilanguage();		
			$xml->startTag("model");
			$xml->addFullTag("table",$table,true);
			$xml->addFullTag("db",$db,true);
			$xml->addFullTag("class",$class,true);
			$xml->addFullTag("pk",$pk,true);
			$xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true);
			$xml->startTag("columns");
			foreach($columnsP as $column => $value)
			{
				$res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk");				
				if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res))			
					$xml->addFullTag("column",$column,true);
			}
			$xml->endTag("columns");
			$xml->endTag("model");
		}
		else
		{
			$xml->addFullTag("error","Sorry this table doesn't exist anymore",true);
		}
		
		$this->saveXML($xml);
	}
Ejemplo n.º 24
0
	/**
	 * Constructor
	 * 
	 * @access public
	 * @since 1.0.7
	 */
	public function __construct() 
	{
		$this->_db = SLS_Sql::getInstance();
	}
	public function action()
	{
		set_time_limit(0);
		
		$user = $this->hasAuthorative();
		$errors = array();
		$sql = SLS_Sql::getInstance();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);

		// Get all models
		$models = array();
		$handle = opendir($this->_generic->getPathConfig("models"));
		while (false !== ($file = readdir($handle)))
		{
			if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") 
			{
				$modelExploded = explode(".",$file);
				array_push($models,strtolower($modelExploded[0]).".".$modelExploded[1]);
			}
		}
		
		// If reload
		if ($this->_http->getParam("reload")=="true")
		{
			// Get the tables dude wants to generate
			$tablesG = ($this->_http->getParam("tables")=="") ? array() : $this->_http->getParam("tables");
			
			// Foreach tables, generate model
			foreach($tablesG as $tableG)
			{
				$db = Sls_String::substrBeforeFirstDelimiter($tableG,".");
				$table = Sls_String::substrAfterFirstDelimiter($tableG,".");
				
				// Change db if it's required
				if ($sql->getCurrentDb() != $db)
					$sql->changeDb($db);
				
				// If table exists
				if ($sql->tableExists($table))
				{					
					$columns = $sql->showColumns($table);
					$tableName = $table;
					$currentTable = array("table"=>$db.".".$tableName,"errors"=>array());
					$fieldsOk = true;
					$className = ucfirst($db)."_".SLS_String::tableToClass($tableName);
					$fileName  = ucfirst($db).".".SLS_String::tableToClass($table).".model.php";					
															
					for($i=0 ; $i<$count=count($columns) ; $i++)
					{						
						// Check forbidden chars
						if (SLS_String::removePhpChars($columns[$i]->Field) != $columns[$i]->Field)
						{
							$error = array("column"=>$columns[$i]->Field,"column_clean"=>SLS_String::removePhpChars($columns[$i]->Field));
							array_push($currentTable["errors"],$error);
							$fieldsOk = false;
						}
					}
					
					// If all ok with special chars for the current model
					if ($fieldsOk)
					{
						// Check real fks
						$create = array_shift($sql->select("SHOW CREATE TABLE `".$table."`"));						
						$queries = array_map("trim",explode("\n",$create->{Create." ".Table}));						
						foreach($queries as $query)
						{
							if (SLS_String::startsWith($query,"CONSTRAINT"))
							{
								$tableFk = strtolower($db."_".$tableName);
								$columnFk = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"FOREIGN KEY (`"),"`)");
								$tablePk = $db."_".SLS_String::tableToClass(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`"));
								$onDelete = strtolower(SLS_String::stringToUrl(trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"ON DELETE"),"ON UPDATE")),"_"));
								$labelPk = "";
								$columns = $sql->showColumns(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`"));
								for($i=0 ; $i<$count=count($columns) ; $i++)
								{
									if ($columns[$i]->Key != "PRI" && $columns[$i]->Field != "pk_lang" && SLS_String::contains($columns[$i]->Type,"char"))
									{
										$labelPk = $columns[$i]->Field;
										break;
									}
								}
								if (empty($labelPk))
									$labelPk = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `".SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`")."` (`"),"`)");
								$xmlNode = '<entry tableFk="'.$tableFk.'" columnFk="'.$columnFk.'" multilanguage="false" ondelete="'.$onDelete.'" labelPk="'.$labelPk.'" tablePk="'.$tablePk.'" />';
								
								$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
								$result = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$tableFk."' and @columnFk='".$columnFk."' and @tablePk='".$tablePk."']");
								if (!empty($result))
								{
									$xmlTmp = $xmlFk->deleteTags("//sls_configs/entry[@tableFk='".$tableFk."' and @columnFk='".$columnFk."' and @tablePk='".$tablePk."']");
									$xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlTmp);
									$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
								}
								
								$xmlFk->appendXMLNode("//sls_configs",$xmlNode);
								$xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlFk->getXML());
							}
						}
						
						// Generate Model						
						$contentM = $this->getModelSource($tableName,$db);						
						$status = touch($this->_generic->getPathConfig("models")."/".$fileName);
						if ($status)					
							file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM);
						
						// Create SQL
						$fileNameS = ucfirst($db).".".SLS_String::tableToClass($table).".sql.php";
						$contentS = '<?php'."\n".
								   '/**'."\n".
								   '* Object '.$className.'Sql'."\n".
								   '* @author SillySmart'."\n".
								   '* @copyright SillySmart'."\n".
								   '* @package Mvc.Models.Objects'."\n".
								   '* @see Sls.Models.Core.SLS_FrontModel'."\n".
								   '* @since 1.0'."\n".
								   '*/'."\n".
								   'class '.$className.'Sql extends SLS_FrontModelSql'."\n".
								   '{'."\n".
								   ''."\n".
								   '}'."\n".
								   '?>';
						if ($status)
							$status2 = touch($this->_generic->getPathConfig("modelsSql")."/".$fileNameS);
						if ($status2)					
							file_put_contents($this->_generic->getPathConfig("modelsSql")."/".$fileNameS,$contentS);					 
					}
					else					
						array_push($errors,$currentTable);					
				}
			}
			// If no errors
			if (empty($errors))
			{
				$controllers = $this->_generic->getTranslatedController("SLS_Bo","Models");
				$this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']);
			}
			else
			{	
				// Get all models
				$models = array();
				$handle = opendir($this->_generic->getPathConfig("models"));
				while (false !== ($file = readdir($handle))) 			
					if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") 
					{
						$modelExploded = explode(".",$file);
						array_push($models,strtolower($modelExploded[0]).".".$modelExploded[1]);
					}
					
				// Form errors
				$xml->startTag("errors");
				for($i=0 ; $i<$count=count($errors) ; $i++)
				{
					$xml->startTag("error");
					$xml->addFullTag("table",SLS_String::substrAfterFirstDelimiter($errors[$i]["table"],"."),true);
					$xml->addFullTag("db",SLS_String::substrBeforeFirstDelimiter($errors[$i]["table"],"."),true);
					$xml->startTag("columns");
					for($j=0 ; $j<$count2=count($errors[$i]["errors"]) ; $j++)
					{
						$xml->startTag("column");
						$xml->addFullTag("old",$errors[$i]["errors"][$j]["column"],true);
						$xml->addFullTag("new",$errors[$i]["errors"][$j]["column_clean"],true);
						$xml->endTag("column");
					}
					$xml->endTag("columns");
					$xml->endTag("error");
				}
				$xml->endTag("errors");				
			}
		}
		
		// Foreach db
		$dbs = $sql->getDbs();
		$allDbs = array();	
		
		foreach($dbs as $db)
		{
			$allDbs[$db] = array();
			
			// Change db
			$sql->changeDb($db);
			
			// Get all tables
			$tables = $sql->showTables();						
			for($i=0 ; $i<$count=count($tables) ; $i++)
			{
				$allDbs[$db][$tables[$i]->Name] = array("name" 	=> $tables[$i]->Name,
														"existed" => (in_array($db.".".SLS_String::tableToClass($tables[$i]->Name),$models)) ? 'true' : 'false');				
			}
		}
		
		asort($allDbs,SORT_REGULAR);
		uksort($allDbs,array($this, 'unshiftDefaultDb'));
		
		$xml->startTag("dbs");
		foreach($allDbs as $key => $db)
		{
			asort($db,SORT_REGULAR);
			
			$xml->startTag("db");
			$xml->addFullTag("name",$key,true);
			$xml->startTag("tables");
			foreach($db as $tableCur)
			{
				if (!SLS_String::startsWith(strtolower($tableCur["name"]),"sls_graph"))
				{
					$xml->startTag("table");				
					$xml->addFullTag("name",$tableCur["name"]);
					$xml->addFullTag("existed",$tableCur["existed"]);
					$xml->endTag("table");
				}
			}
			$xml->endTag("tables");
			$xml->endTag("db");
		}
		$xml->endTag("dbs");
			
		$this->saveXML($xml);
	}
Ejemplo n.º 26
0
	/**
	 * Action Home
	 *
	 */
	public function action() 
	{
		$this->secureURL();
		$this->_generic->registerLink('DataBase', 'SLS_Init', 'DataBase');
		$step = 0;
		$xml = $this->getXML();
		$errors = array();
		$mysqlCharsets = array("armscii8","ascii","big5","binary","cp1250","cp1251","cp1256","cp1257","cp850","cp852","cp866","cp932","dec8","eucjpms","euckr","gb2312","gbk","geostd8","greek","hebrew","hp8","keybcs2","koi8u","koi8r","latin1","latin2","latin5","latin7","macce","macroman","sjis","swe7","tis620","ucs2","ujis","utf8");
		
		if ($this->_http->getParam("database_reload") == "1")
		{
			$useSql = $this->_http->getParam("database_useSql");
			if (empty($useSql))
				array_push($errors, "Will you need MySQL connection?");
			else
			{
				if ($this->_http->getParam("database_useSql") == "false")
				{
					$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"MailSettings",1=>"MailSettings"));
					return $this->_generic->dispatch("SLS_Init", "MailSettings");	
				}
				else
				{
					$step = 1;
					$nbDbs = $this->_http->getParam("nb_databases");
					if (empty($nbDbs) || !is_numeric($nbDbs) || $nbDbs <= 0)
						$nbDbs = 1;
					$xml->startTag("nb_databases");
					for($i=0 ; $i<$nbDbs ; $i++)
						$xml->addFullTag("nb_database","",true);
					$xml->endTag("nb_databases");
				}
			}
		}
		elseif ($this->_http->getParam("database_reload") == "2")
		{
			$nb_databases = SLS_String::trimSlashesFromString($this->_http->getParam("nb_databases"));
			if (empty($nb_databases) || !is_numeric($nb_databases) || $nb_databases <= 0)
				$nb_databases = 1;
			$xml->startTag("nb_databases");
			for($i=0 ; $i<$nb_databases ; $i++)
				$xml->addFullTag("nb_database","",true);
			$xml->endTag("nb_databases");
			$nicks_used = array();
			
			for($i=1 ; $i<=$nb_databases ; $i++)
			{
				$nick_{$i} 		= strtolower(SLS_String::tableToClass(SLS_String::trimSlashesFromString($this->_http->getParam("database_alias_".$i))));
				$charset_{$i} 	= SLS_String::trimSlashesFromString($this->_http->getParam("database_charset_".$i));
				$host_{$i} 		= SLS_String::trimSlashesFromString($this->_http->getParam("database_host_".$i));			
				$name_{$i} 		= SLS_String::trimSlashesFromString($this->_http->getParam("database_name_".$i));
				$user_{$i} 		= SLS_String::trimSlashesFromString($this->_http->getParam("database_user_".$i));
				$pass_{$i} 		= SLS_String::trimSlashesFromString($this->_http->getParam("database_pass_".$i));
				$no_p_{$i} 		= SLS_String::trimSlashesFromString($this->_http->getParam("database_no_pass_".$i));
				
				if (empty($charset_{$i}) || !in_array($charset_{$i},$mysqlCharsets))
					array_push($errors, "You have to fill the charset for the database n°".$i);
				if (empty($nick_{$i}))
					array_push($errors, "You have to fill the database alias for the database n°".$i);
				else if (in_array($nick_{$i},$nicks_used))
					array_push($errors, "The database alias must be unique");
				else
					array_push($nicks_used,$nick_{$i});
					
				if (empty($host_{$i}))
					array_push($errors, "You have to fill the database host for the database n°".$i);
				if (empty($name_{$i}))
					array_push($errors, "You have to fill the database name for the database n°".$i);
				if (empty($user_{$i}))
					array_push($errors, "You have to fill the database username for the database n°".$i);
				if (empty($no_p_{$i}) && empty($pass_{$i}))
					array_push($errors, "You have to fill the database password or to check 'No password' for the database n°".$i);
			}
			
			// Ping
			if ($this->_http->getParam("ping") == "true")
			{
				$sql = SLS_Sql::getInstance();
				$errorsP = array();
				for($i=1 ; $i<=$nb_databases ; $i++)
				{					
					$verdict = $sql->pingConnection($host_{$i},$name_{$i},$user_{$i},(empty($no_p_{$i}) ? $pass_{$i} : ""));					
					if ($verdict === true)
						array_push($errorsP,'<li style="color:green;"><u>Database n°'.$i.':</u><br />Connection successfull</li>');
					if ($verdict !== true)
						array_push($errorsP,'<li style="color:red;"><u>Database n°'.$i.':</u><br />Connection failed with message `'.$verdict.'`</li>');
				}				
				$xml->addFullTag("ping",(empty($errorsP)) ? "true" : "false",true);
				$xml->startTag("ping_msgs");
				foreach($errorsP as $errorP)
					$xml->addFullTag("ping_msg",$errorP,true);
				$xml->endTag("ping_msgs");
			}
			
			// If it have errors
			//if (!empty($errors))
			//{
				$xml->startTag("dbs");
				for($i=1 ; $i<=$nb_databases ; $i++)
				{
					$xml->startTag("db_".$i);
					$xml->addFullTag("alias",$nick_{$i},true);
					$xml->addFullTag("charset",$charset_{$i},true);
					$xml->addFullTag("host",$host_{$i},true);
					$xml->addFullTag("name",$name_{$i},true);
					$xml->addFullTag("user",$user_{$i},true);
					$xml->addFullTag("pass",$pass_{$i},true);
					$xml->addFullTag("no_pass",(empty($no_p_{$i}))?"false":"true",true);
					$xml->endTag("db_".$i);
				}
				$xml->endTag("dbs");
			//}
			// Good, we can save it!
			if (empty($errors)  && $this->_http->getParam("ping") != "true")
			{
				$dbXml 		= $this->_generic->getDbXML();
				$str_xml 	= "";
				for($i=1 ; $i<=$nb_databases ; $i++)
				{
					$default = ($i==1) ? 'true' : 'false';
					
					$host_{$i} = SLS_Security::getInstance()->encrypt($host_{$i},$this->_generic->getSiteConfig("privateKey"));
					$name_{$i} = SLS_Security::getInstance()->encrypt($name_{$i},$this->_generic->getSiteConfig("privateKey"));
					$user_{$i} = SLS_Security::getInstance()->encrypt($user_{$i},$this->_generic->getSiteConfig("privateKey"));
					$pass_{$i} = (empty($no_p_{$i})) ? SLS_Security::getInstance()->encrypt($pass_{$i},$this->_generic->getSiteConfig("privateKey")) : "";
					
					$str_xml .= '<db alias="'.$nick_{$i}.'" isDefault="'.$default.'" isSecure="true" js="false" charset="'.$charset_{$i}.'">'.
									'<host><![CDATA['.$host_{$i}.']]></host>'.
									'<base><![CDATA['.$name_{$i}.']]></base>'.
									'<user><![CDATA['.$user_{$i}.']]></user>'.
									'<pass><![CDATA['.$pass_{$i}.']]></pass>'.
								'</db>';
				}
				$dbXml->appendXMLNode("//dbs",$str_xml);
				$dbXml->saveXML($this->_generic->getPathConfig("configSecure")."db.xml");
				$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"MailSettings",1=>"MailSettings"));
				
				// If old sls_graph_* exists
				$sql = SLS_Sql::getInstance();
				$graphTables = array("sls_graph",
									 "sls_graph_query",
									 "sls_graph_query_column",
									 "sls_graph_query_group",
									 "sls_graph_query_join",
									 "sls_graph_query_limit",
									 "sls_graph_query_order",
									 "sls_graph_query_where");
				foreach($graphTables as $graphTable)
				{
					try 
					{
						if ($sql->tableExists($graphTable))
							$sql->exec("DROP TABLE `".$graphTable."`");
					}
					catch (Exception $e)
					{
						continue;
					}
				}
				return $this->_generic->dispatch("SLS_Init", "MailSettings");
			}			
			$step = 1;
		}
		
		if (!empty($errors) && $this->_http->getParam("database_reload") == "1" || ( !empty($errors) && $this->_http->getParam("ping") != "true"))
		{
			$xml->startTag("errors");
			foreach($errors as $error)
				$xml->addFullTag("error", $error, true);
			$xml->endTag("errors");
		}
		$xml->addFullTag("step", $step, true);
		$xml->startTag("charsets");
		foreach($mysqlCharsets as $key => $value)
			$xml->addFullTag("charset",$value,true);
		$xml->endTag("charsets");
		$this->saveXML($xml);
	}
Ejemplo n.º 27
0
	public function action() 
	{		
		// Objects
		$xml = $this->getXML();
		$user = $this->hasAuthorative();
		$xml = $this->makeMenu($xml);
		$this->_generic->registerLink('Generate', 'SLS_Bo', 'GenerateBo');
		$this->_generic->registerLink('Translation', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "Boi18n"));
		$this->_generic->registerLink('FileUpload', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoFileUpload"));
		$this->_generic->registerLink('ManageAdmin', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoUserList|BoUserAdd|BoUserDelete|BoUserModify|BoUserStatus"));
		$this->_generic->registerLink('ProjectSettings', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoProjectSettings"));
		$this->_generic->registerLink('Manage_Rights', 'SLS_Bo', 'ManageRights');
		$this->_generic->registerLink('Manage_BoMenu', 'SLS_Bo', 'BoMenu');
		$xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteBo",array(),false));
		$xml->addFullTag("edit",$this->_generic->getFullPath("SLS_Bo","EditBo",array(),false));
		$this->_xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
		$bos = array();
		
		// Search for user back-office
		$controllersXML = $this->_generic->getControllersXML();
		$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));
		if (!empty($controller))
		{
			$models = $this->getAllModels();			
			for($i=0 ; $i<$count=count($models) ; $i++)
			{
				$model 	= SLS_String::substrAfterFirstDelimiter($models[$i],".");
				$db 	= SLS_String::substrBeforeFirstDelimiter($models[$i],".");
				if ($this->boActionExist($model,$db))
				{
					$this->_generic->useModel($model,$db,"user");
					$class = ucfirst($db)."_".SLS_String::tableToClass($model);
					$object = new $class();
					$bos[$class] = array("db" 			=> $db,
									 	 "className" 	=> $class,
									 	 "tableName" 	=> $object->getTable(),											 	
									 	 "nb_actions" 	=> count($this->getActionsBo($model,$db)));
				}
			}	
		}		
		
		asort($bos,SORT_REGULAR);
		
		$xml->startTag("bos");
		foreach($bos as $bo)
		{
			$categoryExists = $this->_xmlBo->getTag("//sls_configs/entry[@type='category' and entry[@type='table' and @name='".strtolower($bo["db"]."_".$bo["tableName"])."']]/@name");
			
			$xml->startTag("bo");
			$xml->addFullTag("db",strtolower($bo["db"]),true);
			$xml->addFullTag("class",$bo["className"],true);
			$xml->addFullTag("table",$bo["tableName"],true);
			$xml->addFullTag("category",(empty($categoryExists)) ? "X" : $categoryExists,true);
			$xml->addFullTag("nb_actions",$bo["nb_actions"],true);
			$xml->endTag("bo");
		}
		$xml->endTag("bos");		
		
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");
		$xmlRights = new SLS_XMLToolbox($pathsHandle);
		$result = $xmlRights->getTags("//sls_configs/entry");
		$xml->addFullTag("admins_exist",(!empty($result)) ? "true" : "false",true);
		
		$xml->startTag("actions");
		$action = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Boi18n']"));
		$action2 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoFileUpload']"));
		$action3 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoUserList']"));
		$action4 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoProjectSettings']"));
		$xml->startTag("action");
			$xml->addFullTag("name","Translation",true);
			$xml->addFullTag("icon","boi18n16.png",true);
			$xml->addFullTag("existed",(!empty($action)) ? "true" : "false",true);
		$xml->endTag("action");
		$xml->startTag("action");
			$xml->addFullTag("name","FileUpload",true);
			$xml->addFullTag("icon","boupload16.png",true);
			$xml->addFullTag("existed",(!empty($action2)) ? "true" : "false",true);
		$xml->endTag("action");
		$xml->startTag("action");
			$xml->addFullTag("name","ManageAdmin",true);
			$xml->addFullTag("icon","boadmin16.png",true);
			$xml->addFullTag("existed",(!empty($action3)) ? "true" : "false",true);
		$xml->endTag("action");
		$xml->startTag("action");
			$xml->addFullTag("name","ProjectSettings",true);
			$xml->addFullTag("icon","bosettings16.png",true);
			$xml->addFullTag("existed",(!empty($action4)) ? "true" : "false",true);
		$xml->endTag("action");
		$xml->endTag("actions");
		if (SLS_Sql::getInstance()->tableExists("sls_graph"))
		{
			$this->_generic->useModel("Sls_graph",$this->defaultDb,"sls");
			$className = ucfirst($this->defaultDb)."_Sls_graph";
			$slsGraph = new $className;
			$nbGraph = $slsGraph->countModels("sls_graph");
		}
		else
			$nbGraph = 0;
		$xml->addFullTag("nb_reporting",$nbGraph,true);
		$xml->addFullTag("url_reporting",$this->_generic->getFullPath("SLS_Bo","ReportingBo"),true);
		
		$this->saveXML($xml);
	}
	public function action()
	{
		$user = $this->hasAuthorative();
		$sql = SLS_Sql::getInstance();
		
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$errors = array();
		
		// Get the table name
		$table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$column= $this->_http->getParam("column");		
		$class = ucfirst($db)."_".SLS_String::tableToClass($table);
		$file  = ucfirst($db).".".SLS_String::tableToClass($table);
		
		// If current db is not this one
		if ($sql->getCurrentDb() != $db)
			$sql->changeDb($db);
		
		if ($sql->tableExists($table))
		{
			if ($this->_http->getParam("reload") == "true")
			{
				$replacements = array('&amp;','&gt;','&lt;','&#61;','"',"'");
				$masks = array('&','>','<','=','','','');
				
				$columnWanted 	= $this->_http->getParam("column");
				$tableWanted 	= $this->_http->getParam("table");
				$labelWanted 	= $this->_http->getParam($tableWanted.'_fkLabel');
				$labelSpecified = SLS_String::trimSlashesFromString($this->_http->getParam("fkLabel_specified"));				
				$multilang 		= $this->_http->getParam("multilanguage");
				$onDelete 		= $this->_http->getParam("ondelete");
								
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
				$xmlFk = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
				$xmlType = new SLS_XMLToolbox($pathsHandle);
				$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
				$xmlFilter = new SLS_XMLToolbox($pathsHandle);
				if (!empty($labelSpecified))
					$labelSpecified = str_replace(array('='),array('&#61;'),htmlentities(strtolower($labelSpecified),ENT_QUOTES,"UTF-8"));				
				$result = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$columnWanted."' and @tablePk='".$tableWanted."']");
				
				// If an entry already exists in the XML, delete this record
				if (!empty($result))
				{
					$xmlTmp = $xmlFk->deleteTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$columnWanted."' and @tablePk='".$tableWanted."']");					
					$xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlTmp);
					$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
					$xmlFk = new SLS_XMLToolbox($pathsHandle);
				}
				
				// Save it into the XML
				$xmlNode = '<entry tableFk="'.$db."_".$table.'" columnFk="'.$columnWanted.'" multilanguage="'.$multilang.'" ondelete="'.$onDelete.'" labelPk="'.(empty($labelSpecified) ? $labelWanted : $labelSpecified).'" tablePk="'.$tableWanted.'" />';					
				$xmlFk->appendXMLNode("//sls_configs",$xmlNode);
				$xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlFk->getXML());
				
				// Update model
				$this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));
			}
			
			// Get generic object
			$this->_generic->useModel(SLS_String::tableToClass($table),$db,"user");
			$object = new $class();
			
			// Get object's infos
			$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
			$xmlFk = new SLS_XMLToolbox($pathsHandle);
			$columnsP = $object->getParams();
			$pk = $object->getPrimaryKey();
			$multilanguage = $object->isMultilanguage();		
			$xml->startTag("model");
			$xml->addFullTag("table",$table,true);
			$xml->addFullTag("db",$db,true);
			$xml->addFullTag("class",$class,true);
			$xml->addFullTag("pk",$pk,true);
			$xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true);
			$xml->startTag("columns");
			foreach($columnsP as $key => $value)
			{							
				if ($object->getPrimaryKey() != $key && $key != "pk_lang")			
					$xml->addFullTag("column",$key,true);
			}
			$xml->endTag("columns");
						
			$attributes = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($db."_".$table)."' and @ columnFk='".$column."']",array("multilanguage","labelPk","tablePk","ondelete")));
			$this->_generic->useModel(SLS_String::substrAfterFirstDelimiter($attributes["attributes"][2]["value"],"_"),ucfirst(SLS_String::substrBeforeFirstDelimiter($attributes["attributes"][2]["value"],"_")),"user");
			$className = ucfirst($attributes["attributes"][2]["value"]);
			$objectN = new $className();
			$columns = $objectN->getColumns();
			$specificPattern = true;
			foreach($columns as $key)
				if ($key == $attributes["attributes"][1]["value"])
					$specificPattern = false;
			
			$xml->startTag("current_values");
				$xml->addFullTag("tableFk",$db."_".SLS_String::tableToClass($table),true);
				$xml->addFullTag("columnFk",$column,true);
				$xml->addFullTag("multilanguage",$attributes["attributes"][0]["value"],true);
				$xml->addFullTag("labelPk",$attributes["attributes"][1]["value"],true);
				$xml->addFullTag("tablePk",$attributes["attributes"][2]["value"],true);
				$xml->addFullTag("ondelete",$attributes["attributes"][3]["value"],true);
				$xml->addFullTag("specific_pattern",($specificPattern) ? "true" : "false",true);
			$xml->endTag("current_values");
			
			$tables = $this->getAllModels();
			
			sort($tables,SORT_REGULAR);			
				
			$xml->startTag("tables");			
			for($i=0 ; $i<$count=count($tables) ; $i++)
			{
				if (SLS_String::startsWith($tables[$i],$db))
				{
					$xml->startTag("table");
					$xml->addFullTag("name",SLS_String::substrAfterFirstDelimiter($tables[$i],"."));
					$xml->addFullTag("db",SLS_String::substrBeforeFirstDelimiter($tables[$i],"."));
					$tableN = SLS_String::substrAfterFirstDelimiter($tables[$i],".");
					$dbN = SLS_String::substrBeforeFirstDelimiter($tables[$i],".");
					$classN = ucfirst($dbN)."_".SLS_String::tableToClass($tableN);								
					$this->_generic->useModel($tableN,$dbN,"user");				
					$obj = new $classN();
					$properties = $obj->getParams();
					$xml->startTag("columns");
					foreach($properties as $key => $value)
						if ($key != "pk_lang")
							$xml->addFullTag("column",$key,true);
					$xml->endTag("columns");
					$xml->endTag("table");
				}
			}
				
			$xml->endTag("tables");	
			$xml->endTag("model");
		}
		else
		{
			$xml->addFullTag("error","Sorry this table doesn't exist anymore",true);
		}
		
		$this->saveXML($xml);
	}
Ejemplo n.º 29
0
	public function action()
	{
		set_time_limit(0);
		
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$controllersXML = $this->_generic->getControllersXML();
		$controller = $controllersXML->getTag("//controllers/controller[@isBo='true']/@name");
		$tokenSecret = sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3));
		$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
		$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
		$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));
		
		// Check if bo controller already exist
		if (empty($controller))
		{
			$xml->startTag("errors");
			$xml->addFullTag("error","Back-office controller could not be found. Please follow the following link to create it.",true);
			$xml->endTag("errors");
		}
		// Else, let's choose the models
		else 
		{
			// If reload
			if ($this->_http->getParam("reload") == "true")
			{
				$modelsWanted = $this->_http->getParam("models");
				$langs = $this->_lang->getSiteLangs();
				
				if (is_array($modelsWanted))
				{
					// Foreach models choose, generate files
					foreach($modelsWanted as $model)
					{
						$db = Sls_String::substrBeforeFirstDelimiter($model,".");
						$table = Sls_String::substrAfterFirstDelimiter($model,".");
						
						# Node into bo.xml
						$boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']";
						$boExists = $xmlBo->getTag($boPath."/@type");
						if (empty($boExists))
							$boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']";
						$boExists = $xmlBo->getTag($boPath);
						if (empty($boExists))
						{
							$this->_generic->useModel(SLS_String::tableToClass($table),ucfirst(strtolower($db)),"user");
							$class = ucfirst(strtolower($db))."_".SLS_String::tableToClass($table);
							$object = new $class();
							$xmlNode = '    <entry type="table" name="'.strtolower($db."_".$table).'" multilanguage="'.(($object->isMultilanguage()) ? "true" : "false").'">'."\n";
							$xmlNode .= '        <columns>'."\n";
							foreach($object->getColumns() as $column)
							{
								// Avoid pk
								$isPk = ($column == $object->getPrimaryKey() || $column == 'pk_lang') ? true : false;
								// Avoid fk
								$fkExist = $xmlFk->getTag("//sls_configs/entry[@tableFk='".strtolower($db."_".$table)."' and @columnFk='".$column."']/@tablePk");
								$isFk = (!empty($fkExist)) ? true : false;
								// Avoid quick edit on type file
								$fileExist = $xmlType->getTag("//sls_configs/entry[@table='".strtolower($db."_".$table)."' and @column='".$column."' and (@type='file_all' or @type='file_img')]/@column");
								$isFile = (!empty($fileExist)) ? true : false;
								
								$xmlNode .= '            <column table="'.strtolower($db."_".$table).'" name="'.$column.'" multilanguage="'.(($object->isMultilanguage() && !$isPk) ? "true" : "false").'" displayFilter="true" displayList="'.(($isFk) ? "false" : "true").'" allowEdit="'.(($isPk || $isFk || $isFile) ? "false" : "true").'" allowHtml="false" />'."\n";
							}
							$xmlNode .= '        </columns>'."\n";
							$xmlNode .= '    </entry>'."\n";
							$xmlBo->appendXMLNode("//sls_configs",$xmlNode);
							$xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML());
							$xmlBo->refresh();
						}
						# /Node into bo.xml
						
						# BoActions
						$boActions = array("List","Add","Modify","Clone","Delete");
						foreach($boActions as $boAction)
						{
							// Generate Action
							$action = ucfirst(strtolower($boAction)).ucfirst(strtolower($db))."_".SLS_String::tableToClass($table);
							$params = array(0 => array("key" 	=> "reload",
									  				   "value" 	=> "true"),
									  		1 => array("key" 	=> "Controller",
									  				   "value" 	=> $controller),
										 	2 => array("key" 	=> "actionName",
									  				   "value" 	=> $action),
									  		3 => array("key"	=> "token",
									  				   "value"	=> $tokenSecret),
									  		4 => array("key"	=> "template",
									  				   "value" 	=> "bo"),
									  		5 => array("key"	=> "dynamic",
									  				   "value" 	=> "on"),
									  		6 => array("key"	=> "indexes",
									  				   "value"	=> "noindex,nofollow")
										    );
							foreach($langs as $lang)
							{
								$tmpParam = array("key" 	=> $lang."-action",
												  "value" 	=> $action."_".$lang);
								$tmpTitle = array("key" 	=> $lang."-title",
												  "value" 	=> $action);
								array_push($params,$tmpParam);
								array_push($params,$tmpTitle);
							}
							file_get_contents($this->_generic->getFullPath("SLS_Bo",
																		  "AddAction",
																		  $params,
																		  true));
							
							// Erase Action
							if (file_exists($this->_generic->getPathConfig("installDeployement")."Controllers/Actions/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.controller.php"))
							{
								$source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Controllers/Actions/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.controller.php"));
								file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/".$action.".controller.php",$source);
							}
							
							// Erase View Head
							if (file_exists($this->_generic->getPathConfig("installDeployement")."Views/Headers/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl"))
							{
								$source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Views/Headers/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl"));
								file_put_contents($this->_generic->getPathConfig("viewsHeaders").$controller."/".$action.".xsl",$source);
							}
							
							// Erase View Body
							if (file_exists($this->_generic->getPathConfig("installDeployement")."Views/Body/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl"))
							{
								$source = str_replace(array("{{USER_BO}}","{{DB}}","{{TABLE}}"),array($controller,ucfirst(strtolower($db)),SLS_String::tableToClass($table)),file_get_contents($this->_generic->getPathConfig("installDeployement")."Views/Body/{{USER_BO}}/".$boAction."{{DB}}_{{TABLE}}.xsl"));
								file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/".$action.".xsl",$source);
							}
						}
						# /BoActions
					}
					
					$this->_generic->forward("SLS_Bo","ManageRights");
				}
			}
			
			$sql = SLS_Sql::getInstance();
			$models = $this->getAllModels();			
			$dbs = $sql->getDbs();
			sort($dbs,SORT_REGULAR);
						
			$xml->startTag("dbs");
			foreach($dbs as $db)
			{
				sort($models,SORT_REGULAR);
				
				$xml->startTag("db");
				$xml->addFullTag("name",$db,true);
				$xml->startTag("models");
				for($i=0 ; $i<$count=count($models) ; $i++)
				{
					if (SLS_String::startsWith($models[$i],$db))
					{
						$xml->startTag("model");
						$xml->addFullTag("name",SLS_String::substrAfterFirstDelimiter($models[$i],"."),true);
						$xml->addFullTag("existed",($this->boActionExist(SLS_String::substrAfterFirstDelimiter($models[$i],"."),SLS_String::substrBeforeFirstDelimiter($models[$i],"."))) ? "true" : "false",true);
						$xml->endTag("model");
					}
				}
				$xml->endTag("models");
				$xml->endTag("db");
			}
			$xml->endTag("dbs");
		}
		
		$xml->addFullTag("url_add_controller",$this->_generic->getFullPath("SLS_Bo","AddController",array(0=>array("key"=>"isBo","value"=>"true"))),true);
		$this->saveXML($xml);
	}