コード例 #1
0
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml"));
		
		$param = $this->_http->getParam("name");
		$model = SLS_String::substrAfterFirstDelimiter($param,"_");
		$alias = SLS_String::substrBeforeFirstDelimiter($param,"_");
		
		if ($this->_http->getParam("type") == "")	
			$actionsTypes = array("list","add","modify","delete","clone");
		else
			$actionsTypes = array($this->_http->getParam("type"));
		foreach($actionsTypes as $actionType)
			$this->deleteActionBo($model,$actionType,$alias);
		
		# Node into bo.xml
		$boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($alias."_".$model)."']";
		$boExists = $xmlBo->getTag($boPath."/@type");
		if (empty($boExists))		
			$boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($alias."_".$model)."']";
		$boExists = $xmlBo->getTag($boPath);
		if (!empty($boExists))
		{
			$xmlBo->deleteTags($boPath, count($xmlBo->getTags($boPath)));
			$xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML());
			$xmlBo->refresh();	
		}
		# /Node into bo.xml
			
		$controllers = $this->_generic->getTranslatedController("SLS_Bo","Bo");
		$this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"]);
	}
コード例 #2
0
	public function action() 
	{		
		// Objects		
		$user = $this->hasAuthorative();		
			
		$name = SLS_String::trimSlashesFromString($this->_http->getParam("name"));						
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml");
		$xmlRights = new SLS_XMLToolbox($pathsHandle);			
		$result = $xmlRights->getTags("//sls_configs/entry[@login='******']");
				
		if (!empty($result))
		{								
			$xmlRights->deleteTags('//sls_configs/entry[@login="******"]');
			$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());
		}
		$this->_generic->redirect("Manage/Rights");		
	}
コード例 #3
0
	/**
	 * Action Home
	 *
	 */
	public function action() 
	{
		$this->secureURL();
		
		$this->_generic->registerLink('authentication', 'SLS_Init', 'Authentication');
		$reload = $this->_http->getParam('authentication_reload');
		$login = SLS_String::trimSlashesFromString($this->_http->getParam('auth_login'));
		$pass1 =  SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass1'));
		$pass2 = SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass2'));
		$xml = $this->getXML();
		$errors = array();
		if ($reload == 'true')
		{
			if (strlen($login) < 6)
				array_push($errors, "The administrator username should have 6 caracters at least");
			if (strlen($pass1) < 6)
				array_push($errors, "The password should have 6 caracters at least");
			if ($pass1 != $pass2)
				array_push($errors, "Both password must be the same");
			
			if (empty($errors))
			{
				if (!is_file($this->_generic->getPathConfig('configSls')."sls.xml") && !touch($this->_generic->getPathConfig('configSls')."sls.xml"))
					$this->_generic->dispatch('SLS_Init', 'DirRights');
				else 
				{
					$coreXml = $this->_generic->getCoreXml('sls');
					$user = new SLS_XMLToolbox(false);
					$user->startTag("user", array("login"=>sha1($login),"pass"=>sha1($pass1),"level"=>"0"));
					$user->endTag("user");
					$coreXml->appendXMLNode("//sls_configs/auth/users", $user->getXML('noHeader'));
					file_put_contents($this->_generic->getPathConfig("configSls")."sls.xml", $coreXml->getXML());
					$this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"GlobalSettings",1=>"Settings"));
					return $this->_generic->dispatch("SLS_Init", "GlobalSettings");
				}
			}
			else 
			{				
				$xml->startTag("errors");
				foreach ($errors as $error)
					$xml->addFullTag("error", $error, true);
				$xml->endTag("errors");
			}
		}
		$this->saveXML($xml);
	}
コード例 #4
0
	/**
	 * Check if an admin is authorized to log in
	 *
	 * @access public static
	 * @param string $login login
	 * @param string $pwd password
	 * @return mixed 1 if connected, 0 if expired, -1 not logged, -2 disabled
	 * @since 1.0
	 */
	public static function connect($login,$pwd)
	{
		$generic = SLS_Generic::getInstance();
		$session = $generic->getObjectSession();
		$sessionToken = substr(substr(sha1($generic->getSiteConfig("privateKey")),12,31).substr(sha1($generic->getSiteConfig("privateKey")),4,11),6);
		
		$pathsHandle = file_get_contents($generic->getPathConfig("configSls")."/rights.xml");
		$xmlRights = new SLS_XMLToolbox($pathsHandle);
		$result = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login='******' and @password='******' and count(action) > 0]",array("login")));
		
		if (!empty($result))
		{
			$attributes = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login='******' and @password='******']",array("reset_pwd","renew_pwd","last_renew_pwd","name","firstname","last_connection","enabled")));
			
			$reset_pwd = $attributes["attributes"][0]["value"];
			$renew_pwd = $attributes["attributes"][1]["value"];
			$last_renew_pwd = $attributes["attributes"][2]["value"];
			$name = $attributes["attributes"][3]["value"];
			$firstname = $attributes["attributes"][4]["value"];
			$lastLogin = $attributes["attributes"][5]["value"];
			$enabled = $attributes["attributes"][6]["value"];
			
			if ($reset_pwd == "true" || (!empty($last_renew_pwd) && !empty($renew_pwd) && (strtotime("+".$renew_pwd, SLS_Date::dateToTimestamp($last_renew_pwd)) < SLS_Date::dateToTimestamp(date("Y-m-d")))))
				return 0;
			if ($enabled == "false")
				return -2;
				
			$xmlRights->setTagAttributes("//sls_configs/entry[@login='******']",array("last_connection" => date("Y-m-d H:i:s")));
			$xmlRights->saveXML($generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());
			
			$session->setParam("SLS_BO_VALID_".$sessionToken,"true");	
			$session->setParam("SLS_BO_USER_".$sessionToken,$login);
			$session->setParam("SLS_BO_PREVIOUS_LOGIN",$lastLogin);
			$session->setParam("SLS_BO_LOGGED","true");
			$session->setParam("SLS_BO_USER",$login);
			$session->setParam("SLS_BO_USER_NAME",$name);
			$session->setParam("SLS_BO_USER_FIRSTNAME",$firstname);
			$session->setParam("ckfinderAuthorized",true);
			return 1;
		}
		else
			return -1;
	}
コード例 #5
0
	/**	 
	 * Write Controller' specifics params into XML before send it
	 *
	 * @access protected
	 * @since 1.0
	 */
	protected function writeParams()
	{
		// We check if we aren't passed here with the dispatcher
		if ($this->_output == "xhtml")
		{
			if (strpos($this->_generic->getBufferXML(),"<ControllerParams>") === false)
			{
				$controllersParams = new SLS_XMLToolbox(false);
				$controllersParams->startTag("action");				
				$controllersParams->startTag("metas");
					$controllersParams->addFullTag("title", $this->_pageTitle, true);
					$controllersParams->addFullTag("description", $this->_metas['description'], true);
					$controllersParams->addFullTag("keywords", $this->_metas['keywords'], true);
					$controllersParams->addFullTag("robots", $this->_metas['robots'], true);
					$controllersParams->addFullTag("author", $this->_metas['author'], true);
					$controllersParams->addFullTag("copyright", $this->_metas['copyright'], true);
					$controllersParams->addFullTag("favicon", $this->_metas['favicon'], true);
				$controllersParams->endTag("metas");
				$controllersParams->startTag("links");
				$links = $this->_generic->getRegisteredLinks();
				for($i=0;$i<count($links);$i++)
				{
					$controllersParams->startTag("link");
					$controllersParams->addFullTag("name", strtoupper($links[$i]['codeName']), true);
					$controllersParams->addFullTag("href", $links[$i]['href'], true);
					$controllersParams->endTag("link");
				}
				$controllersParams->endTag("links");
				$controllersParams->endTag("action");
				
				// Save it into the XML's buffer
				$this->_generic->setBufferXML($controllersParams->getXML(), true, "//root/Statics/Sls/Configs");
			}
			// Set Protocol
			$xml = new SLS_XMLToolbox($this->_generic->getBufferXML());			
			$xml->setTag("//root/Statics/Sls/Configs/site/protocol", $this->_generic->getProtocol(), true);
			$xml->setTag("//root/Statics/Sls/Configs/site/siteprotocol", $this->_generic->getSiteConfig('protocol'), true);
			
			$this->_generic->setBufferXML($xml->getXML(), false);
		}
		elseif ($this->_output == "json")
		{			
			$xml = new SLS_XMLToolbox($this->_generic->getBufferXML());
			$output = json_encode(SLS_XMLToArray::createArray($xml->getNode("//root/View")));
			header('Content-Type: application/json');
			header('X-Robots-Tag: noindex,nofollow,noarchive');
			print($output);
			exit;			
		}
		else if ($this->_output == "rss" || $this->_output == "atom")
		{
			if ($this->_output == "rss")
				header('Content-Type: application/rss+xml');
			else 
				header('Content-Type: application/atom+xml');
			print($this->_outputOptions); 
			exit;
		}
		else 
		{
			header("Content-type: text/xml");
			if (!is_null($this->_outputOptions))
				print($this->_outputOptions);
			else 
			{
				$xml = new SLS_XMLToolbox($this->_generic->getBufferXML());
				$view = $xml->getNode("//root/View");
				print('<?xml version="1.0" encoding="UTF-8"?>'.$view);
			}
			exit;				
		}
	}
コード例 #6
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);
		}
	}
コード例 #7
0
	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);
	}
コード例 #8
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);
	}
コード例 #9
0
	/**
	 * Save the cache file if the cache is enabled	 
	 *
	 * @access public
	 * @param string $xml the xml to save
	 * @since 1.0
	 */
	public function saveCacheXML($xml)
	{
		
		$cacheObjects = file_get_contents($this->_root.$this->_configSecurePath."/cache.xml");
		$writeXML = new SLS_XMLToolbox($cacheObjects);
		$writeXML->overwriteTags("//statics", $xml);		
		try {
			$xml = simplexml_load_string($writeXML->getXML());
			$writeXML->saveXML($this->_root.$this->_configSecurePath."/cache.xml");
		}
		catch (Exception $e) {} 
	}
コード例 #10
0
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml	= $this->makeMenu($xml);
		$reload = $this->_http->getParam("reload");
		$action = $this->_http->getParam("Action");
		$errors = array();
		$slsXml = $this->_generic->getCoreXML('sls');
		$syncServer = array_shift($slsXml->getTags("slsnetwork"));
		$slsVersion = array_shift($slsXml->getTags("version"));
		$edit = $this->_generic->getTranslatedController('SLS_Bo', 'EditPlugin');		
		$editAppli = $this->_generic->getTranslatedController('SLS_Bo', 'CreatePlugin');		
		
		$pluginsXML = $this->_generic->getPluginXml("plugins");
		// List own Plugins
		if ($action == "")
		{
			$deleteController = $this->_generic->getTranslatedController("SLS_Bo", "DeletePlugin");
			if (($count = count($pluginsXML->getTags("//plugins/plugin[@beta='1']"))) > 0)
			{
				$xml->startTag("own_plugin");
					for($i=1;$i<=$count;$i++)
					{
						$id = array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@id"));
						$xml->startTag("plugin", array("code"=>array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@code")),"id"=>$id));
						$xml->addFullTag("description", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/description")), true);
						$xml->addFullTag("custom", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/@customizable")), true);
						$xml->addFullTag("edit", $edit['protocol']."://".$this->_generic->getSiteConfig('domainName')."/".$edit['controller']."/".$edit['scontroller']."/Plugin/".$id.".sls", true);
						$xml->addFullTag("name", array_shift($pluginsXML->getTags("//plugins/plugin[@beta='1'][".$i."]/name")), true);
						$xml->addFullTag("delete", $deleteController['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$deleteController['controller']."/".$deleteController['scontroller']."/Plugin/".$id.".sls", true);
						$xml->addFullTag("editAppli", $editAppli['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$editAppli['controller']."/".$editAppli['scontroller']."/Plugin/".$id."/Action/Edit.sls", true);						
						$xml->endTag("plugin");
						
					}
				$xml->endTag("own_plugin");
			}
			$this->registerLink("CREATE", "SLS_Bo", "CreatePlugin", array("Action"=>"Create"));
			$xml->addFullTag("step", "list", true);
		}
		// Create a new Plugin
		elseif ($action == "Create")
		{
			if ($reload == "true")
			{
				$name = SLS_String::trimSlashesFromString($this->_http->getParam("name"));
				$code = SLS_String::stringToUrl(strtolower(SLS_String::getSafeFilename(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", true);
				$output = SLS_String::trimSlashesFromString($this->_http->getParam("output"));
				$custom = SLS_String::trimSlashesFromString($this->_http->getParam("custom"));
				$path = SLS_String::trimSlashesFromString($this->_http->getParam("path"));
				$pathName = SLS_String::stringToUrl(SLS_String::getSafeFilename(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", false);
				$description = SLS_String::trimSlashesFromString($this->_http->getParam("full_description"));
				
				// Get Plugins Versions
				$serversJSON = @file_get_contents($syncServer);
				$pluginsAvailable = array();
				$filesReserved = array();
				$dirsReserved = array();
				if ($serversJSON !== false && !empty($serversJSON))
				{					
					$servers = json_decode($serversJSON);
					$pluginsServers = $servers->servers->plugins;
					$plugins = array();
					
					foreach ($pluginsServers as $pluginsServer)
					{						
						$serverContent = @file_get_contents($pluginsServer->url);
						if ($serverContent !== false && !empty($serverContent))
						{
							$serverContent = json_decode($serverContent);
							$plugs = $serverContent->plugins;
							foreach ($plugs as $plug)
							{
								$pluginsAvailable[] = $plug->code;
								if ($plug->type == 'file')
									$filesReserved[] = $plug->path;
								else 
									$dirsReserved[] = $plug->path;
							}
						}
					}
				}
				
				$xml->startTag("form");
					$xml->addFullTag("name", $name, true);
					$xml->addFullTag("code", $code, true);
					$xml->addFullTag("custom", $custom, true);
					$xml->addFullTag("path", $path, true);
					$xml->addFullTag("path_name", $pathName, true);
					$xml->addFullTag("fill_description", $description, true);
					if (empty($name))
						$errors[] = "You must fill the common name";
					if (empty($code))
						$errors[] = "You must fill the code name";
					if (empty($output) || ($output != 'yes' && $output != 'no'))
						$errors[] = "Choose if your plugin is an output type";
					if (empty($custom) || ($custom != 'yes' && $custom != 'no'))
						$errors[] = "Choose if your plugin will be customizable";
					if (empty($path) || ($path != 'file' && $path != 'dir'))
						$errors[] = "Choose if your plugin require only a file or multiple files in a directory";	
					if (empty($pathName))
						$errors[] = "You must choose a filename or a directory name";	
					if (empty($description))
						$errors[] = "You must fill the full description in English";	
					if (empty($errors))
					{
						if (in_array($code, $pluginsAvailable))
							$errors[] = "This code name is already in use for another plugin";
						if ($path == 'file' && in_array($pathName.".class.php", $filesReserved))
							$errors[] = "This file name is already in use for another plugin";
						if ($path == 'dir' && in_array($pathName, $dirsReserved))
							$errors[] = "This directory name is already in use for another plugin";
						
						if (empty($errors))
						{
							
							$newId = md5(uniqid($this->_generic->getSiteConfig("privateKey")));
							$pathFile = $this->_generic->getPathConfig("plugins");
							if ($path =="dir")
								$pathFile .= $pathName."/";
							
							if ($output == 'no')
							{
								$str = '<?php'."\n".
										'/**'."\n".
										' * Plugin '.$name."\n". 
										' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n".
										' *'."\n".
										' * @package Plugins'."\n".
										' * @since 1.0'."\n".
										' */'."\n". 
										'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin'."\n".
										'{'."\n".
										t(1).'public function __construct()'."\n".
										t(1).'{'."\n".
											t(2).'parent::__construct($this);'."\n".
											t(2).'$this->checkDependencies();'."\n".
										t(1).'}'."\n\n".
										t(1).'public function checkDependencies()'."\n".
										t(1).'{'."\n".
										t(1).'}'."\n".
										'}'."\n".
										'?>';
							}
							else 
							{
								$str = '<?php'."\n".
										'/**'."\n".
										' * Plugin '.$name."\n". 
										' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n".
										' *'."\n".
										' * @package Plugins'."\n".
										' * @since 1.0'."\n".
										' */'."\n". 
										'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin, SLS_IPluginOutput'."\n".
										'{'."\n".
										t(1).'public function __construct()'."\n".
										t(1).'{'."\n".
											t(2).'parent::__construct($this);'."\n".
											t(2).'$this->checkDependencies();'."\n".
										t(1).'}'."\n\n".
										t(1).'public function checkDependencies()'."\n".
										t(1).'{'."\n".
										t(1).'}'."\n".
										'}'."\n".
										'?>';
							}
							
							if (@file_put_contents($pathFile.$pathName.".class.php", $str) === false)
								$errors[] = "Plugin Creation failed";
									
							
							if (empty($errors))
							{
								if ($custom == "yes")
								{
									$str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><plugin><exemple_part writable=\"1\" label=\"Exemple Part\" clonable=\"1\" alias=\"main\"><exemple_row writable=\"1\" label=\"Exemple Row\" type=\"string\" clonable=\"0\" /></exemple_part></plugin>";
									if (@file_put_contents($this->_generic->getPathConfig("configPlugins").$newId."_".$code.".xml", $str) === false)
										$errors[] = "Plugin Creation failed";
								}
								
							}
							if (empty($errors))
							{
								$newPlugin = new SLS_XMLToolbox(false);
								$newPlugin->startTag("plugin", array(
									"beta"=>"1",
									"code"=>$code,
									"id"=>$newId,
									"version"=>"0.1",
									"compability"=>$slsVersion,
									"customizable"=>($custom=="yes")?"1":"0",
									"output"=>($output=="yes")?"1":"0",
									"file"=>($path=="file")?"1":"0",
									"path"=>($path=="file")?$pathName.".class.php" : $pathName
								));
								$newPlugin->addFullTag("name", $name, true);
								$newPlugin->addFullTag("description", $description, true);
								$newPlugin->addFullTag("author", "Me", true);
								$newPlugin->addFullTag("dependencies", "", false);
								$newPlugin->endTag("plugin");
								$pluginsXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader'));
								file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginsXML->getXML());
								$this->goDirectTo("SLS_Bo", "CreatePlugin");
							}
							
						}
						
					}
					
				$xml->endTag("form");
			}
			$xml->addFullTag("step", "create", true);
		}
		elseif ($action == "Edit")
		{
			
			$pluginID = $this->_http->getParam("Plugin");
			if (SLS_PluginsManager::isExists($pluginID) === false)
				$this->goDirectTo("SLS_Bo", "CreatePlugin");
			
			$originalPlugin = new SLS_PluginsManager($pluginID);
				
			if ($reload == "true")
			{
				
				$name = SLS_String::trimSlashesFromString($this->_http->getParam("name"));
				$code = SLS_String::stringToUrl(strtolower(SLS_String::getSafeFilename(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", true);
				$output = SLS_String::trimSlashesFromString($this->_http->getParam("output"));
				$custom = SLS_String::trimSlashesFromString($this->_http->getParam("custom"));
				$path = SLS_String::trimSlashesFromString($this->_http->getParam("path"));
				$pathName = SLS_String::stringToUrl(SLS_String::getSafeFilename(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("code")))), "", false);
				$description = SLS_String::trimSlashesFromString($this->_http->getParam("full_description"));
				
				// Get Plugins Versions
				$serversJSON = @file_get_contents($syncServer);
				$pluginsAvailable = array();
				$filesReserved = array();
				$dirsReserved = array();
				if ($serversJSON !== false && !empty($serversJSON))
				{					
					$servers = json_decode($serversJSON);
					$pluginsServers = $servers->servers->plugins;
					$plugins = array();
					
					foreach ($pluginsServers as $pluginsServer)
					{						
						$serverContent = @file_get_contents($pluginsServer->url);
						if ($serverContent !== false && !empty($serverContent))
						{
							$serverContent = json_decode($serverContent);
							$plugs = $serverContent->plugins;
							foreach ($plugs as $plug)
							{
								$pluginsAvailable[] = $plug->code;
								if ($plug->type == 'file')
									$filesReserved[] = $plug->path;
								else 
									$dirsReserved[] = $plug->path;
							}
						}
					}
				}
				
				$xml->startTag("form");
					$xml->addFullTag("name", $name, true);
					$xml->addFullTag("code", $code, true);
					$xml->addFullTag("custom", $custom, true);
					$xml->addFullTag("path", $path, true);
					$xml->addFullTag("path_name", $pathName, true);
					$xml->addFullTag("fill_description", $description, true);
					if (empty($name))
						$errors[] = "You must fill the common name";
					if (empty($code))
						$errors[] = "You must fill the code name";
					if (empty($output) || ($output != 'yes' && $output != 'no'))
						$errors[] = "Choose if your plugin is an output type";
					if (empty($custom) || ($custom != 'yes' && $custom != 'no'))
						$errors[] = "Choose if your plugin will be customizable";
					if (empty($path) || ($path != 'file' && $path != 'dir'))
						$errors[] = "Choose if your plugin require only a file or multiple files in a directory";	
					if (empty($pathName))
						$errors[] = "You must choose a filename or a directory name";	
					if (empty($description))
						$errors[] = "You must fill the full description in English";	
					if (empty($errors))
					{
						if ($code != $originalPlugin->_code && in_array($code, $pluginsAvailable))
							$errors[] = "This code name is already in use for another plugin";
						if ($pathName.".class.php" != $originalPlugin->_path && $path == 'file' && in_array($pathName.".class.php", $filesReserved))
							$errors[] = "This file name is already in use for another plugin";
						if ($pathName != $originalPlugin->_path && $path == 'dir' && in_array($pathName, $dirsReserved))
							$errors[] = "This directory name is already in use for another plugin";
						if (empty($errors))
						{
							if ($originalPlugin->_file == 1 && $path == 'dir')
							{
								if (!is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path))
									mkdir($this->_generic->getPathConfig("plugins").$pathName);
								if (is_file($this->_generic->getPathConfig("plugins").$originalPlugin->_path))
									@unlink($this->_generic->getPathConfig("plugins").$originalPlugin->_path);
								
							}
							if ($originalPlugin->_file == 0 && $path == 'file')
							{
								if (is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path))
									$this->_generic->rm_recursive($this->_generic->getPathConfig("plugins").$originalPlugin->_path);
								if ($output == 'no')
								{
									$str = '<?php'."\n".
											'/**'."\n".
											' * Plugin '.$name."\n". 
											' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n".
											' *'."\n".
											' * @package Plugins'."\n".
											' * @since 1.0'."\n".
											' */'."\n". 
											'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin'."\n".
											'{'."\n".
											t(1).'public function __construct()'."\n".
											t(1).'{'."\n".
												t(2).'parent::__construct($this);'."\n".
												t(2).'$this->checkDependencies();'."\n".
											t(1).'}'."\n\n".
											t(1).'public function checkDependencies()'."\n".
											t(1).'{'."\n".
											t(1).'}'."\n".
											'}'."\n".
											'?>';
								}
								else 
								{
									$str = '<?php'."\n".
											'/**'."\n".
											' * Plugin '.$name."\n". 
											' * '.str_replace("<br />", "\\n * ", nl2br($description))."\n".
											' *'."\n".
											' * @package Plugins'."\n".
											' * @since 1.0'."\n".
											' */'."\n". 
											'class '.$pathName.' extends SLS_PluginGeneric implements SLS_IPlugin, SLS_IPluginOutput'."\n".
											'{'."\n".
											t(1).'public function __construct()'."\n".
											t(1).'{'."\n".
												t(2).'parent::__construct($this);'."\n".
												t(2).'$this->checkDependencies();'."\n".
											t(1).'}'."\n\n".
											t(1).'public function checkDependencies()'."\n".
											t(1).'{'."\n".
											t(1).'}'."\n".
											'}'."\n".
											'?>';
								}
								
								if (@file_put_contents($this->_generic->getPathConfig("plugins").$pathName.".class.php", $str) === false)
									$errors[] = "Plugin Creation failed";
							}
							if ($originalPlugin->_file == 1 && $path == 'file' && $pathName.".class.php" != $originalPlugin->_path)
							{
								if (is_file($this->_generic->getPathConfig("plugins").$originalPlugin->_path))
									rename($this->_generic->getPathConfig("plugins").$originalPlugin->_path, $this->_generic->getPathConfig("plugins").$pathName.".class.php");
							}
							if ($originalPlugin->_file == 0 && $path == 'dir' && $pathName != $originalPlugin->_path)
							{
								if (is_dir($this->_generic->getPathConfig("plugins").$originalPlugin->_path))
									rename($this->_generic->getPathConfig("plugins").$originalPlugin->_path, $this->_generic->getPathConfig("plugins").$pathName);
							}
							if (empty($errors))
							{
								if ($custom == "yes" && $originalPlugin->_customizable == false)
								{
									$str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><plugin><exemple_part writable=\"1\" label=\"Exemple Part\" clonable=\"1\" alias=\"main\"><exemple_row writable=\"1\" label=\"Exemple Row\" type=\"string\" clonable=\"0\" /></exemple_part></plugin>";
									if (@file_put_contents($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$code.".xml", $str) === false)
										$errors[] = "Plugin Creation failed";
								}
								if ($custom == "no" && $originalPlugin->_customizable == true)
								{
									if (is_file($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml"))
										unlink($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml");
								}
								
							}
							if (empty($errors))
							{
								if ($code != $originalPlugin->_code)
								{
									$pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("code"=>$code));
									if (is_file($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml"))
										rename($this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$originalPlugin->_code.".xml", $this->_generic->getPathConfig("configPlugins").$originalPlugin->_id."_".$code.".xml");
								}
								if (($output == "yes" && $originalPlugin->_output == 0) || ($output == "no" && $originalPlugin->_output == 1))
									$pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("output"=>($output=="yes")?"1":"0"));
								if (($custom == "yes" && $originalPlugin->_customizable == false) || ($custom == "no" && $originalPlugin->_customizable == true))
									$pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("customizable"=>($custom=="yes")?"1":"0"));
								if (($originalPlugin->_file == 1 && $path == 'dir') || ($originalPlugin->_file == 0 && $path == 'file'))
									$pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("file"=>($path=="file")?"1":"0"));
								if (($path == 'file' && $originalPlugin->_path != $pathName.".class.php") || ($path == 'dir' && $originalPlugin->_path != $pathName))
									$pluginsXML->setTagAttributes("//plugins/plugin[@beta='1' and @id='".$pluginID."']", array("path"=>($path=="file")?$pathName.".class.php" : $pathName));
								if ($originalPlugin->_name != $name)
									$pluginsXML->setTag("//plugins/plugin[@beta='1' and @id='".$pluginID."']/name", $name, true);
								if ($originalPlugin->_description != $description)
									$pluginsXML->setTag("//plugins/plugin[@beta='1' and @id='".$pluginID."']/description", $description, true);
								
								file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginsXML->getXML());
								$this->goDirectTo("SLS_Bo", "CreatePlugin");
							}
							
						}
						
					}
					
				$xml->endTag("form");
			}
			$originalPlugin = new SLS_PluginsManager($pluginID);
			$xml->startTag("plugin");
				$xml->addFullTag("name", $originalPlugin->_name, true);
				$xml->addFullTag("code", $originalPlugin->_code, true);
				$xml->addFullTag("output", ($originalPlugin->_output == 1)?"yes":"no", true);
				$xml->addFullTag("custom", ($originalPlugin->_customizable)?"yes":"no", true);
				$xml->addFullTag("path", ($originalPlugin->_file==1)?'file':'dir', true);
				$xml->addFullTag("path_name", ($originalPlugin->_file==1)?SLS_String::substrBeforeLastDelimiter($originalPlugin->_path, ".class.php"):$originalPlugin->_path, true);
				$xml->addFullTag("fill_description", $originalPlugin->_description, true);
			$xml->endTag("plugin");
			$xml->addFullTag("step", "edit", true);
		}
		
		if (!empty($errors))
		{
			$xml->startTag("errors");
			foreach ($errors as $error)
				$xml->addFullTag("error", $error, true);
			$xml->endTag("errors");
		}
		
		$this->saveXML($xml);		
	}
コード例 #11
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);
	}
コード例 #12
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);
	}
コード例 #13
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);
	}
コード例 #14
0
	public function action()
	{
		$user = $this->hasAuthorative();
				
		// Objects		
		$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));
		$xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml"));
		$xml = $this->getXML();
		$tables = array();
		
		$xml = $this->makeMenu($xml);
				
		// Get the table & class name
		$table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_");
		$db	   = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_");
		$class = ucfirst($db)."_".SLS_String::tableToClass($table);
		
		$result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1")));
		$res = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($class)."']",array("tablePk","columnFk"));
		if (!empty($result) || count($res) != "2")
			$this->_generic->forward("SLS_Bo","EditModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));		
		else
		{
			$xml->startTag("fks");
			for($i=0 ; $i<$count=count($res) ; $i++)
			{
				$className = ucfirst($res[$i]["attributes"][0]["value"]);
				$this->_generic->useModel(SLS_String::substrAfterFirstDelimiter($className,"_"),SLS_String::substrBeforeFirstDelimiter($className,"_"),"user");							
				$object = new $className();
				array_push($tables,$className);
				
				$xml->startTag("fk");
					$xml->addFullTag("class",$className,"true");
					$xml->addFullTag("table",$object->getTable(),"true");
				$xml->endTag("fk");
			}
			$xml->endTag("fks");
		}
		
		$xml->startTag("model");
		$xml->addFullTag("table",$table,true);
		$xml->addFullTag("class",$class,true);
		$xml->endTag("model");
		
		if ($this->_http->getParam("reload") == "true")
		{
			$target_table = SLS_String::trimSlashesFromString($this->_http->getParam("target_table"));
			$tableBearer = $class;
			$table2 = "";
			foreach($tables as $table)			
				if ($table != $target_table)
					$table2 = $table;			
			
			$xmlNode = '<entry tableBearer="'.$tableBearer.'" table1="'.$target_table.'" table2="'.$table2.'" />';				
			$xmlBearer->appendXMLNode("//sls_configs",$xmlNode); 
			$xmlBearer->saveXML($this->_generic->getPathConfig("configSls")."/bearers.xml",$xmlBearer->getXML());
			$this->_generic->forward("SLS_Bo","EditModel",array(array("key"=>"name","value"=>$this->_http->getParam("name"))));
		}
		
		$this->saveXML($xml);
	}
コード例 #15
0
	public function action()
	{
		$user 	= $this->hasAuthorative();
		$xml = $this->makeMenu($this->getXML());
		$slsXml = $this->_generic->getCoreXML('sls');
		$errors = array();
		$syncServer = array_shift($slsXml->getTags("slsnetwork"));
		$action = $this->_http->getParam('Action');
		$serverID = $this->_http->getParam("Server");
		$pluginID = $this->_http->getParam("Plugin");
		$this->registerLink("CREATE", "SLS_Bo", "CreatePlugin");
		$controllers = $this->_generic->getTranslatedController('SLS_Bo', 'SearchPlugin');
		
		$serversJSON = @file_get_contents($syncServer);
		if ($serversJSON === false ||empty($serversJSON))
			$errors[] = "You are not connected to internet or synchronisation server is temporaly unavailable";
		else 
		{			
			$servers = json_decode($serversJSON);
			$pluginsServers = $servers->servers->plugins;
			$plugins = array();
			
			$xml->startTag("servers");
			
			foreach ($pluginsServers as $pluginsServer)
			{				
				$serverContent = @file_get_contents($pluginsServer->url);				
				
				$xml->startTag("server", array("name"=>$pluginsServer->name,"id"=>$pluginsServer->id));
					$xml->addFullTag("url", $pluginsServer->url, true, array("status"=>($serverContent === false || empty($serverContent)) ? "0" : "1"));

					if ($serverContent !== false && !empty($serverContent))
					{
						$serverContent = json_decode($serverContent);
						
						
						$xml->startTag("plugins");
						$plugs = $serverContent->plugins;
						foreach ($plugs as $plug)
						{
							
							// If we want to download this Plugin
							if ($action == "Download" && $pluginsServer->id == $serverID && $plug->id == $pluginID)
							{
								$way = $this->_http->getParam('Way');
								$pluginXML = $this->_generic->getPluginXml("plugins");
								if (count($pluginXML->getTags("//plugins/plugin[@id = '".$plug->id."']")) == 0 && count($pluginXML->getTags("//plugins/plugin[@code = '".$plug->code."' and @beta='1']")) == 0)
								{
									if (SLS_Remote::remoteFileExists($plug->file) != 0)
										$errors[] = $plug->name." is unavailable";
									else 
									{
										$filename = $this->_generic->getPathConfig("coreTmpDownload")."Plugins/".SLS_String::substrAfterLastDelimiter($plug->file, "/");
										if (!is_dir($this->_generic->getPathConfig("coreTmpDownload")."Plugins"))
											mkdir($this->_generic->getPathConfig("coreTmpDownload")."Plugins");
										$result = @copy($plug->file, $filename);
										if ($result === false)
											$errors[] = "The download of ".$plug->name." has failed";
										else 
										{
											$tar = new SLS_Tar();
											if ($tar->openTAR($filename) === false)
												$errors[] = "Plugin archive is corrupted";
											else 
											{
												$hasConf = false;
												$isFile = true;
												$pathName = "";
												foreach ($tar->directories as $directory)
												{
													if (SLS_String::startsWith($directory['name'], "Sources/"))
													{
														$dirName = SLS_String::substrAfterFirstDelimiter($directory['name'], "Sources/");
														if (!empty($dirName))
														{
															if (!is_dir($this->_generic->getPathConfig("plugins").$dirName))
																mkdir($this->_generic->getPathConfig("plugins").$dirName);
															if (empty($pathName))
																$pathName = (strpos($dirName, "/") !== false) ? SLS_String::substrBeforeLastDelimiter($dirName, "/") : $dirName;
															
															$isFile = false;
														}
													}
												}
												
												foreach ($tar->files as $file)
												{
													
													$copy = true;
													if (SLS_String::startsWith($file['name'], "Configs/") && SLS_String::endsWith($file['name'], ".xml"))
													{
														$hasConf = true;
														$copy = @file_put_contents($this->_generic->getPathConfig("configPlugins").$plug->id."_".$plug->code.".xml", $file['file']);
													}
													if (SLS_String::startsWith($file['name'], 'Sources/'))
													{
														if ($isFile === true && $pathName == "")
															$pathName = SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/");
														$realPathFile = $this->_generic->getPathConfig("plugins").SLS_String::substrAfterFirstDelimiter($file['name'], "Sources/");
														$copy = @file_put_contents($realPathFile, $file['file']);
													}
													if ($copy === false)
													{
														$errors[] = "The copy of ".$file['name']." has failed";
													}
												}
												
												if (empty($errors))
												{
													$newPlugin = new SLS_XMLToolbox(false);
													$newPlugin->startTag("plugin", array("code"=>$plug->code,"id"=>$plug->id,"version"=>$plug->version,"compability"=>$plug->compability,"customizable"=>($hasConf) ? "1" : "0","file"=>($isFile)?"1":"0","path"=>$pathName));
														$newPlugin->addFullTag("name", $plug->name, true);
														$newPlugin->addFullTag("description", $plug->desc, true);
														$newPlugin->addFullTag("author", $plug->author, true);
														$newPlugin->addFullTag("dependencies", "", false);
													$newPlugin->endTag("plugin");
													$pluginXML->appendXMLNode("//plugins", $newPlugin->getXML('noHeader'));
													file_put_contents($this->_generic->getPathConfig("configPlugins")."plugins.xml", $pluginXML->getXML());
												}
												if (is_file($filename))
													unlink($filename);
											}
										}
									}
								}
								if ($way == "Maj")
								{
									$this->goDirectTo("SLS_Bo", "Plugins");
								}
								
							}//  /If we want to download this Plugin
							
							// We list all Plugins available on this server
							$exist = SLS_PluginsManager::isExists($plug->id);
							if ($exist)
							{
								$plugin = new SLS_PluginsManager($plug->id);
							}
							$xml->startTag("plugin", array("version"=>$plug->version,"code"=>$plug->code,"id"=>$plug->id,"compability"=>((float)$plug->compability<=(float)array_shift($slsXml->getTags("version"))) ? "1" : "0","has"=>($exist)?"1":"0"));
							$xml->addFullTag("name", $plug->name, true);
							$xml->addFullTag("doc", $pluginsServer->domain.$plug->doc, true);
							$xml->addFullTag("dl", $controllers['protocol']."://".$this->_generic->getSiteConfig("domainName")."/".$controllers['controller']."/".$controllers['scontroller']."/Action/Download/Server/".$pluginsServer->id."/Plugin/".$plug->id.".sls");
							$xml->addFullTag("desc", $plug->desc, true);
							$xml->addFullTag("author", $plug->author, true);
							$xml->endTag("plugin");
						}
						$xml->endTag("plugins");
					}
					
				$xml->endTag("server");
			}
			$xml->endTag("servers");
		}
		if (!empty($errors))
		{
			$xml->startTag("errors");
			foreach ($errors as $error)
				$xml->addFullTag("error", $error, true);
			$xml->endTag("errors");
		}		
		$this->saveXML($xml);
	}
コード例 #16
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"),"_");
		$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);
	}
コード例 #17
0
	public function action()
	{
		
		$user 	= $this->hasAuthorative();
		$xml 	= $this->getXML();
		$xml	= $this->makeMenu($xml);
		$this->_generic->loadProjectSettings();
		
		$env = $this->_http->getParam("Env");
		if (empty($env))
			$env = "prod";
		
		if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/project_".$env.".xml"))					
			$projectXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/project_".$env.".xml"));
		else
			$projectXML = $this->_generic->getProjectXML();
		
		$errors = array();
		
		// Prod Deployment		
		$finalFile = ($this->_http->getParam("ProdDeployment") == "true") ? "project_".$env.".xml" : "project.xml";
		$isInBatch = ($this->_http->getParam("CompleteBatch") == "true") ? true : false;
		$xml->addFullTag("is_batch",($isInBatch) ? "true" : "false",true);
		$xml->addFullTag("is_prod",($this->_http->getParam("ProdDeployment") == "true") ? "true" : "false",true);		
		$reload = $this->_http->getParam("reload");
		
		if ($reload == "true")
		{
			
			$postProject = SLS_String::trimSlashesFromString($this->_http->getParam("project", "post"));
			$newXML = (SLS_String::startsWith(trim($postProject),"<?xml")) ? new SLS_XMLToolbox($postProject) : new SLS_XMLToolbox("<?xml version=\"1.0\" encoding=\"utf-8\"?>".$postProject);
			
			if (!$this->_generic->isValidXML($newXML->getXML()))
				array_push($errors, "The XML is incorrect");
					
			if (empty($errors))
			{
				if (count($newXML->getTags("//project")) != 1)
					array_push($errors, "The Root node should be called 'project'");
				
				$newXML = $this->checkNode("//project", $newXML);
				
				if (empty($errors))
				{
					$xmlStr = trim($newXML->getXML());
					if (substr($xmlStr, 0, 2)!= "<?")
						$xmlStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".$xmlStr;
					$projectXML->refresh();
					@file_put_contents($this->_generic->getPathConfig("configSecure").$finalFile, $xmlStr);
					if ($isInBatch)
						$this->_generic->forward("SLS_Bo","ProductionDeployment");
					else if ($this->_http->getParam("ProdDeployment") == "true")
						$this->_generic->forward("SLS_Bo","ProductionDeployment");
					$projectXML = new SLS_XMLToolbox($xmlStr);
				}
				
			}
			
			if (!empty($errors))
			{ 
				$xml->startTag('errors');
				foreach ($errors as $error)
				{
					$xml->addFullTag('error', $error, true);
				}
				$xml->endTag('errors');
			}
	
		}
		$this->_generic->eraseCache('Project');
		
		$value = (count($projectXML->getTags('//project/*')) == 0) ? "<project>\n</project>" : $projectXML->getXML('noHeader');
		
		$xml->startTag("current_values");
			$xml->addFullTag("project", str_replace(array('<![CDATA[', ']]>'), array('&#139;![CDATA[',']]&#155;'), $value), true);
		$xml->endTag("current_values");
		
		$this->saveXML($xml);		
	}
コード例 #18
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);
	}