public function action() { $user = $this->hasAuthorative(); $plugId = $this->_http->getParam('Plugin'); $field = $this->_http->getParam('Field'); $action = $this->_http->getParam('Action'); $controllers = $this->_generic->getTranslatedController('SLS_Bo', 'EditPlugin'); if (empty($plugId) || SLS_PluginsManager::isExists($plugId) === false) $this->dispatch('SLS_Bo', 'Plugins'); $plugin = new SLS_PluginsManager($plugId); $xmlPlug = $plugin->getXML(); if (empty($field) || empty($action)) $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); $xpath = "//".str_replace("|||", "/", str_replace("|$|", "]", str_replace("$|$", "[", $field))); $clonable = array_shift($xmlPlug->getTags($xpath."/@clonable")); if ($clonable != 1) $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); $nodeName = SLS_String::substrBeforeLastDelimiter($xpath, "["); if ($action == "del" && count($xmlPlug->getTags($nodeName)) > 1) { $xmlPlug->deleteTags($xpath, 1); } if ($action == "add") { $node = new SLS_XMLToolbox($xmlPlug->getNode($xpath)); $parent = SLS_String::substrBeforeLastDelimiter($xpath, "/"); $xmlPlug->appendXMLNode($xpath, $node->getXml('noHeader'), 1, "after"); $newIndex = SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterLastDelimiter($xpath, "["), "]"); $newIndex++; $newNode = SLS_String::substrBeforeLastDelimiter($xpath, "[")."[".$newIndex."]"; if ($xmlPlug->countChilds($newNode) == 0) $xmlPlug->setTag($newNode, "", false); else $xmlPlug = $this->removeRecursiveValues($newNode, $xmlPlug); $xmlPlug->setTagAttributes($newNode, array("alias"=>uniqid())); } $plugin->saveXML($xmlPlug); $this->redirect($controllers['controller']."/".$controllers['scontroller']."/Plugin/".$plugId.".sls"); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); // SLS_XmlToolbox objects $controllerXML = $this->_generic->getControllersXML(); $metaXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."metas.xml")); $siteXML = $this->_generic->getSiteXML(); // Get the lang $lang = $this->_http->getParam("name"); $langs = $this->_generic->getObjectLang()->getSiteLangs(); if (in_array($lang,$langs)) { // controllers.xml $controllerXML->deleteTags("//controllers/controller[@side!='sls']/controllerLangs/controllerLang[@lang='".$lang."']"); $controllerXML->deleteTags("//controllers/controller[@side!='sls']/scontrollers/scontroller/scontrollerLangs/scontrollerLang[@lang='".$lang."']"); $controllerXML->saveXML($this->_generic->getPathConfig("configSecure")."controllers.xml"); // /controllers.xml // metas.xml $metaXML->deleteTags("//sls_configs/action/title[@lang='".$lang."']"); $metaXML->deleteTags("//sls_configs/action/description[@lang='".$lang."']"); $metaXML->deleteTags("//sls_configs/action/keywords[@lang='".$lang."']"); $metaXML->saveXML($this->_generic->getPathConfig("configSls")."metas.xml"); // /metas.xml // site.xml $siteXML->deleteTags("//configs/langs/name[".(array_shift(array_keys($langs,$lang))+1)."]"); $siteXML->saveXML($this->_generic->getPathConfig("configSecure")."site.xml"); // /site.xml // generic.iso.lang.php @unlink($this->_generic->getPathConfig("coreGenericLangs")."generic.".$lang.".lang.php"); // /generic.iso.lang.php // site.iso.lang.php @unlink($this->_generic->getPathConfig("genericLangs")."site.".$lang.".lang.php"); // /site.iso.lang.php // Actions langs files $this->deleteActionsLang($this->_generic->getPathConfig("actionLangs"),$lang); // /Actions langs files } $controllers = $this->_generic->getTranslatedController("SLS_Bo","Langs"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller'].".sls"); }
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"]); }
public function action() { $user = $this->hasAuthorative(); // Get informations $table = $this->_http->getParam("table"); $column = $this->_http->getParam("column"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->deleteTags("//sls_configs/entry[@table='".$table."' and @column='".$column."']")); // Force update $this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$table))); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteLang",array(),false)); $xml->addFullTag("default",$this->_generic->getFullPath("SLS_Bo","DefaultLang",array(),false)); $this->registerLink("ENABLE", "SLS_Bo", "Langs", false); $this->_generic->registerLink('Add_Lang', 'SLS_Bo', 'AddLang'); $isos = $this->_generic->getObjectLang()->getSiteLangs(true); // Enable or Disable Lang $enable = $this->_http->getParam('Enable'); $lang = $this->_http->getParam("iso"); if (($enable == "on" || $enable == "off") && in_array($lang, $isos)) { $xmlLangs = $this->_generic->getSiteXML(); // Enable Lang if ($enable == "on") $xmlLangs->setTagAttributes("//configs/langs/name[node()='".$lang."']", array('active' => 'true')); else { if ($this->_generic->getSiteConfig('defaultLang') != $lang) $xmlLangs->setTagAttributes("//configs/langs/name[node()='".$lang."']", array('active' => 'false')); } $xmlLangs->refresh(); file_put_contents($this->_generic->getPathConfig('configSecure')."site.xml", $xmlLangs->getXML()); $this->_generic->forward("SLS_Bo","Langs"); } $handleLangs = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."international.xml")); $isosActives = $this->_generic->getObjectLang()->getSiteLangs(false); $xml->startTag("langs"); foreach($isos as $iso) { $xml->startTag("lang"); $xml->addFullTag("language",ucwords(array_shift($handleLangs->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[@iso='".$iso."']"))),true); $xml->addFullTag("iso",$iso,true); $xml->addFullTag("default",($this->_generic->getSiteConfig("defaultLang")==$iso) ? "true" : "false",true); $xml->addFullTag("active", (in_array($iso, $isosActives)) ? "true" : "false", true); $xml->endTag("lang"); } $xml->endTag("langs"); $this->saveXML($xml); }
/** * Action Home * */ public function action() { $this->secureURL(); $this->_generic->registerLink('authentication', 'SLS_Init', 'Authentication'); $reload = $this->_http->getParam('authentication_reload'); $login = SLS_String::trimSlashesFromString($this->_http->getParam('auth_login')); $pass1 = SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass1')); $pass2 = SLS_String::trimSlashesFromString($this->_http->getParam('auth_pass2')); $xml = $this->getXML(); $errors = array(); if ($reload == 'true') { if (strlen($login) < 6) array_push($errors, "The administrator username should have 6 caracters at least"); if (strlen($pass1) < 6) array_push($errors, "The password should have 6 caracters at least"); if ($pass1 != $pass2) array_push($errors, "Both password must be the same"); if (empty($errors)) { if (!is_file($this->_generic->getPathConfig('configSls')."sls.xml") && !touch($this->_generic->getPathConfig('configSls')."sls.xml")) $this->_generic->dispatch('SLS_Init', 'DirRights'); else { $coreXml = $this->_generic->getCoreXml('sls'); $user = new SLS_XMLToolbox(false); $user->startTag("user", array("login"=>sha1($login),"pass"=>sha1($pass1),"level"=>"0")); $user->endTag("user"); $coreXml->appendXMLNode("//sls_configs/auth/users", $user->getXML('noHeader')); file_put_contents($this->_generic->getPathConfig("configSls")."sls.xml", $coreXml->getXML()); $this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"GlobalSettings",1=>"Settings")); return $this->_generic->dispatch("SLS_Init", "GlobalSettings"); } } else { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } } $this->saveXML($xml); }
public function action() { // Objects $user = $this->hasAuthorative(); $name = SLS_String::trimSlashesFromString($this->_http->getParam("name")); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"); $xmlRights = new SLS_XMLToolbox($pathsHandle); $result = $xmlRights->getTags("//sls_configs/entry[@login='******']"); if (!empty($result)) { $xmlRights->deleteTags('//sls_configs/entry[@login="******"]'); $xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML()); } $this->_generic->redirect("Manage/Rights"); }
public function action() { // Params $name = SLS_String::trimSlashesFromString($this->_http->getParam("name")); // Objects $user = $this->hasAuthorative(); $xmlRights = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml")); $result = $xmlRights->getTags("//sls_configs/entry[@login='******']"); if (!empty($result)) { $xmlRights->setTagAttributes('//sls_configs/entry[@login="******"]', array("enabled" => ($xmlRights->getTag('//sls_configs/entry[@login="******"]/@enabled')=='false') ? 'true' : 'false')); $xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml"); } $this->_generic->forward("SLS_Bo","ManageRights"); }
public function action() { $user = $this->hasAuthorative(); // Objects $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml")); // Get the table & class name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1"))); if (!empty($result)) $xmlBearer->saveXML($this->_generic->getPathConfig("configSls")."/bearers.xml",$xmlBearer->deleteTags("//sls_configs/entry[@tableBearer='".$class."']")); $this->_generic->forward("SLS_Bo","EditModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); }
public function action() { // Objects $xml = $this->getXML(); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); $this->_generic->registerLink('Add', 'SLS_Bo', 'AddRight'); $xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteRight",array(),false)); $xml->addFullTag("edit",$this->_generic->getFullPath("SLS_Bo","EditRight",array(),false)); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"); $xmlRights = new SLS_XMLToolbox($pathsHandle); $result = $xmlRights->getTagsAttributes("//sls_configs/entry",array("login","password","name","firstname","enabled")); $xml->startTag("accounts"); for($i=0 ; $i<$count=count($result) ; $i++) { $xml->startTag("account"); for($j=0 ; $j<$count2=count($result[$i]["attributes"]) ; $j++) { if ($result[$i]["attributes"][$j]["key"] == "password") $xml->addFullTag($result[$i]["attributes"][$j]["key"],"******",true); else if (SLS_String::contains($result[$i]["attributes"][$j]["key"],"name")) $xml->addFullTag($result[$i]["attributes"][$j]["key"],ucwords(strtolower($result[$i]["attributes"][$j]["value"])),true); else $xml->addFullTag($result[$i]["attributes"][$j]["key"],$result[$i]["attributes"][$j]["value"],true); } $xml->addFullTag("color",$xmlRights->getTag("//sls_configs/entry[@login='******']/settings/setting[@key='color']"),true); $xml->endTag("account"); } $xml->endTag("accounts"); $xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ManageRightsStatus",array(),false)); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $environments = $this->getEnvironments(); $xml->startTag("environments"); for($i=0 ; $i<$count=count($environments) ; $i++) { $prodFiles = array ("site" => false, "db" => false, "mail" => false, "project" => false); foreach($prodFiles as $prodFile => $exists) { $ok = false; if (file_exists($this->_generic->getPathConfig("configSecure").$prodFile."_".$environments[$i].".xml")) { $handle = file_get_contents($this->_generic->getPathConfig("configSecure").$prodFile."_".$environments[$i].".xml"); $xmlConf = new SLS_XMLToolbox($handle); if ($prodFile == "site" && $xmlConf->getTag("//configs/domainName") != "") $ok = true; if ($prodFile == "db" && $xmlConf->getTag("//dbs/db/host") != "") $ok = true; if ($prodFile == "mail" && $xmlConf->getTag("//mails/host") != "") $ok = true; if ($prodFile == "project" && $handle != "") $ok = true; } $prodFiles[$prodFile] = $ok; } $xml->startTag("environment"); $xml->addFullTag("environment_title",$environments[$i],true); $xml->startTag("prod_files"); foreach($prodFiles as $prodFile => $exists) { $action = ""; switch($prodFile) { case "site": $action = "GlobalSettings"; break; case "db": $action = "DataBaseSettings"; break; case "mail": $action = "MailSettings"; break; case "project": $action = "ProjectSettings"; break; } $xml->startTag("prod_file"); $xml->addFullTag("title",$prodFile."_".$environments[$i].".xml",true); $xml->addFullTag("exists",($exists) ? "true" : "false",true); $xml->addFullTag("url_edit",$this->_generic->getFullPath("SLS_Bo",$action,array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"Env","value"=>$environments[$i]))),true); $xml->endTag("prod_file"); } $xml->endTag("prod_files"); $xml->addFullTag("url_batch",$this->_generic->getFullPath("SLS_Bo","GlobalSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$environments[$i]))),true); $xml->endTag("environment"); } $xml->endTag("environments"); $xml->addFullTag("url_add_environment",$this->_generic->getFullPath("SLS_Bo","EnvironmentsAdd"),true); $this->saveXML($xml); }
/** * Get the source code of a model from his table * * @param string $tableName the table name * @param string $db the alias of the database on which the model is located * @return string $contentM the source code */ protected function getModelSource($tableName,$db) { $arrayConvertTypes = array( 'varchar' => 'string', 'tinyint' => 'int', 'text' => 'string', 'date' => 'string', 'smallint' => 'int', 'mediumint' => 'int', 'int' => 'int', 'bigint' => 'int', 'float' => 'float | int', 'double' => 'float | int', 'decimal' => 'float', 'datetime' => 'string', 'timestamp' => 'int', 'time' => 'string | int', 'year' => 'int', 'char' => 'string', 'tinyblob' => 'string', 'tinytext' => 'string', 'blob' => 'string', 'mediumblob'=> 'string', 'mediumtext'=> 'string', 'longblob' => 'string', 'longtext' => 'string', 'enum' => 'string', 'set' => 'string', 'bool' => 'int', 'binary' => 'string', 'varbinary' => 'string' ); $sql = SLS_Sql::getInstance(); $className = ucfirst($db)."_".SLS_String::tableToClass($tableName); $file = ucfirst($db).".".SLS_String::tableToClass($tableName); // Create empty source $contentM = ""; $primaryKey = ""; $multiLanguage = 'false'; $sql->changeDb($db); $columns = $sql->showColumns($tableName); $fileName = ucfirst($db).".".SLS_String::tableToClass($tableName).".model.php"; $primaryKey = ""; $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $fkMethods = array(); $uniquesMultilang = array(); // Create Model $contentM = '<?php'."\n". '/**'."\n". ' * Object '.$className.''."\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.' extends SLS_FrontModel'."\n". '{'."\n". t(1).'/**'."\n". t(1).' * Class variables'."\n". t(1).' */'."\n"; $pkFound = false; for($i=0 ; $i<$count=count($columns) ; $i++) { if (!$pkFound && $columns[$i]->Key == "PRI") { $primaryKey = SLS_String::removePhpChars($columns[$i]->Field); $pkFound = true; } if ($columns[$i]->Field == "pk_lang" && $columns[$i]->Key == "PRI") $multiLanguage = 'true'; $contentM .= t(1).'protected $__'.SLS_String::removePhpChars($columns[$i]->Field).';'."\n"; } $contentM .= t(1).'protected $_table = "'.$tableName.'";'."\n". t(1).'protected $_db = "'.$db.'";'."\n". t(1).'protected $_primaryKey = "'.$primaryKey.'";'."\n"; // Show create table if ($multiLanguage == 'true') { $create = array_shift($sql->select("SHOW CREATE TABLE `".$tableName."`")); $instructions = array_map("trim",explode("\n",$create->{Create." ".Table})); foreach($instructions as $instruction) { if (SLS_String::startsWith($instruction,"UNIQUE KEY")) { $uniqueColumns = explode(",",SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($instruction,"("),")")); if (count($uniqueColumns) == 2 && in_array("`pk_lang`",$uniqueColumns)) { $uniqueColumn = array_shift($uniqueColumns); if ($uniqueColumn == "`pk_lang`") $uniqueColumn = array_shift($uniqueColumns); $uniquesMultilang[] = str_replace("`","",$uniqueColumn); } } } } // Get FKs to create access reference functions $fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk")); $fkFunctions = ""; $fkCursor = ""; for($i=0 ; $i<$count=count($fks) ; $i++) { $tablePk = $fks[$i]["attributes"][1]["value"]; $functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),""); $functionName{0} = strtolower($functionName{0}); $functionNameModified = $functionName; while(in_array($functionNameModified,$fkMethods)) $functionNameModified = $functionName."_".($fkCursor = (empty($fkCursor)) ? 2 : $fkCursor+1); $fkMethods[] = $functionNameModified; $fkFunctions .= "'".$functionNameModified."'"; if ($i < ($count - 1)) $fkFunctions .= ", "; } $contentM .= t(1).'protected $_fks = array('.$fkFunctions.');'."\n"; $contentM .= t(1).'public $_typeErrors = array();'."\n\n". t(1).'/**'."\n". t(1).' * Constructor '.$className.''."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @param bool $mutlilanguage true if multilanguage content, else false'."\n". t(1).' */'."\n". t(1).'public function __construct($multilanguage='.$multiLanguage.')'."\n". t(1).'{'."\n". t(2).'parent::__construct($multilanguage);'."\n". t(2).'$this->buildDefaultValues();'."\n". t(1).'}'."\n\n"; $contentM .= t(1).'/**'."\n". t(1).' * Build default values for specific columns'."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' */'."\n". t(1).'public function buildDefaultValues()'."\n". t(1).'{'."\n"; for($i=0 ; $i<$count=count($columns) ; $i++) { $columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type; $functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",SLS_String::removePhpChars($columns[$i]->Field))," ",false)),""); if ($columns[$i]->Null == "NO") { // Dates if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp" || $columnType == "year" || $columnType == "time") { switch ($columnType) { case "date": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d");'."\n"; break; case "time": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("H:i:s");'."\n"; break; case "datetime": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n"; break; case "timestamp": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n"; break; case "year": $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y");'."\n"; break; } } // Uniqid $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and @type='uniqid']"); if (!empty($result)) { $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n"; } // IP Address $result = array_shift($xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and (@type='ip_both' or @type='ip_v4' or @type='ip_v6')]/@type")); if (!empty($result)) { $contentM .= t(2).'$this->__'.$columns[$i]->Field.' = $_SERVER["REMOTE_ADDR"];'."\n"; } } } $contentM .= t(1).'}'."\n\n"; for($i=0 ; $i<$count=count($columns) ; $i++) { $isPassword = false; if ($columns[$i]->Key != "PRI") { $column = SLS_String::removePhpChars($columns[$i]->Field); $columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type; $functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$column)," ",false)),""); $contentM .= t(1).'/**'."\n". t(1).' * Set the value of '.$column.''."\n". t(1).' * Errors can be catched with the public variable $this->_typeErrors[\''.$column.'\']'."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @param '.$arrayConvertTypes[$columnType].' $value'."\n". t(1).' * @return bool true if updated, false if not'."\n". t(1).' */'."\n". t(1).'public function '.$functionName.'($value'; if ($columns[$i]->Default !== null) $contentM .= '="'.SLS_String::addSlashesToString($columns[$i]->Default,false).'"'; $contentM .= ')'."\n"; $contentM .= t(1).'{'."\n"; // Nullable case if ($columns[$i]->Null == "YES") { $contentM .= t(2).'if (empty($value))'."\n". t(2).'{'."\n". t(3).'$this->__set(\''.$column.'\', $value);'."\n". t(3).'$this->flushError(\''.$column.'\');'."\n". t(3).'return true;'."\n". t(2).'}'."\n\n"; } // Recover Fk $res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$tableName,$column)); if (!empty($res)) { $tableTm = substr($res,(strpos($res,'tablePk="')+9),(strpos($res,'"/>')-(strpos($res,'tablePk="')+9))); $tablePk = SLS_String::substrAfterFirstDelimiter($tableTm,"_"); $dbPk = SLS_String::substrBeforeFirstDelimiter($tableTm,"_"); $contentM .= t(2).'$this->_generic->useModel("'.SLS_String::tableToClass($tablePk).'","'.$dbPk.'","user");'."\n". t(2).'$object = new '.ucfirst($dbPk).'_'.SLS_String::tableToClass($tablePk).'();'."\n". t(2).'if ($object->getModel($value) === false)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_KEY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n". t(2).'$this->__set(\''.$column.'\', $value);'."\n". t(2).'$this->flushError(\''.$column.'\');'."\n". t(2).'return true;'."\n". t(1).'}'."\n\n"; } // If not a fk else { // Check filters $results = $xmlFilter->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@filter"); for($j=0 ; $j<$countJ=count($results) ; $j++) { switch($results[$j]) { case "hash": $isPassword = true; $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = $this->__'.$column.';'."\n"; break; default: $contentM .= t(2).'$value = SLS_String::filter($value,"'.$results[$j].'");'."\n"; break; } } if (count($results) > 0) $contentM .= "\n"; $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']"); // Force specific type numeric if ($this->containsRecursive($columnType,array("int","float","double","decimal","real"))) { $typeExists =($xmlType->getTag("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@type")); if (empty($typeExists)) { file_get_contents($this->_generic->getFullPath("SLS_Bo", "AddType", array("name" => strtolower($db."_".$tableName), "column" => $column, "reload" => "true", "type" => "num", "num" => (SLS_String::contains($columns[$i]->Type,"unsigned")) ? "gte" : "all", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); $xmlType->refresh(); } } if (!empty($result)) { $type = ""; $array = array('color','uniqid','email','ip_both','ip_v4','ip_v6','url','file_all','file_img','position','num_all','num_gt','num_gte','num_lt','num_lte','complexity'); for($j=0 ; $j<count($array) ; $j++) { $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."' and @type='".$array[$j]."']"); if (!empty($result)) { $type = $array[$j]; switch($type) { case "position": $contentM .= t(2).'if ($value == "" || $value == null || !is_int(intval($value)) || intval($value) < 0)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'$qbd = new SLS_QueryBuilder();'."\n". t(2).'$old_'.$column.' = $this->__'.$column.';'."\n". t(2).'if (empty($old_'.$column.'))'."\n". t(2).'{'."\n". t(3).'$qbd->update()'."\n". t(4).'->from("'.$tableName.'")'."\n". t(4).'->set("`'.$column.'` = `'.$column.'` + 1")'."\n". t(4).'->where($qbd->expr()->gte("'.$column.'",$value))'."\n". t(4).'->groupBy("`'.$primaryKey.'`")'."\n". t(4).'->execute();'."\n". t(2).'}'."\n". t(2).'else'."\n". t(2).'{'."\n". t(3).'if ($old_'.$column.' != $value)'."\n". t(3).'{'."\n". t(4).'$qbd->update()'."\n". t(5).'->from("'.$tableName.'")'."\n". t(5).'->set("`'.$column.'` = `'.$column.'` ".(($old_'.$column.' < $value) ? "-" : "+")." 1")'."\n". t(5).'->where($qbd->expr()->{($old_'.$column.' < $value) ? "gt" : "gte"}("'.$column.'",($old_'.$column.' < $value) ? $old_'.$column.' : $value))'."\n". t(5).'->whereAnd($qbd->expr()->{($old_'.$column.' < $value) ? "lte" : "lt"}("'.$column.'",($old_'.$column.' < $value) ? $value : $old_'.$column.'))'."\n". t(5).'->groupBy("`'.$primaryKey.'`")'."\n". t(5).'->execute();'."\n". t(4).'$qbd->update()'."\n". t(5).'->from("'.$tableName.'")'."\n". t(5).'->set($qbd->expr()->eq("'.$column.'",$value))'."\n". t(5).'->where($qbd->expr()->eq("'.$primaryKey.'",$this->__'.$primaryKey.'))'."\n". t(5).'->groupBy("`'.$primaryKey.'`")'."\n". t(5).'->execute();'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; case "color": $contentM .= t(2).'if (!ctype_xdigit($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "uniqid": $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n\n"; break; case "email": $contentM .= t(2).'if (!SLS_String::validateEmail($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "url": $contentM .= t(2).'if (!SLS_String::isValidUrl($value))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case (in_array($type,array("ip_both","ip_v4","ip_v6"))): $type = SLS_String::substrAfterLastDelimiter($type,"_"); $contentM .= t(2).'if (empty($value))'."\n". t(3).'$value = $_SERVER["REMOTE_ADDR"];'."\n\n"; $contentM .= t(2).'if (!SLS_String::isIp($value,"'.$type.'"))'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case (in_array($type,array("num_all","num_gt","num_gte","num_lt","num_lte"))): $type = SLS_String::substrAfterLastDelimiter($type,"_"); switch($type) { case "gt": $operator = "<="; break; case "gte": $operator = "<"; break; case "lt": $operator = ">="; break; case "lte": $operator = ">"; break; } if ($type != 'all') { $contentM .= t(2).'if ($value '.$operator.' 0)'."\n"; $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } break; case "complexity": $rules = $xmlType->getTag("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@rules"); $rules = explode("|",$rules); $complexityMin = false; foreach($rules as $rule) { if (SLS_String::startsWith($rule,"min")) { $complexityMin = SLS_String::substrAfterFirstDelimiter($rule,"min"); unset($rules[array_shift(array_keys($rules,$rule))]); } else $rules[array_shift(array_keys($rules,$rule))] = '"'.$rule.'"'; } $rules = implode(",",$rules); $contentM .= t(2).'$complexity = array('.$rules.');'."\n". t(2).'if ((in_array("lc",$complexity) && preg_match(\'`[[:lower:]]`\', $value) === 0) || (in_array("uc",$complexity) && preg_match(\'`[[:upper:]]`\', $value) === 0) || (in_array("digit",$complexity) && preg_match(\'`[[:digit:]]`\', $value) === 0) || (in_array("wild",$complexity) && preg_match(\'`[^a-zA-Z0-9]`\', $value) === 0))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_COMPLEXITY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; if (is_numeric($complexityMin)) $contentM .= t(2).'if (strlen(utf8_decode($value)) < '.$complexityMin.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "file_all": $contentM .= t(2).'if (!empty($this->__'.$column.') && $this->__'.$column.' != "'.$columns[$i]->Default.'" && $this->__'.$column.' != $value && SLS_String::startsWith((is_array($value)) ? ((array_key_exists("data",$value)) ? $value["data"]["tmp_name"] : $value["tmp_name"]) : $value, $this->getTable()."/"))'."\n". t(2).'{'."\n". t(3).'$this->deleteFiles(array("'.$column.'"));'."\n". t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n". t(3).'$this->save();'."\n". t(2).'}'."\n\n". t(2).'if (is_array($value))'."\n". t(2).'{'."\n". t(3).'if (array_key_exists("size",$value) && is_array($value["size"]))'."\n". t(4).'$size = $value["size"];'."\n". t(3).'if (array_key_exists("data",$value))'."\n". t(4).'$value = $value["data"];'."\n"; if ($columns[$i]->Null == "YES") $contentM .= t(3).'if ($value["error"] == 4)'."\n". t(3).'{'."\n". t(4).'$this->__set(\''.$column.'\',(empty($this->__'.$column.')) ? "" : $this->__'.$column.');'."\n". t(4).'$this->flushError(\''.$column.'\');'."\n". t(4).'return true;'."\n". t(3).'}'."\n"; $contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(3).'else'."\n". t(3).'{'."\n". t(4).'try {'."\n". t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n". t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n". t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n". t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token.".".SLS_String::substrAfterLastDelimiter($value["name"],".");'."\n". t(5).'rename($value["tmp_name"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName);'."\n". t(5).'$value = $this->_table."/".$fileName;'."\n". t(4).'}'."\n". t(4).'catch (Exception $e) {'."\n". t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_WRITE";'."\n". t(5).'return false;'."\n". t(4).'}'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; case "file_img": $contentM .= t(2).'if (!empty($this->__'.$column.') && $this->__'.$column.' != "'.$columns[$i]->Default.'" && $this->__'.$column.' != $value && SLS_String::startsWith((is_array($value)) ? ((array_key_exists("data",$value)) ? $value["data"]["tmp_name"] : $value["tmp_name"]) : $value, $this->getTable()."/"))'."\n". t(2).'{'."\n". t(3).'$this->deleteFiles(array("'.$column.'"));'."\n". t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n". t(3).'$this->save();'."\n". t(2).'}'."\n\n". t(2).'if (is_array($value))'."\n". t(2).'{'."\n". t(3).'if (array_key_exists("size",$value) && is_array($value["size"]))'."\n". t(4).'$size = $value["size"];'."\n". t(3).'if (array_key_exists("data",$value))'."\n". t(4).'$value = $value["data"];'."\n"; if ($columns[$i]->Null == "YES") $contentM .= t(3).'if ($value["error"] == 4)'."\n". t(3).'{'."\n". t(4).'$this->__set(\''.$column.'\',(empty($this->__'.$column.')) ? "" : $this->__'.$column.');'."\n". t(4).'$this->flushError(\''.$column.'\');'."\n". t(4).'return true;'."\n". t(3).'}'."\n"; $contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(3).'else'."\n". t(3).'{'."\n". t(4).'try {'."\n". t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n". t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n". t(5).'$tmpName = $value["tmp_name"];'."\n". t(5).'if (!SLS_String::startsWith($tmpName,$this->_generic->getPathConfig("files")) || !SLS_String::contains($tmpName,"."))'."\n". t(5).'{'."\n". t(6).'if (!file_exists($this->_generic->getPathConfig("files")."__Uploads"))'."\n". t(7).'@mkdir($this->_generic->getPathConfig("files")."__Uploads");'."\n". t(6).'if (!file_exists($this->_generic->getPathConfig("files")."__Uploads/__Deprecated"))'."\n". t(7).'@mkdir($this->_generic->getPathConfig("files")."__Uploads/__Deprecated");'."\n". t(6).'$newName = $this->_generic->getPathConfig("files")."__Uploads/__Deprecated/".SLS_String::substrAfterLastDelimiter($tmpName,"/").((!SLS_String::contains($tmpName,".")) ? ".".SLS_String::substrAfterLastDelimiter($value["name"],".") : "");'."\n". t(6).'rename($tmpName,$newName);'."\n". t(6).'$tmpName = $newName;'."\n". t(5).'}'."\n". t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n". t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token;'."\n". t(5).'$extension = pathinfo($tmpName, PATHINFO_EXTENSION);'."\n\n". t(5).'// Check img'."\n". t(5).'$img = new SLS_Image($tmpName);'."\n". t(5).'if ($img->getParam("existed"))'."\n". t(5).'{'."\n". t(6).'// Default crop'."\n". t(6).'if (empty($size))'."\n". t(7).'$size = array("x" => "0", "y" => "0", "w" => $img->getParam("width"), "h" => $img->getParam("height"));'."\n\n". t(6).'// Crop image'."\n". t(6).'$img->crop($size["x"],$size["y"],$size["w"],$size["h"]);'."\n". t(6).'// Check thumbs'."\n". t(6).'$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));'."\n". t(6).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$this->getDatabase()."_".$this->getTable()."\' and @column=\''.$column.'\' and @type=\'file_img\']","thumbs"));'."\n". t(6).'$thumbs = unserialize(str_replace("||#||",\'"\',$result["attribute"]));'."\n". t(6).'if (!empty($thumbs))'."\n". t(6).'{'."\n". t(7).'for($i=0 ; $i<$count=count($thumbs) ; $i++)'."\n". t(7).'{'."\n". t(8).'$img->transform($thumbs[$i]["width"],$thumbs[$i]["height"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName.$thumbs[$i]["suffix"].".".$extension,$extension);'."\n". t(7).'}'."\n". t(6).'}'."\n\n". t(6).'// Move original'."\n". t(6).'rename($tmpName,$this->_generic->getPathConfig("files").$this->_table."/".$fileName.".".$extension);'."\n". t(5).'}'."\n". t(5).'else'."\n". t(5).'{'."\n". t(6).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(6).'return false;'."\n". t(5).'}'."\n". t(5).'$value = $this->_table."/".$fileName.".".$extension;'."\n". t(4).'}'."\n". t(4).'catch (Exception $e) {'."\n". t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_WRITE";'."\n". t(5).'return false;'."\n". t(4).'}'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; break; } break; } } } // Not Nullable if ($columns[$i]->Null == "NO") { $contentM .= t(2).'if ($value === "")'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_EMPTY";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } if ($isPassword) { $result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']","hash")); $hash = (empty($result["attribute"])) ? "sha1" : $result["attribute"]; $contentM .= t(2).'if ($value != $this->__'.$column.')'."\n". t(3).'$value = SLS_String::filter($value,"hash","'.$hash.'");'."\n\n"; } // Not Nullable if ($columns[$i]->Null == "NO") { $contentM .= t(2).'if (is_null($value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_NULL";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Check change $contentM .= t(2).'if ($this->__'.$column.' == $value)'."\n". t(2).'{'."\n". t(3).'$this->flushError(\''.$column.'\');'."\n". t(3).'return true;'."\n". t(2).'}'."\n\n"; // Unique if ($columns[$i]->Key == "UNI" || in_array($column,$uniquesMultilang)) { $contentM .= t(2).'if (!$this->isUnique(\''.SLS_String::addSlashes($column, 'QUOTES').'\',$value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_UNIQUE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Float types if (SLS_String::startsWith($columnType,"float") || SLS_String::startsWith($columnType,"double") || SLS_String::startsWith($columnType,"decimal")) { $length = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ')'), '('), ","); if (empty($length)) $length = "25"; $contentM .= t(2).'$decimal = (strpos($value, \',\')) ? str_replace(\',\', \'.\', $value) : (!strpos($value, \'.\')) ? $value.\'.0\' : $value;'."\n". t(2).'if (!is_numeric($decimal))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'if ((strlen($decimal)-1) > '.$length.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } // Enum types else if ($columnType == "enum" || $columnType == "set") { $values = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, "')"), "('"); if ($columnType == "enum") { $contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n". t(2).'if (!in_array($value, $values))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else { $contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n". t(2).'$valueE = explode(",",$value);'."\n". t(2).'foreach($valueE as $set)'."\n". t(2).'{'."\n". t(3).'if (!in_array($set, $values))'."\n". t(3).'{'."\n". t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n". t(4).'return false;'."\n". t(3).'}'."\n". t(2).'}'."\n\n"; } } else { if (strpos($columns[$i]->Type, "(")) { $length = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ")"), "("); $contentM .= t(2).'if (strlen(utf8_decode($value)) > '.$length.')'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } if(SLS_String::endsWith($columnType, "int")) { $contentM .= t(2).'if (!is_numeric($value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp") { switch ($columnType) { case "date": $contentM .= t(2).'if (!SLS_Date::isDate($value))'."\n"; break; case "datetime": $contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n"; break; case "timestamp": $contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n"; break; } $contentM .= t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; } else if ($columnType == "time" || $columnType == "year") { switch ($columnType) { case "time": $contentM .= t(2).'if (strpos(\':\', $value) && substr_count($value, \':\') != 2)'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n". t(2).'$check = explode(\':\', $value);'."\n". t(2).'if (count($check) == 1 && !is_numeric($check[0]))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n". t(2).'else if ((count($check) > 1) && (!is_numeric($check[0]) || (!is_numeric($check[1]) || strlen($check[1]) > 2) || (!is_numeric($check[2]) || strlen($check[2]) > 2)))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; case "year": $contentM .= t(2).'if (!mktime(0, 0, 0, 0, 0, $value))'."\n". t(2).'{'."\n". t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n". t(3).'return false;'."\n". t(2).'}'."\n\n"; break; } } } $contentM .= t(2).'$this->__set(\''.$column.'\', $value);'."\n". t(2).'$this->flushError(\''.$column.'\');'."\n". t(2).'return true;'."\n". t(1).'}'."\n\n"; } } } // Get FKs to create access reference functions $fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk")); $fkMethods = array(); $fkCursor = ""; for($i=0 ; $i<$count=count($fks) ; $i++) { $columnFk = $fks[$i]["attributes"][0]["value"]; $tablePk = $fks[$i]["attributes"][1]["value"]; $functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),""); $functionName{0} = strtolower($functionName{0}); $functionNameModified = $functionName; while(in_array($functionNameModified,$fkMethods)) $functionNameModified = $functionName."_".($fkCursor = (empty($fkCursor)) ? 2 : $fkCursor+1); $fkMethods[] = $functionNameModified; $contentM .= t(1).'/**'."\n". t(1).' * Get the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model described by '.$columnFk.''."\n". t(1).' * @author SillySmart'."\n". t(1).' * @copyright SillySmart'."\n". t(1).' * @return '.SLS_String::tableToClass($tablePk).' $object the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model'."\n". t(1).' */'."\n". t(1).'public function '.$functionNameModified.'()'."\n". t(1).'{'."\n". t(2).'$this->_generic->useModel("'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'","'.SLS_String::substrBeforeFirstDelimiter($tablePk,"_").'","user");'."\n". t(2).'$object = new '.ucfirst(SLS_String::substrBeforeFirstDelimiter($tablePk,"_")).'_'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'();'."\n". t(2).'$object->getModel($this->__'.$columnFk.');'."\n". t(2).'return $object;'."\n". t(1).'}'; $contentM .= ($i == ($count-1)) ? "\n" : "\n\n"; } $contentM .= '}'."\n". '?>'; return $contentM; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $langs = $this->_generic->getObjectLang()->getSiteLangs(); $errors = array(); $siteXML = $this->_generic->getSiteXML(); $aliasesSelected = array(); $componentsSelected = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; $controllersXML = $this->_generic->getControllersXML(); $metasXML = $this->_generic->getCoreXML('metas'); $controller = $this->_http->getParam('Controller'); $action = $this->_http->getParam('Action'); $actionExist = $controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']"); $actionId = array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@id")); $protocol = $this->_generic->getActionProtocol($actionId); if (count($actionExist) == 1) { $aliasesChecked = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']",array("domains"))); if (!empty($aliasesChecked)) { $alias = explode(",",$aliasesChecked["attributes"][0]["value"]); foreach($alias as $cur_alias) array_push($aliasesSelected,$cur_alias); } $componentsChecked = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']",array("components"))); if (!empty($componentsChecked)) { $component = explode(",",$componentsChecked["attributes"][0]["value"]); foreach($component as $cur_component) array_push($componentsSelected,$cur_component); } $reload = $this->_http->getParam("reload"); if ($reload == 'true') { $oldAction = SLS_String::trimSlashesFromString($this->_http->getParam("genericName")); $newAction = SLS_String::stringToUrl(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("actionName"))), "", false); $needDynamic = SLS_String::trimSlashesFromString($this->_http->getParam("dynamic")); $needOffline = SLS_String::trimSlashesFromString($this->_http->getParam("offline")); $needDefault = SLS_String::trimSlashesFromString($this->_http->getParam("default")); $searchEngine = SLS_String::trimSlashesFromString($this->_http->getParam("indexes")); $postProtocol = SLS_String::trimSlashesFromString($this->_http->getParam("protocol")); $tpl = SLS_String::trimSlashesFromString($this->_http->getParam('template')); $aliases = SLS_String::trimSlashesFromString($this->_http->getParam('domains')); $components = SLS_String::trimSlashesFromString($this->_http->getParam('components')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_scope = SLS_String::trimSlashesFromString($this->_http->getParam('cache_scope')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); $toCache = (in_array($cache_visibility,array("public","private"))) ? true : false; if ($controller == "Home" && $action == "Index") { $needDefault = "true"; $newAction = $oldAction; } // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } $postActionsLang = array(); $postTitlesLang = array(); $postDescriptionsLang = array(); $postKeywordsLang = array(); // Save Form informations $xml->startTag("form"); $xml->addFullTag("actionName", $newAction, true); foreach ($langs as $lang) { $postLang = trim(SLS_String::stringToUrl(SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-action")), "", false)); $postOldLang = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-oldAction")); if ($postLang != $oldAction) { $translationExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name != '".$oldAction."']/scontrollerLangs[scontrollerLang = '".$postLang."']"); if (empty($postLang)) array_push($errors, "You need to fill the ".$lang." url translations"); elseif(count($translationExist) != 0) array_push($errors, "You URL translation in ".$lang." is already in use on another action in the same controller"); else $postActionsLang[$lang] = $postLang; } // Get Titles $postTitlesLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-title")); $postDescriptionsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-description")); $postKeywordsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-keywords")); $xml->addFullTag($lang."-action", $postLang, true); $xml->addFullTag($lang."-title", $postTitlesLang[$lang], true); $xml->addFullTag($lang."-description", $postDescriptionsLang[$lang], true); $xml->addFullTag($lang."-keywords", $postKeywordsLang[$lang], true); } $xml->endTag("form"); if (empty($postProtocol) || ($postProtocol != 'http' && $postProtocol != 'https')) array_push($errors, "Protocol must be http or https"); else $protocol = $postProtocol; if (!empty($aliases) && is_array($aliases)) { $aliasesSelected = array(); foreach($aliases as $alias) array_push($aliasesSelected,$alias); } else { $aliasesSelected = array(); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('domains' => '')); } if ($toCache && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); if ($toCache && (!in_array($cache_scope,array("full","partial")))) array_push($errors, "Your must describe your cache scope"); if ($toCache && is_numeric($cache_expiration) && $cache_expiration >= 0 && in_array($cache_scope,array("full","partial"))) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('cache' => $cache_visibility.'|'.$cache_scope.'|'.(($cache_responsive == 'true') ? 'responsive' : 'no_responsive').'|'.$cache_expiration)); if (!$toCache) $controllersXML->deleteTagAttribute("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']","cache"); if (!empty($components) && is_array($components)) { $componentsSelected = array(); foreach($components as $component) array_push($componentsSelected,$component); } else { $componentsSelected = array(); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('components' => '')); } if ((($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) && ($oldAction != $newAction)) { $newNameExist = $controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$newAction."']"); if (count($newNameExist) != 0) array_push($errors, "The generic action name is already in use in this controller"); } else $newAction = $oldAction; if (empty($newAction)) array_push($errors, "Action name can't be empty."); if (!empty($aliases)) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('domains' => implode(",",$aliasesSelected))); if (!empty($components)) $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('components' => implode(",",$componentsSelected))); $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."' and @id='".$actionId."']", array('disable' => (empty($needOffline)) ? '0' : '1')); if ($tpl == -1) $controllersXML->deleteTagAttribute("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']", "tpl"); else $controllersXML->setTagAttributes("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']", array('tpl' => $tpl)); file_put_contents($this->_generic->getPathConfig('configSecure')."controllers.xml", $controllersXML->getXML()); $dynamic = (($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) ? ($needDynamic == 'on') ? "1" : "0" : array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and side='user']/scontrollers/scontroller[@name='".$oldAction."']/@needParam")); // If no errors if (empty($errors)) { // If default, reset other in current controller if (!empty($needDefault)) { $actions = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/@id"); foreach($actions as $curActionId) $controllersXML->setTagAttributes("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@id='".$curActionId."']", array('default' => '0')); } $controllersXML->setTagAttributes("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']", array("name"=>$newAction,"needParam"=>$dynamic,'protocol'=>$protocol,"default"=>(empty($needDefault) ? '0' : '1'))); foreach ($langs as $lang) { if (array_key_exists($lang, $postActionsLang)) $controllersXML->setTag("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']", $postActionsLang[$lang], true); else $controllersXML->setTag("//controllers/controller/scontrollers/scontroller[@id='".$actionId."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']", SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-oldAction")), true); } // If generic name is not the same, we modify all files if ($oldAction != $newAction) { // Controller $contentController = file_get_contents($this->_generic->getPathConfig('actionsControllers').$controller."/".$oldAction.".controller.php"); $contentController = str_replace(array(0=>" ".$controller.$oldAction." ", 1=>" ".$oldAction." "), array(0=>" ".$controller.$newAction." ", 1=>" ".$newAction." "), $contentController); file_put_contents($this->_generic->getPathConfig('actionsControllers').$controller."/".$newAction.".controller.php", $contentController); unlink($this->_generic->getPathConfig('actionsControllers').$controller."/".$oldAction.".controller.php"); //Langs foreach ($langs as $lang) { $contentLang = file_get_contents($this->_generic->getPathConfig('actionLangs').$controller."/".$oldAction.".".$lang.".lang.php"); $contentLang = str_replace(array(0=>" ".$controller.$oldAction." ", 1=>" ".$oldAction." "), array(0=>" ".$controller.$newAction." ", 1=>" ".$newAction." "), $contentLang); file_put_contents($this->_generic->getPathConfig('actionLangs').$controller."/".$newAction.".".$lang.".lang.php", $contentLang); unlink($this->_generic->getPathConfig('actionLangs').$controller."/".$oldAction.".".$lang.".lang.php"); } // Views // Body $contentBody = file_get_contents($this->_generic->getPathConfig('viewsBody').$controller."/".$oldAction.".xsl"); $contentBody = str_replace(array(0=>"name=\"".$oldAction."\">", 1=>$oldAction.".xsl"), array(0=>"name=\"".$newAction."\">", 1=>$newAction.".xsl"), $contentBody); file_put_contents($this->_generic->getPathConfig('viewsBody').$controller."/".$newAction.".xsl", $contentBody); unlink($this->_generic->getPathConfig('viewsBody').$controller."/".$oldAction.".xsl"); // Headers $contentHeader = file_get_contents($this->_generic->getPathConfig('viewsHeaders').$controller."/".$oldAction.".xsl"); $contentHeader = str_replace(array(0=>"name=\"Header".$oldAction."\">"), array(0=>"name=\"Header".$newAction."\">"), $contentHeader); file_put_contents($this->_generic->getPathConfig('viewsHeaders').$controller."/".$newAction.".xsl", $contentHeader); unlink($this->_generic->getPathConfig('viewsHeaders').$controller."/".$oldAction.".xsl"); } // We now update the XML foreach ($langs as $lang) { // Metas $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/title[@lang='".$lang."']", $postTitlesLang[$lang], true); $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/description[@lang='".$lang."']", $postDescriptionsLang[$lang], true); $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/keywords[@lang='".$lang."']", $postKeywordsLang[$lang], true); } if (!SLS_String::contains($searchEngine,", ")) $searchEngine = str_replace(",",", ",$searchEngine); if ($searchEngine != "index, follow" && $searchEngine != "noindex, follow" && $searchEngine != "noindex, nofollow" && $searchEngine != "index, nofollow") $searchEngine = "index, follow"; $metasXML->setTag("//sls_configs/action[@id='".$actionId."']/robots", $searchEngine, true); file_put_contents($this->_generic->getPathConfig("configSecure")."controllers.xml", $controllersXML->getXML()); file_put_contents($this->_generic->getPathConfig("configSls")."metas.xml", $metasXML->getXML()); } if (count($errors) != 0) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); } $xml->startTag("cache"); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_scope", $cache_scope,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->addFullTag("cache_responsive", $cache_responsive,true); $xml->endTag("cache"); } else { $actionCache = $this->_cache->getAction($actionId); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", (is_array($actionCache)) ? $actionCache[0] : "",true); $xml->addFullTag("cache_scope", (is_array($actionCache)) ? $actionCache[1] : "",true); $xml->addFullTag("cache_expiration", (is_array($actionCache)) ? $actionCache[3] : "",true); $xml->addFullTag("cache_responsive", (is_array($actionCache)) ? (($actionCache[2]=="responsive") ? "true" : "") : "",true); $xml->endTag("cache"); } $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@tpl"); if (empty($tpl)) $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/@tpl"); $controllersXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSecure")."controllers.xml")); $xml->startTag("action"); $xml->addFullTag("name", $action, true); $xml->addFullTag("dynamic", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@needParam")) == '1') ? 'true' : 'false', true); $xml->addFullTag("offline", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@disable")) == '1') ? 'true' : 'false', true); $xml->addFullTag("default", (array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/@default")) == '1') ? 'true' : 'false', true); $xml->addFullTag("indexes", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/robots")), true); $xml->addFullTag("canBeModified", (($controller != 'Home' && $controller != 'Default') || (($controller == 'Home' && $action != 'Index') || ($controller == 'Default' && ($action != 'UrlError' && $action != 'BadRequestError' && $action != 'AuthorizationError' && $action != 'ForbiddenError' && $action != 'InternalServerError' && $action != 'TemporaryRedirectError' && $action != 'MaintenanceError')))) ? 'true' : 'false', true); $xml->startTag("translations"); foreach ($langs as $lang) { $xml->startTag("translation"); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", array_shift($controllersXML->getTags("//controllers/controller[@name='".$controller."' and @side='user']/scontrollers/scontroller[@name='".$action."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']")) ,true); $xml->addFullTag("title", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/title[@lang='".$lang."']")),true); $xml->addFullTag("description", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/description[@lang='".$lang."']")),true); $xml->addFullTag("keywords", array_shift($metasXML->getTags("//sls_configs/action[@id='".$actionId."']/keywords[@lang='".$lang."']")),true); $xml->endTag("translation"); } $xml->endTag("translations"); $xml->endTag("action"); $xml->startTag('controller'); $xml->addFullTag("name", $controller, true); $xml->startTag('translations'); foreach ($langs as $lang) { $xml->startTag('translation'); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/controllerLangs/controllerLang[@lang='".$lang."']"), true); $xml->endTag('translation'); } $xml->endTag('translations'); $xml->endTag('controller'); // Build all tpls $tpls = $this->getAppTpls(); $xml->startTag("tpls"); foreach($tpls as $template) $xml->addFullTag("tpl",$template,true); $xml->endTag("tpls"); $xml->addFullTag('request', 'modifyAction', true); $aliases = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); $xml->startTag("aliases"); for($i=0 ; $i<$count=count($aliases) ; $i++) { $xml->startTag("alias"); $xml->addFullTag("name",$aliases[$i]["attributes"][0]["value"],true); $xml->addFullTag("selected",(in_array($aliases[$i]["attributes"][0]["value"],$aliasesSelected)) ? "true" : "false",true); $xml->endTag("alias"); } $xml->endTag("aliases"); $components = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("componentsControllers"), array(), array(0=>"php")); $xml->startTag("components"); foreach ($components as $component) { $xml->startTag("component"); $xml->addFullTag("name", SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),true); $xml->addFullTag("selected",(in_array(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),$componentsSelected)) ? "true" : "false",true); $xml->endTag("component"); } $xml->endTag("components"); } else { $this->_generic->dispatch('SLS_Bo', 'Controllers'); } $xml->addFullTag('protocol', $protocol, true); $xml->addFullTag('template', $tpl, true); $this->saveXML($xml); }
public function action() { $xml = $this->getXML(); $xml = $this->makeMenu($xml); $user = $this->hasAuthorative(); // Objects $sql = SLS_Sql::getInstance(); $properties = array(); $pathsHandleFk = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $pathsHandleType = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $pathsHandleFilter = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandleFk); $xmlType = new SLS_XMLToolbox($pathsHandleType); $xmlFilter = new SLS_XMLToolbox($pathsHandleFilter); // Foreach existing models $models = scandir($this->_generic->getPathConfig("models")); foreach($models as $file) { if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") { $fileExploded = explode(".",$file); if (is_array($fileExploded) && count($fileExploded) == 4) { $db = strtolower($fileExploded[0]); $class = $fileExploded[1]; $className = $db."_".$class; $this->_generic->useModel($class,$db,"user"); $object = new $className(); $table = $object->getTable(); $properties[$db][$table] = array("types" => array(), "filters" => array(), "fks" => array()); $types = $xmlType->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."']",array("column","type","rules")); for($i=0 ; $i<$count=count($types) ; $i++) { $column = $types[$i]["attributes"][0]["value"]; $type = $types[$i]["attributes"][1]["value"]; $rules = $types[$i]["attributes"][2]["value"]; if ($type == "complexity" && !empty($rules)) $type .= " (".$rules.")"; $properties[$db][$table]["types"][$column][] = $type; } $filters = $xmlFilter->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."']",array("column","filter","hash")); for($i=0 ; $i<$count=count($filters) ; $i++) { $column = $filters[$i]["attributes"][0]["value"]; $filter = $filters[$i]["attributes"][1]["value"]; $hash = $filters[$i]["attributes"][2]["value"]; if ($filter == "hash" && !empty($hash)) $filter .= " (".$hash.")"; $properties[$db][$table]["filters"][$column][] = $filter; } $fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$table."']",array("columnFk","tablePk","labelPk")); for($i=0 ; $i<$count=count($fks) ; $i++) { $column = $fks[$i]["attributes"][0]["value"]; $classPk = ucfirst($fks[$i]["attributes"][1]["value"]); $labelPk = $fks[$i]["attributes"][2]["value"]; $tablePk = SLS_String::substrAfterFirstDelimiter($classPk,"_"); $this->_generic->useModel($tablePk,$db,"user"); $objectPk = new $classPk(); $properties[$db][$table]["fks"][$column][] = $objectPk->getTable(); } } } } asort($properties,SORT_REGULAR); uksort($properties,array($this, 'unshiftDefaultDb')); $xml->startTag("dbs"); foreach($properties as $db => $tables) { $xml->startTag("db"); $xml->addFullTag("name",$db,true); $xml->startTag("tables"); foreach($tables as $table => $infos) { $columns = array(); $xml->startTag("table"); $xml->addFullTag("name",$table,true); $xml->startTag("types"); foreach($infos["types"] as $column => $type) { $xml->addFullTag("type",implode(", ",$type),true,array("column"=>$column)); $columns[] = $column; } $xml->endTag("types"); $xml->startTag("filters"); foreach($infos["filters"] as $column => $filter) { $xml->addFullTag("filter",implode(", ",$filter),true,array("column"=>$column)); $columns[] = $column; } $xml->endTag("filters"); $xml->startTag("fks"); foreach($infos["fks"] as $column => $fk) { $xml->addFullTag("fk",implode(", ",$fk),true,array("column"=>$column)); $columns[] = $column; } $xml->endTag("fks"); $xml->startTag("columns"); foreach($columns as $column) $xml->addFullTag("column",$column,true); $xml->endTag("columns"); $xml->endTag("table"); } $xml->endTag("tables"); $xml->endTag("db"); } $xml->endTag("dbs"); $xml->addFullTag("url_type",$this->_generic->getFullPath("SLS_Bo","EditType",array(),false),true); $xml->addFullTag("url_model",$this->_generic->getFullPath("SLS_Bo","EditModel",array(),false),true); $xml->addFullTag("url_fk",$this->_generic->getFullPath("SLS_Bo","EditForeignKey",array(),false),true); $this->saveXML($xml); }
/** * Recursive Fields * * @access private * @param string $xpath the xpath way * @param SLS_XMLToolbox $xml xml object * @return SLS_XMLToolbox $xml xml object * @see SLS_PluginsManager::getFields * @since 1.0 */ private function recursiveFields($xpath, $xml) { $childs = $this->_pluginXML->getChilds($xpath); $fields = array(); $editField = $this->_generic->getTranslatedController('SLS_Bo', 'EditPluginField'); foreach ($childs as $child) { if (array_shift($this->_pluginXML->getTags($xpath."/".$child."/@writable")) == 1) { $tag = array_shift(explode("[", $child)); if (key_exists($tag, $fields)) $fields[$tag]++; else $fields[$tag] = 1; $xml->startTag('field'); $xml->addFullTag('tag', $tag, true); $xml->addFullTag('path', str_replace("/", "|||", str_replace("]", "|#|", str_replace("[", "#|#", str_replace("//", "", $xpath))))."|||".str_replace("]", "|#|", str_replace("[", "#|#", $child)), true); $xml->addFullTag('label', array_shift($this->_pluginXML->getTags($xpath."/".$child."/@label")), true); $xml->addFullTag('clonable', (array_shift($this->_pluginXML->getTags($xpath."/".$child."/@clonable")) == '1') ? 'true' : 'false', true); if (array_shift($this->_pluginXML->getTags($xpath."/".$child."/@clonable")) == '1') { $xml->addFullTag('linkAdd', $editField['protocol']."://".$this->_generic->getSiteConfig('domainName')."/".$editField['controller']."/".$editField['scontroller']."/Action/add/Plugin/".$this->_id."/Field/".str_replace("/", "|||", str_replace("]", "|$|", str_replace("[", "$|$", str_replace("//", "", $xpath))))."|||".str_replace("]", "|$|", str_replace("[", "$|$", $child)).".sls", true); $xml->addFullTag('linkDel', $editField['protocol']."://".$this->_generic->getSiteConfig('domainName')."/".$editField['controller']."/".$editField['scontroller']."/Action/del/Plugin/".$this->_id."/Field/".str_replace("/", "|||", str_replace("]", "|$|", str_replace("[", "$|$", str_replace("//", "", $xpath))))."|||".str_replace("]", "|$|", str_replace("[", "$|$", $child)).".sls", true); } $xml->addFullTag('index', $fields[$tag], true); $xml->addFullTag('value', array_shift($this->_pluginXML->getTags($xpath."/".$child)), true); $xml->addFullTag('alias', array_shift($this->_pluginXML->getTags($xpath."/".$child."/@alias")), true); $type = (array_shift($this->_pluginXML->getTags($xpath."/".$child."/@type")) == "") ? "part" : array_shift($this->_pluginXML->getTags($xpath."/".$child."/@type")); $xml->addFullTag('type', $type, true); if ($type == 'select' || $type == "radio" || $type == "check") { $xml->startTag("values"); $values = explode("|||", array_shift($this->_pluginXML->getTags($xpath."/".$child."/@values"))); foreach ($values as $value) $xml->addFullTag('value', $value, true); $xml->endTag("values"); } if ($this->_pluginXML->countChilds($xpath."/".$child) > 0) $xml = $this->recursiveFields($xpath."/".$child, $xml); $xml->endTag('field'); } } return $xml; }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $column= $this->_http->getParam("column"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $replacements = array('&','>','<','=','"',"'"); $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('='),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); }
/** * Read recursively path & sub-paths to include components files used by currect action controller * * @access private * @param string $path the root path * @param string $type the type ('core' || 'user') * @since 1.0 */ private function recursiveStaticLoading($path, $type) { $controllersXML = $this->_generic->getControllersXML(); if ($this->_isCache) { $staticsHandle = file_get_contents($this->_generic->getPathConfig("configSecure")."cache.xml"); $xmlCache = new SLS_XMLToolbox($staticsHandle); $files = $xmlCache->getTags("//components/".$type."/controller/file"); $names = $xmlCache->getTags("//components/".$type."/controller/name"); for($i=0;$i<count($files);$i++) { $components = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$this->_generic->getActionId()."']",array("components"))); if (!empty($components)) { $components = explode(",",$components["attributes"][0]["value"]); $components = array_map("trim",$components); $components = array_map("strtolower",$components); } else $components = array(); if (empty($components) || in_array(strtolower(trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($names[$i], "/"), "Controller"))),$components)) { $this->_generic->_time_checkpoint = microtime(true); include_once($this->_generic->getRoot().$files[$i]); $name = $names[$i]; $xml = ""; // Component cache enabled ? $componentsName = strtolower(SLS_String::substrBeforeFirstDelimiter($name,"Controller")); $componentsCacheVisibility = $this->_cache->getObject($componentsName,"components","visibility"); $componentsCacheResponsive = $this->_cache->getObject($componentsName,"components","responsive"); $componentsCacheExpiration = $this->_cache->getObject($componentsName,"components","expire"); $componentsCache = false; if ($this->_generic->getSide() == "user" && $this->_generic->getGenericControllerName() != "Default" && !$this->_generic->isBo() && in_array($componentsCacheVisibility,array("public","private"))) { $componentsCache = true; // Partial xml cached if (false !== ($componentsCached = $this->_cache->getCachePartial($componentsCacheExpiration,"component",$componentsName,$componentsCacheVisibility,$componentsCacheResponsive))) { $xml = $componentsCached; $this->_generic->logTime($this->_generic->monitor($this->_generic->_time_checkpoint),"Cache (Partial): Executing Component Controller", "Controller: ".SLS_String::substrBeforeLastDelimiter($name,"Controller"),"Controller Component"); } } if (empty($xml)) { $classObj = new $name(); $xml = $classObj->getXML(); $this->_generic->logTime($this->_generic->monitor($this->_generic->_time_checkpoint),"Executing Component Controller", "Controller: ".SLS_String::substrBeforeLastDelimiter($name,"Controller"),"Controller Component"); // Save partial xml component cache if ($componentsCache) $this->_cache->saveCachePartial($xml,"component",$componentsName,$componentsCacheVisibility,$componentsCacheResponsive); } $this->_xmlToolBox->appendXMLNode("//Components/".$type, $xml); } } } else { $searchedExt = array('php'); $arrayResult = array(); $arrayResult = $this->_generic->recursiveReadDir($path, $arrayResult, $searchedExt); $this->_cacheXML->startTag($type); for($i=0;$i<$count = count($arrayResult);$i++) { $components = array_shift($controllersXML->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id='".$this->_generic->getActionId()."']",array("components"))); if (!empty($components)) { $components = explode(",",$components["attributes"][0]["value"]); $components = array_map("trim",$components); $components = array_map("strtolower",$components); } else $components = array(); $this->_cacheXML->startTag("controller"); include_once($arrayResult[$i]); $componentName = array_shift(explode(".", SLS_String::substrAfterLastDelimiter($arrayResult[$i], "/")))."Controller"; if (class_exists($componentName)) { $this->_cacheXML->addFullTag("file", $arrayResult[$i], true); $this->_cacheXML->addFullTag("name", $componentName, true); if (empty($components) || in_array(strtolower(trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($arrayResult[$i], "/"), ".controller.php"))),$components)) { $this->_generic->_time_checkpoint = microtime(true); $classObj = new $componentName(); $this->_xmlToolBox->appendXMLNode("//Components/".$type, $classObj->getXML()); $this->_generic->logTime($this->_generic->monitor($this->_generic->_time_checkpoint),"Executing Component Controller", "Controller: ".SLS_String::substrBeforeLastDelimiter($componentName,"Controller"),"Controller Component"); } } $this->_cacheXML->endTag("controller"); } $this->_cacheXML->endTag($type); } }
public function action() { $user = $this->hasAuthorative(); $json = array(); $xml = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig('configSls').'fks.xml')); $tableName = $this->_http->getParam('table_name'); $tmp = explode('.', $tableName); if(count($tmp) != 2) die; $slsGraphQueryDbAlias = $tmp[0]; $slsGraphQueryTable = $tmp[1]; $this->sql->changeDb($slsGraphQueryDbAlias); if($this->sql->tableExists($slsGraphQueryTable)) { $json['status'] = 'OK'; $json['fields'] = array(); $fields = $this->sql->showColumns($slsGraphQueryTable); // Get Attributes $getAttributes = $xml->getTagsAttributes('//sls_configs/entry[@tableFk="'.$slsGraphQueryDbAlias."_".$slsGraphQueryTable.'"]', array('columnFk', 'labelPk', 'tablePk')); // Format Attributes $columnFk = array(); $labelPk = array(); $tablePk = array(); for($i = 0; $i < $count = count($getAttributes); $i++) { array_push($columnFk, $getAttributes[$i]['attributes'][0]['value']); array_push($labelPk, $getAttributes[$i]['attributes'][1]['value']); array_push($tablePk, $getAttributes[$i]['attributes'][2]['value']); } foreach($fields as $field) { if(in_array($field->Field, $columnFk)) { $isFk = true; $index = array_search($field->Field, $columnFk); $labelPkValue = $labelPk[$index]; $tablePkValue = $tablePk[$index]; } else { $isFk = false; } array_push($json['fields'], array( 'field_name' => $field->Field, 'field_table' => $slsGraphQueryTable, 'field_label' => $field->Field, 'field_isFk' => $isFk, 'field_labelPk' => $labelPkValue, 'field_tablePk' => empty($tablePkValue) ? '' : $slsGraphQueryDbAlias.'.'.SLS_String::substrAfterFirstDelimiter(strtolower($tablePkValue), '_')) ); } } else{ $json['status'] = 'ERROR'; $json['error'] = "Table doesn't exist"; } echo json_encode($json); die; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $langs = array(); $appli_langs = array(); $handle = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."international.xml")); $step = 0; $errors = array(); $controllerXML = $this->_generic->getControllersXML(); $metaXML = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."metas.xml")); $appli_langs = $this->_generic->getObjectLang()->getSiteLangs(); $defaultLang = $this->_generic->getObjectLang()->getDefaultLang(); // If lang have been choose if ($this->_http->getParam("step") == "1") { $lang1 = SLS_String::trimSlashesFromString($this->_http->getParam("lang")); $lang = array_shift($handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[node()='".$lang1."']/@iso")); if (!in_array($lang,$appli_langs)) { $step = 2; $xml->addFullTag("step","2",true); $xml->addFullTag("lang_to_add",$lang,true); } else { $xml->addFullTag("lang_selected",$lang1,true); $xml->startTag("errors"); $xml->addFullTag("error","This lang already exist in your application",true); $xml->endTag("errors"); } } if ($this->_http->getParam("step") == "2" || $step == 2) { $lang = (empty($lang)) ? $this->_http->getParam("lang_to_add") : $lang; $xml->addFullTag("step","2",true); $xml->addFullTag("lang_to_add",$lang,true); $generics = array( "MONDAY" => "", "TUESDAY" => "", "WEDNESDAY" => "", "THURSDAY" => "", "FRIDAY" => "", "SATURDAY" => "", "SUNDAY" => "", "JANUARY" => "", "FEBRUARY" => "", "MARCH" => "", "APRIL" => "", "MAY" => "", "JUNE" => "", "JULY" => "", "AUGUST" => "", "SEPTEMBER" => "", "OCTOBER" => "", "NOVEMBER" => "", "DECEMBER" => "", "DATE_PATTERN_TIME" => "", "DATE_PATTERN_FULL_TIME" => "", "DATE_PATTERN_DATE" => "", "DATE_PATTERN_MONTH_LITTERAL" => "", "DATE_PATTERN_FULL_LITTERAL" => "", "DATE_PATTERN_FULL_LITTERAL_TIME" => "", "DATE_PATTERN_MONTH_LITTERAL_TIME" => "", "DATE_DIFF_Y" => "", "DATE_DIFF_M" => "", "DATE_DIFF_W" => "", "DATE_DIFF_D" => "", "DATE_DIFF_H" => "", "DATE_DIFF_I" => "", "DATE_DIFF_S" => "", "E_CONTENT" => "", "E_EMPTY" => "", "E_KEY" => "", "E_COMPLEXITY" => "", "E_LENGTH" => "", "E_NULL" => "", "E_UNIQUE" => "", "E_TYPE" => "", "E_SIZE" => "", "E_EXIST" => "", "E_WRITE" => "", "E_LOGGED" => "", "E_AUTHORIZED" => "" ); // Try to recover generic langs from Deployement if (file_exists($this->_generic->getPathConfig("installDeployement")."Langs/Generics/generic.".$lang.".lang.php")) include($this->_generic->getPathConfig("installDeployement")."Langs/Generics/generic.".$lang.".lang.php"); // Set the default value by english or current lang if has been found in Deployement foreach($generics as $key => $value) $generics[$key] = SLS_String::trimSlashesFromString($GLOBALS[$GLOBALS['PROJECT_NAME']]['JS']['SLS_'.$key]); $controllers = array(); // Recover all controllers $controllersA = $controllerXML->getTags("//controllers/controller[@side='user']/@name"); foreach($controllersA as $controller) { $id = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/@id")); $values = array(); foreach($appli_langs as $appli_lang) $values[$appli_lang] = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/controllerLangs/controllerLang[@lang='".$appli_lang."']")); $values[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam($id."_".$lang)); $result = array("id" => $id, "key" => $controller, "values" => $values, "actions" => array()); array_push($controllers,$result); } // Foreach controllers, recover all actions for($i=0 ; $i<$count=count($controllers) ; $i++) { $controller = $controllers[$i]["key"]; $actions = $controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller/@name"); $actionsA = array(); foreach($actions as $action) { $id = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."']/@id")); $values = array(); foreach($appli_langs as $appli_lang) $values[$appli_lang] = array_shift($controllerXML->getTags("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@name='".$action."']/scontrollerLangs/scontrollerLang[@lang='".$appli_lang."']")); $values[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam($id."_".$lang)); $metas = array("title" => array(), "description" => array(), "keywords" => array()); $titles = array(); $descriptions = array(); $keywords = array(); foreach($appli_langs as $appli_lang) { $titles[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/title[@lang='".$appli_lang."']")); $descriptions[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/description[@lang='".$appli_lang."']")); $keywords[$appli_lang] = array_shift($metaXML->getTags("//sls_configs/action[@id='".$id."']/keywords[@lang='".$appli_lang."']")); } $titles[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_title-".$id."_".$lang)); $descriptions[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_description-".$id."_".$lang)); $keywords[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam("meta_keywords-".$id."_".$lang)); $metas["title"] = $titles; $metas["description"] = $descriptions; $metas["keywords"] = $keywords; $result = array("id" => $id,"key" => $action, "values" => $values, "metas" => $metas); array_push($actionsA,$result); } $controllers[$i]["actions"] = $actionsA; } // If informations have been sent, check if it's good if ($this->_http->getParam("reload") == "true") { $mods = array(); $smods = array(); // Get all controllers foreach($this->_http->getParams() as $key => $value) { // Controllers case if (SLS_String::startsWith($key,"c_")) { $id = SLS_String::substrBeforeLastDelimiter($key,"_".$lang); $mod = array_shift($controllerXML->getTags("//controllers/controller[@id='".$id."']/@name")); $mods[$id] = SLS_String::stringToUrl(SLS_String::trimSlashesFromString($value),"",false); if (empty($mods[$id])) array_push($errors,"You have to fill the rewrite of the controller '".$mod."'."); $modsExisted = $controllerXML->getTags("//controllers/controller/controllerLangs/controllerLang"); if (in_array($mods[$id],$modsExisted)) array_push($errors,"The name for rewrite of the controller '".$mod."' is already used, please choose another one."); } // Actions case else if (SLS_String::startsWith($key,"a_")) { $id = SLS_String::substrBeforeLastDelimiter($key,"_".$lang); $smod = array_shift($controllerXML->getTags("//controllers/controller/scontrollers/scontroller[@id='".$id."']/@name")); $mod = array_shift($controllerXML->getTags("//controllers/controller[scontrollers/scontroller[@id='".$id."']]/@name")); $idC = array_shift($controllerXML->getTags("//controllers/controller[scontrollers/scontroller[@id='".$id."']]/@id")); $smods[$id] = SLS_String::stringToUrl(SLS_String::trimSlashesFromString($value),"",false); if (empty($smods[$id])) array_push($errors,"You have to fill the rewrite of the action '".$smod."' (controller '".$mod."')."); $smodsExisted = $controllerXML->getTags("//controllers/controller[@id='".$idC."']/scontrollers/scontroller/scontrollerLangs/scontrollerLang[@lang='".$lang."']"); if (in_array($smods[$id],$smodsExisted)) array_push($errors,"The name for rewrite of the action '".$smod."' (controller '".$mod."') is already used by another action of the same controller, please choose another one."); } // Generics case else if (SLS_String::startsWith($key,"generic_")) { $label = SLS_String::substrAfterFirstDelimiter($key,"generic_"); if (empty($value)) array_push($errors,"You have to fill the content of the variable '".$label."'"); $generics[$label] = strtolower(SLS_String::trimSlashesFromString($value)); } } // If all cool if (empty($errors)) { // controllers.xml foreach($mods as $key => $value) { $str = '<controllerLang lang="'.$lang.'"><![CDATA['.$value.']]></controllerLang>'; $controllerXML->appendXMLNode("//controllers/controller[@id='".$key."']/controllerLangs",$str); } foreach($smods as $key => $value) { $str = '<scontrollerLang lang="'.$lang.'"><![CDATA['.$value.']]></scontrollerLang>'; $controllerXML->appendXMLNode("//controllers/controller/scontrollers/scontroller[@id='".$key."']/scontrollerLangs",$str); // metas.xml $title = SLS_String::trimSlashesFromString($this->_http->getParam("meta_title-".$key."_".$lang)); if (empty($title)) $str = '<title lang="'.$lang.'"/>'; else $str = '<title lang="'.$lang.'"><![CDATA['.$title.']]></title>'; $metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str); $description = SLS_String::trimSlashesFromString($this->_http->getParam("meta_description-".$key."_".$lang)); if (empty($description)) $str = '<description lang="'.$lang.'"/>'; else $str = '<description lang="'.$lang.'"><![CDATA['.$description.']]></description>'; $metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str); $keyword = SLS_String::trimSlashesFromString($this->_http->getParam("meta_keywords-".$key."_".$lang)); if (empty($keyword)) $str = '<keywords lang="'.$lang.'"/>'; else $str = '<keywords lang="'.$lang.'"><![CDATA['.$keyword.']]></keywords>'; $metaXML->appendXMLNode("//sls_configs/action[@id='".$key."']",$str); // /metas.xml } $controllerXML->saveXML($this->_generic->getPathConfig("configSecure")."controllers.xml"); $metaXML->saveXML($this->_generic->getPathConfig("configSls")."metas.xml"); // /controllers.xml // site.xml $siteXML = $this->_generic->getSiteXML(); $str = '<name isSecure="false" js="false" active="false"><![CDATA['.$lang.']]></name>'; $siteXML->appendXMLNode("//configs/langs",$str); $siteXML->saveXML($this->_generic->getPathConfig("configSecure")."site.xml"); // /site.xml // generic.iso.lang.php $fileContent = '<?php'."\n". '/**'."\n". ' * Generic Sls Vars'."\n". ' */'."\n"; foreach($generics as $key => $value) $fileContent .= '$GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_'.$key.'\'] = "'.str_replace('"','\"',$value).'";'."\n"; $fileContent .= '?>'; file_put_contents($this->_generic->getPathConfig("coreGenericLangs")."generic.".$lang.".lang.php",$fileContent); // /generic.iso.lang.php // site.iso.lang.php $fileContent = '<?php'."\n". '/**'."\n". ' * SillySmart Translations'."\n". ' * Language : '.array_shift($handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[node()='".$lang."']/@iso")).' ('.strtoupper($lang).')'."\n". ' */'."\n\n". '?>'; file_put_contents($this->_generic->getPathConfig("genericLangs")."site.".$lang.".lang.php",str_replace(array("Translations in '".strtoupper($defaultLang)."'","site.".$defaultLang.".lang.php","sentence in ".strtoupper($defaultLang)),array("Translations in '".strtoupper($lang)."'","site.".$lang.".lang.php","sentence in ".strtoupper($lang)),file_get_contents($this->_generic->getPathConfig("genericLangs")."site.".$defaultLang.".lang.php"))); // /site.iso.lang.php // Actions langs files $directories = array(); foreach($mods as $key => $value) array_push($directories,array_shift($controllerXML->getTags("//controllers/controller[@id='".$key."']/@name"))); $this->copyActionsLang($directories,$lang); // /Actions langs files // User_Bo langs $controllerBo = $controllerXML->getTag("//controllers/controller[@side='user' and @isBo='true']/@name"); if (!empty($controllerBo)) { if (file_exists($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.".$lang.".lang.php")) $langContent = str_replace(array("{{USER_BO}}"),array($controllerBo),file_get_contents($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.".$lang.".lang.php")); else $langContent = str_replace(array("{{USER_BO}}"),array($controllerBo),file_get_contents($this->_generic->getPathConfig("installDeployement")."Langs/Actions/{{USER_BO}}/__{{USER_BO}}.en.lang.php")); if (!empty($langContent)) file_put_contents($this->_generic->getPathConfig("actionLangs").$controllerBo."/__".$controllerBo.".".$lang.".lang.php",$langContent); } // MySQL multilanguage tables $handle = opendir($this->_generic->getPathConfig("models")); // Disable explain SLS_Sql::getInstance()->_explain = false; // Foreach models while (false !== ($file = readdir($handle))) { if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") { $fileExploded = explode(".",$file); if (is_array($fileExploded) && count($fileExploded) == 4) { $db = $fileExploded[0]; $class = $fileExploded[1]; $className = $db."_".$class; $this->_generic->useModel($class,$db,"user"); $object = new $className(); if ($object->isMultilanguage()) { $results = $object->searchModels($object->getTable(),array(),array(0=>array("column"=>"pk_lang","value"=>$defaultLang,"mode"=>"equal"))); for($i=0 ; $i<$count=count($results) ; $i++) { $object = new $className(); $object->setModelLanguage($lang); foreach($results[$i] as $column => $col_value) { if ($column != "pk_lang" && $column != $object->getPrimaryKey()) { $object->__set($column,$col_value); } } try { $object->create($results[$i]->{$object->getPrimaryKey()}); } catch (Exception $e){} } } } } } // /MySQL multilanguage tables // Redirect $controllers = $this->_generic->getTranslatedController("SLS_Bo","Langs"); $this->_generic->redirect($controllers["controller"]."/".$controllers["scontroller"].".sls"); } // Else, form errors else { $xml->startTag("errors"); foreach($errors as $error) $xml->addFullTag("error",$error,true); $xml->endTag("errors"); } } $xml->startTag("generic_langs"); foreach($generics as $key => $value) { $xml->startTag("generic_lang"); $xml->addFullTag("key",$key,true); $xml->addFullTag("value",$value,true); $xml->endTag("generic_lang"); } $xml->endTag("generic_langs"); $xml->startTag("controllers"); for($i=0 ; $i<$count=count($controllers) ; $i++) { $xml->startTag("controller"); $xml->addFullTag("id",$controllers[$i]["id"],true); $xml->addFullTag("key",$controllers[$i]["key"],true); $xml->startTag("values"); foreach($controllers[$i]["values"] as $key2 => $value2) { $xml->startTag("value"); $xml->addFullTag("key",$key2,true); $xml->addFullTag("value",$value2,true); $xml->endTag("value"); } $xml->endTag("values"); $xml->startTag("actions"); for($j=0 ; $j<$count2=count($controllers[$i]["actions"]) ; $j++) { $action = $controllers[$i]["actions"]; $xml->startTag("action"); $xml->addFullTag("id",$action[$j]["id"],true); $xml->addFullTag("key",$action[$j]["key"],true); $xml->startTag("values"); foreach($action[$j]["values"] as $key3 => $value3) { $xml->startTag("value"); $xml->addFullTag("key",$key3,true); $xml->addFullTag("value",$value3,true); $xml->endTag("value"); } $xml->endTag("values"); $xml->startTag("metas"); foreach($action[$j]["metas"] as $key4 => $value4) { $xml->startTag("meta"); $xml->addFullTag("key",$key4,true); $xml->startTag("values"); foreach($value4 as $key5 => $value5) { $xml->startTag("value"); $xml->addFullTag("key",$key5,true); $xml->addFullTag("value",$value5,true); $xml->endTag("value"); } $xml->endTag("values"); $xml->endTag("meta"); } $xml->endTag("metas"); $xml->endTag("action"); } $xml->endTag("actions"); $xml->endTag("controller"); } $xml->endTag("controllers"); } $xpathLangs = $handle->getTags("//sls_configs/sls_country/sls_country_langs/sls_country_lang[@iso != '']"); foreach ($xpathLangs as $lang) if (!in_array(trim($lang), $langs)) array_push($langs, trim($lang)); array_multisort($langs, SORT_STRING, SORT_ASC); $xml->startTag("langs"); foreach ($langs as $lang) $xml->addFullTag("lang", $lang, true); $xml->endTag("langs"); $this->saveXML($xml); }
public function action() { // Objects $xml = $this->getXML(); $user = $this->hasAuthorative(); $xml = $this->makeMenu($xml); $this->_generic->registerLink('Generate', 'SLS_Bo', 'GenerateBo'); $this->_generic->registerLink('Translation', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "Boi18n")); $this->_generic->registerLink('FileUpload', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoFileUpload")); $this->_generic->registerLink('ManageAdmin', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoUserList|BoUserAdd|BoUserDelete|BoUserModify|BoUserStatus")); $this->_generic->registerLink('ProjectSettings', 'SLS_Bo', 'GenerateBoAction', array("Actions" => "BoProjectSettings")); $this->_generic->registerLink('Manage_Rights', 'SLS_Bo', 'ManageRights'); $this->_generic->registerLink('Manage_BoMenu', 'SLS_Bo', 'BoMenu'); $xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteBo",array(),false)); $xml->addFullTag("edit",$this->_generic->getFullPath("SLS_Bo","EditBo",array(),false)); $this->_xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $bos = array(); // Search for user back-office $controllersXML = $this->_generic->getControllersXML(); $controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name")); if (!empty($controller)) { $models = $this->getAllModels(); for($i=0 ; $i<$count=count($models) ; $i++) { $model = SLS_String::substrAfterFirstDelimiter($models[$i],"."); $db = SLS_String::substrBeforeFirstDelimiter($models[$i],"."); if ($this->boActionExist($model,$db)) { $this->_generic->useModel($model,$db,"user"); $class = ucfirst($db)."_".SLS_String::tableToClass($model); $object = new $class(); $bos[$class] = array("db" => $db, "className" => $class, "tableName" => $object->getTable(), "nb_actions" => count($this->getActionsBo($model,$db))); } } } asort($bos,SORT_REGULAR); $xml->startTag("bos"); foreach($bos as $bo) { $categoryExists = $this->_xmlBo->getTag("//sls_configs/entry[@type='category' and entry[@type='table' and @name='".strtolower($bo["db"]."_".$bo["tableName"])."']]/@name"); $xml->startTag("bo"); $xml->addFullTag("db",strtolower($bo["db"]),true); $xml->addFullTag("class",$bo["className"],true); $xml->addFullTag("table",$bo["tableName"],true); $xml->addFullTag("category",(empty($categoryExists)) ? "X" : $categoryExists,true); $xml->addFullTag("nb_actions",$bo["nb_actions"],true); $xml->endTag("bo"); } $xml->endTag("bos"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"); $xmlRights = new SLS_XMLToolbox($pathsHandle); $result = $xmlRights->getTags("//sls_configs/entry"); $xml->addFullTag("admins_exist",(!empty($result)) ? "true" : "false",true); $xml->startTag("actions"); $action = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Boi18n']")); $action2 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoFileUpload']")); $action3 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoUserList']")); $action4 = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='BoProjectSettings']")); $xml->startTag("action"); $xml->addFullTag("name","Translation",true); $xml->addFullTag("icon","boi18n16.png",true); $xml->addFullTag("existed",(!empty($action)) ? "true" : "false",true); $xml->endTag("action"); $xml->startTag("action"); $xml->addFullTag("name","FileUpload",true); $xml->addFullTag("icon","boupload16.png",true); $xml->addFullTag("existed",(!empty($action2)) ? "true" : "false",true); $xml->endTag("action"); $xml->startTag("action"); $xml->addFullTag("name","ManageAdmin",true); $xml->addFullTag("icon","boadmin16.png",true); $xml->addFullTag("existed",(!empty($action3)) ? "true" : "false",true); $xml->endTag("action"); $xml->startTag("action"); $xml->addFullTag("name","ProjectSettings",true); $xml->addFullTag("icon","bosettings16.png",true); $xml->addFullTag("existed",(!empty($action4)) ? "true" : "false",true); $xml->endTag("action"); $xml->endTag("actions"); if (SLS_Sql::getInstance()->tableExists("sls_graph")) { $this->_generic->useModel("Sls_graph",$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph"; $slsGraph = new $className; $nbGraph = $slsGraph->countModels("sls_graph"); } else $nbGraph = 0; $xml->addFullTag("nb_reporting",$nbGraph,true); $xml->addFullTag("url_reporting",$this->_generic->getFullPath("SLS_Bo","ReportingBo"),true); $this->saveXML($xml); }
/** * Format Errors * * @access protected * @param array $errors list of errors <code>array("error1", "error2")</code> * @param SLS_XMLToolbox $currentXML the current xml * @return SLS_XMLToolbox $currentXML the current xml modified * @since 1.0 */ protected function insertErrors($errors, $currentXML) { if (!empty($errors)) { $currentXML->startTag("errors"); foreach ($errors as $error) $currentXML->addFullTag("error", $error, true); $currentXML->endTag("errors"); } return $currentXML; }
public function action() { $user = $this->hasAuthorative(); // Objects $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); // Actions $xml->addFullTag("delete",$this->_generic->getFullPath("SLS_Bo","DeleteModel",array(),false)); $xml->addFullTag("delete_bearer",$this->_generic->getFullPath("SLS_Bo","DeleteBearerTable",array(),false)); $xml->addFullTag("delete_type",$this->_generic->getFullPath("SLS_Bo","DeleteType",array(),false)); $xml->addFullTag("edit_type",$this->_generic->getFullPath("SLS_Bo","EditType",array(),false)); $xml->addFullTag("delete_fk",$this->_generic->getFullPath("SLS_Bo","DeleteForeignKey",array(),false)); $xml->addFullTag("edit_fk",$this->_generic->getFullPath("SLS_Bo","EditForeignKey",array(),false)); $xml->addFullTag("update",$this->_generic->getFullPath("SLS_Bo","UpdateModel",array(),false)); $xml->addFullTag("descriptions",$this->_generic->getFullPath("SLS_Bo","UpdateDescription",array(),false)); // Get the table & class name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); // Get generic object $this->_generic->useModel(SLS_String::tableToClass($table),$db,"user"); $object = new $class(); // Get description's table $description = $object->getTableComment($table); $columnsInfos = $sql->showColumns($table); // Get object's infos $columns = array(); $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("description",(SLS_String::contains($description,"InnoDB free")) ? SLS_String::substrBeforeFirstDelimiter($description,"; InnoDB free") : $description,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->startTag("columns"); $cursor = 0; foreach($columnsP as $column => $value) { $xml->startTag("column"); $xml->addFullTag("name",$column,true); array_push($columns,$column); $fk = ""; $sType = ""; $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$table,$column)); if (!empty($res)) { $tableTmp = substr($res,(strpos($res,'tablePk="')+9),(strpos($res,'"/>')-(strpos($res,'tablePk="')+9))); $fk = SLS_String::substrAfterFirstDelimiter($tableTmp,"_"); } $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $res = $xmlType->getTagsByAttributes("//sls_configs/entry",array("table","column"),array($db."_".$table,$column)); if (!empty($res)) { $sType = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($res,'type="'),'"/>'); // If specific type numeric and native type too if (SLS_String::startsWith($sType,"num_") && $this->containsRecursive($columnsInfos[$cursor]->Type,array("int","float","double","decimal","real"))) $xml->addFullTag("allow_to_delete_type","false",true); } $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $results = $xmlFilter->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$column."']",array("filter","hash")); $xml->startTag("filters"); for($i=0 ; $i<$count=count($results) ; $i++) { $filter = $results[$i]["attributes"][0]["value"]; $result = $results[$i]["attributes"][1]["value"]; $xml->startTag("filter"); $xml->addFullTag("name",$filter.((!empty($result)) ? ' ['.$result.']' : ''),true); $xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","DeleteFilter",array(array("key"=>"table","value"=>$this->_http->getParam("name")),array("key"=>"column","value"=>$column),array("key"=>"filter","value"=>$filter))),true); $xml->endTag("filter"); } $xml->endTag("filters"); $xml->addFullTag("fk",$fk,true); $xml->addFullTag("type",ucfirst($sType),true); $xml->addFullTag("comment",$object->getColumnComment($column),true); $xml->endTag("column"); $cursor++; } $xml->endTag("columns"); $xml->addFullTag("url_add_type",$this->_generic->getFullPath("SLS_Bo","AddType",array(0=>array("key"=>"name","value"=>$db."_".$table))),true); $xml->addFullTag("url_add_filter",$this->_generic->getFullPath("SLS_Bo","AddFilter",array(0=>array("key"=>"name","value"=>$db."_".$table))),true); $xml->addFullTag("url_add_fk",$this->_generic->getFullPath("SLS_Bo","AddForeignKey",array(0=>array("key"=>"name","value"=>$db."_".$table))),true); // Get the source of the current model $xml->addFullTag("current_source",str_replace("\t"," ",file_get_contents($this->_generic->getPathConfig("models").$file.".model.php")),true); // Get the source of the current table if (!$sql->tableExists($table)) $xml->addFullTag("current_table",-1,true); else { $columns = $sql->showColumns($table); $tableName = $table; $currentTable = array("table"=>$db.".".$tableName,"errors"=>array()); $className = ucfirst($db)."_".SLS_String::tableToClass($tableName); $fileName = ucfirst($db).".".SLS_String::tableToClass($table).".model.php"; $primaryKey = ""; $multiLanguage = 'false'; $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); // Get source $contentM = $this->getModelSource($tableName,$db); // Is data bearer $xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml")); $result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1"))); $xml->addFullTag("is_data_bearer",(!empty($result)) ? $result["attributes"][0]["value"] : "false",true); // Save the new source $xml->addFullTag("current_table",str_replace("\t"," ",$contentM),true); $xml->addFullTag("url_data_bearer",$this->_generic->getFullPath("SLS_Bo","AddBearerTable",array(array("key"=>"name","value"=>$this->_http->getParam("name")))),true); } $xml->endTag("model"); $this->saveXML($xml); }
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); } }
/** * Get the statics files for include * * @access public * @return string $string the statics files * @since 1.0 */ public function includeStaticsFiles() { $xmlToolBox = new SLS_XMLToolbox($this->_xml); $this->_staticsXsl['unloaded'] = ($this->_cacheActive == 0) ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Unloaded/xsl/file") : ($this->_generic->getSide() == 'user') ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Unloaded/xsl/file") : $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/SlsUnloaded/xsl/file"); $this->_staticsXsl['loaded']['headers']['file'] = ($this->_cacheActive == 0) ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Headers/xsl/file") : ($this->_generic->getSide() == 'user') ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Headers/xsl/file") : $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/SlsHeaders/xsl/file"); $this->_staticsXsl['loaded']['headers']['name'] = ($this->_cacheActive == 0) ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Headers/xsl/templateName") : ($this->_generic->getSide() == 'user') ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Headers/xsl/templateName") : $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/SlsHeaders/xsl/templateName"); $this->_staticsXsl['loaded']['body']['file'] = ($this->_cacheActive == 0) ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Body/xsl/file") : ($this->_generic->getSide() == 'user') ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Body/xsl/file") : $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/SlsBody/xsl/file"); $this->_staticsXsl['loaded']['body']['name'] = ($this->_cacheActive == 0) ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Body/xsl/templateName") : ($this->_generic->getSide() == 'user') ? $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/Body/xsl/templateName") : $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/SlsBody/xsl/templateName"); $this->_staticsXsl['coreUnloaded'] = $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/CoreUnloaded/xsl/file"); $this->_staticsXsl['loaded']['coreHeaders']['file'] = $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/CoreHeaders/xsl/file"); $this->_staticsXsl['loaded']['coreHeaders']['name'] = $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/CoreHeaders/xsl/templateName"); $this->_staticsXsl['loaded']['coreBody']['file'] = $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/CoreBody/xsl/file"); $this->_staticsXsl['loaded']['coreBody']['name'] = $xmlToolBox->getTags("//root/Statics/Sls/XslStatics/files/Loaded/CoreBody/xsl/templateName"); $files = array_merge($this->_staticsXsl['unloaded'], $this->_staticsXsl['coreUnloaded'], $this->_staticsXsl['loaded']['headers']['file'], $this->_staticsXsl['loaded']['body']['file'], $this->_staticsXsl['loaded']['coreHeaders']['file'], $this->_staticsXsl['loaded']['coreBody']['file']); $string = ""; foreach ($files as $file) $string .= "<xsl:include href=\"".$file."\" />\n"; return $string; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $sql = SLS_Sql::getInstance(); $slsGraphId = $this->_http->getParam('id'); $this->useModel('Sls_graph_query',$this->defaultDb,"sls"); $this->useModel('Sls_graph',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_column',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_join',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_group',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_where',$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query"; $slsGraphQuery = new $className(); $className = ucfirst($this->defaultDb)."_Sls_graph"; $slsGraph = new $className(); if($slsGraph->getModel($slsGraphId) === false || $slsGraphQuery->getModel($slsGraph->sls_graph_query_id) === false) $this->forward('SLS_Default', 'UrlError'); $slsGraphQueryCurrent = $slsGraphQuery; $errors = array(); $slsGraphTypes = array('pie', 'bar', 'pivot', 'list'); $slsGraphAggregationTypes = array('sum', 'avg', 'count'); $slsGraphAggregationTypesNeedField = array('sum', 'avg'); $slsGraphQueryOperators = array('like','notlike','startwith','endwith','equal','notequal','in','notin','lt','lte','gt','gte','null','notnull'); $this->queryOperatorsNeedField = array('like','notlike','startwith','endwith','equal','notequal','in','notin','lt','lte','gt','gte'); $tableFieldsValues = array(); $slsGraphQueryData = array( 'sls_graph_query_where' => array( 'sls_graph_query_where_type' => 'group', 'sls_graph_query_where_condition' => '', 'sls_graph_query_where_column' => '', 'sls_graph_query_where_operator' => '', 'sls_graph_query_where_value' => '', 'sls_graph_query_where_children' => array(), 'sls_graph_query_where_root' => 'true', ) ); $slsGraphData = array(); $slsGraphQueryWheres = array(); # reload if($this->_http->getParam('reload') == 'true') { $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $slsGraphQueryData = $this->_http->getParam('sls_graph_query'); $slsGraphData = $this->_http->getParam('sls_graph'); if(!$slsGraph->setSlsGraphTitle($slsGraphData['sls_graph_title'])) $errors['sls_graph_title'] = 'Titre invalide'; $tmp = explode('.', $slsGraphQueryData['sls_graph_query_table']); if(count($tmp) == 2) { $slsGraphQueryDbAlias = $tmp[0]; $slsGraphQueryTable = $tmp[1]; $slsGraphQueryTableAlias = $this->getTableAlias($slsGraphQueryTable); $sql->changeDb($slsGraphQueryDbAlias); } else { $slsGraphQueryTableAlias = $slsGraphQueryDbAlias = $slsGraphQueryTable = ''; } if(!$slsGraphQuery->setSlsGraphQueryDbAlias($slsGraphQueryDbAlias) || !$slsGraphQuery->setSlsGraphQueryTable($slsGraphQueryTable) || !$slsGraphQuery->setSlsGraphQueryTableAlias($slsGraphQueryTableAlias) || !$sql->tableExists($slsGraphQueryTable)) $errors['sls_graph_query_table'] = 'Table invalide'; else { $tableFields = $sql->showColumns($slsGraphQueryTable); $tableFieldsValues = array_map(array($this,'filterFields'), $tableFields); } if(!$slsGraph->setSlsGraphType($slsGraphData['sls_graph_type'])) { $errors['sls_graph_type'] = 'Type invalide'; } else if($slsGraphData['sls_graph_type'] == 'pie') { # query columns $tmp = explode('.', $slsGraphData['sls_graph_pie_group_by']); $column = $tmp[1]; $columnConcat = $column; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn1 = new $className(); $slsGraphQueryColumn1->setSlsGraphQueryColumnName($column); $slsGraphQueryColumn1->setSlsGraphQueryColumnAlias('legend_id'); $slsGraphQueryColumn1->setSlsGraphQueryColumnTable($slsGraphQueryTable); $slsGraphQueryColumn1->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk"))); if(!empty($columnFk)) { $tablePk = $columnFk['attributes'][0]['value']; $labelPk = $columnFk['attributes'][1]['value']; $dbPk = SLS_String::substrBeforeFirstDelimiter($tablePk, '_'); $tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_'); $this->_generic->useModel($tablePk, $dbPk, "user"); $classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk); $objectFk = new $classFk(); $columns = array(); $columnsLabel = array(); $clause = array(); $render = array(); $columnTable = $objectFk->getTable(); # add join $i = 1; # target $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$i} = new $className(); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column); # /target # source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable); $slsGraphQueryJoin = $this->getTableAlias($columnTable); /*$slsGraphQueryJoin = $columnTable.$aliasIndex; $aliasIndex++;*/ ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey()); # /source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left'); $i++; # /add join foreach($objectFk->getParams() as $key => $value) { array_push($columns,"`".$key."`"); if (SLS_String::contains($labelPk,$key)) $columnsLabel[$key] = strpos($labelPk,$key); } array_multisort($columnsLabel); foreach($columnsLabel as $columnLabel => $offset) array_push($clause,$columnLabel); $pattern = str_replace("'","''",$labelPk); foreach($clause as $columnC) $pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern); $columnConcat = "CONCAT('".$pattern."')"; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn2 = new $className(); $slsGraphQueryColumn2->setSlsGraphQueryColumnName($columnConcat); $slsGraphQueryColumn2->setSlsGraphQueryColumnAlias('legend'); $slsGraphQueryColumn2->setSlsGraphQueryColumnTable($slsGraphQueryTable); $slsGraphQueryColumn2->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn3 = new $className(); $slsGraphQueryColumn3->setSlsGraphQueryColumnAggregation('count'); $slsGraphQueryColumn3->setSlsGraphQueryColumnAlias('count'); $slsGraphQueryColumn3->setSlsGraphQueryColumnTable($slsGraphQueryTable); $slsGraphQueryColumn3->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); # /query columns # query groups $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup1 = new $className(); if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($column)/* || !in_array($slsGraphData['sls_graph_pie_group_by'], $tableFieldsValues)*/) $errors['sls_graph_pie_group_by'] = 'Champ groupé invalide'; # /query groups $sql->changeDb($slsGraphQueryDbAlias); $joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_pie_group_by'])); } else if($slsGraphData['sls_graph_type'] == 'bar') { $i = 1; $j = 1; # query columns $tmp = explode('.', $slsGraphData['sls_graph_bar_aggregation_field']); if(count($tmp) == 2) $columnAggregationField = $tmp[1]; else $columnAggregationField = ''; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); if(empty($slsGraphData['sls_graph_bar_aggregation']) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAggregation($slsGraphData['sls_graph_bar_aggregation']) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('value')) $errors['sls_graph_bar_aggregation'] = 'Aggrégation invalide'; if(in_array($slsGraphData['sls_graph_bar_aggregation'], $slsGraphAggregationTypesNeedField) && (empty($columnAggregationField) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnAggregationField))) $errors['sls_graph_bar_aggregation_field'] = 'Champ aggrégation invalide'; $j++; # query column group $tmp = explode('.', $slsGraphData['sls_graph_bar_group_by']); $column = $tmp[1]; $columnConcat = $column; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_group_id'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; $columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk"))); if(!empty($columnFk)) { $tablePk = $columnFk['attributes'][0]['value']; $labelPk = $columnFk['attributes'][1]['value']; $dbPk = SLS_String::substrBeforeFirstDelimiter($tablePk, '_'); $tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_'); $this->_generic->useModel($tablePk, $dbPk, "user"); $classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk); $objectFk = new $classFk(); $columns = array(); $columnsLabel = array(); $clause = array(); $render = array(); $columnTable = $objectFk->getTable(); # add join # target $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$i} = new $className(); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column); # /target # source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable); $slsGraphQueryJoin = $this->getTableAlias($columnTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey()); # /source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left'); $i++; # /add join foreach($objectFk->getParams() as $key => $value) { array_push($columns,"`".$key."`"); if (SLS_String::contains($labelPk,$key)) $columnsLabel[$key] = strpos($labelPk,$key); } array_multisort($columnsLabel); foreach($columnsLabel as $columnLabel => $offset) array_push($clause,$columnLabel); $pattern = str_replace("'","''",$labelPk); foreach($clause as $columnC) $pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern); $columnConcat = "CONCAT('".$pattern."')"; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_group'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; # query column group # query column stacked if(!empty($slsGraphData['sls_graph_bar_stacked_field'])) { $tmp = explode('.', $slsGraphData['sls_graph_bar_stacked_field']); $column = $tmp[1]; $columnConcat = $column; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_stacked_id'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; $columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk"))); if(!empty($columnFk)) { $tablePk = $columnFk['attributes'][0]['value']; $labelPk = $columnFk['attributes'][1]['value']; $dbPk = SLS_String::substrBeforeFirstDelimiter($tablePk, '_'); $tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_'); $this->_generic->useModel($tablePk, $dbPk, "user"); $classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk); $objectFk = new $classFk(); $columns = array(); $columnsLabel = array(); $clause = array(); $render = array(); $columnTable = $objectFk->getTable(); # add join # target $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$i} = new $className(); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column); # /target # source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable); $slsGraphQueryJoin = $this->getTableAlias($columnTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey()); # /source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left'); $i++; # /add join foreach($objectFk->getParams() as $key => $value) { array_push($columns,"`".$key."`"); if (SLS_String::contains($labelPk,$key)) $columnsLabel[$key] = strpos($labelPk,$key); } array_multisort($columnsLabel); foreach($columnsLabel as $columnLabel => $offset) array_push($clause,$columnLabel); $pattern = str_replace("'","''",$labelPk); foreach($clause as $columnC) $pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern); $columnConcat = "CONCAT('".$pattern."')"; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_stacked'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); } # query column stacked # /query columns # query groups $tmp = explode('.', $slsGraphData['sls_graph_bar_group_by']); $columnGroupByField = $tmp[1]; $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup1 = new $className(); if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($columnGroupByField)) $errors['sls_graph_bar_group_by'] = 'Champ groupé invalide'; if(!empty($slsGraphData['sls_graph_bar_stacked_field'])) { $tmp = explode('.', $slsGraphData['sls_graph_bar_stacked_field']); $columnStackedField = $tmp[1]; $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup2 = new $className(); if(!$slsGraphQueryGroup2->setSlsGraphQueryGroupColumn($columnStackedField)) $errors['sls_graph_bar_stacked_field'] = 'Champ réservé invalide'; } # /query groups $joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_bar_group_by'])); } else if($slsGraphData['sls_graph_type'] == 'pivot') { $i = 1; $j = 1; # query columns $tmp = explode('.', $slsGraphData['sls_graph_pivot_aggregation_field']); if(count($tmp) == 2) $columnAggregationField = $tmp[1]; else $columnAggregationField = ''; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); if(empty($slsGraphData['sls_graph_pivot_aggregation']) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAggregation($slsGraphData['sls_graph_pivot_aggregation']) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('value')) $errors['sls_graph_pivot_aggregation'] = 'Aggrégation invalide'; if(in_array($slsGraphData['sls_graph_pivot_aggregation'], $slsGraphAggregationTypesNeedField) && (empty($columnAggregationField) || !${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnAggregationField))) $errors['sls_graph_pivot_aggregation_field'] = 'Champ aggrégation invalide'; $j++; # query column line $tmp = explode('.', $slsGraphData['sls_graph_pivot_line']); $column = $tmp[1]; $columnConcat = $tmp[1]; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_line_id'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; $columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk"))); if(!empty($columnFk)) { $tablePk = $columnFk['attributes'][0]['value']; $labelPk = $columnFk['attributes'][1]['value']; $dbPk = SLS_String::substrBeforeFirstDelimiter($tablePk, '_'); $tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_'); $this->_generic->useModel($tablePk, $dbPk, "user"); $classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk); $objectFk = new $classFk(); $columns = array(); $columnsLabel = array(); $clause = array(); $render = array(); $columnTable = $objectFk->getTable(); # add join # target $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$i} = new $className(); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column); # /target # source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable); $slsGraphQueryJoin = $this->getTableAlias($columnTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey()); # /source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left'); $i++; # /add join foreach($objectFk->getParams() as $key => $value) { array_push($columns,"`".$key."`"); if (SLS_String::contains($labelPk,$key)) $columnsLabel[$key] = strpos($labelPk,$key); } array_multisort($columnsLabel); foreach($columnsLabel as $columnLabel => $offset) array_push($clause,$columnLabel); $pattern = str_replace("'","''",$labelPk); foreach($clause as $columnC) $pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern); $columnConcat = "CONCAT('".$pattern."')"; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_line'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; # query column line # query column column $tmp = explode('.', $slsGraphData['sls_graph_pivot_column']); $column = $tmp[1]; $columnConcat = $column; $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($column); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_column_id'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); $j++; $columnFk = array_shift($xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".strtolower($slsGraphQueryDbAlias.'_'.$slsGraphQueryTable)."' and @columnFk = '".$column."']",array("tablePk","labelPk"))); if(!empty($columnFk)) { $tablePk = $columnFk['attributes'][0]['value']; $labelPk = $columnFk['attributes'][1]['value']; $dbPk = SLS_String::substrBeforeFirstDelimiter($tablePk, '_'); $tablePk = SLS_String::substrAfterFirstDelimiter($tablePk, '_'); $this->_generic->useModel($tablePk, $dbPk, "user"); $classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk); $objectFk = new $classFk(); $columns = array(); $columnsLabel = array(); $clause = array(); $render = array(); $columnTable = $objectFk->getTable(); # add join # target $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$i} = new $className(); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableTarget($slsGraphQueryTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasTarget($slsGraphQueryTableAlias); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnTarget($column); # /target # source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableSource($columnTable); $slsGraphQueryJoin = $this->getTableAlias($columnTable); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinTableAliasSource($slsGraphQueryJoin); ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinColumnSource($objectFk->getPrimaryKey()); # /source ${slsGraphQueryJoin.$i}->setSlsGraphQueryJoinMode('left'); $i++; # /add join foreach($objectFk->getParams() as $key => $value) { array_push($columns,"`".$key."`"); if (SLS_String::contains($labelPk,$key)) $columnsLabel[$key] = strpos($labelPk,$key); } array_multisort($columnsLabel); foreach($columnsLabel as $columnLabel => $offset) array_push($clause,$columnLabel); $pattern = str_replace("'","''",$labelPk); foreach($clause as $columnC) $pattern = str_replace($columnC,"',"."CAST(".$slsGraphQueryJoin.".`".$columnC."` AS CHAR),'",$pattern); $columnConcat = "CONCAT('".$pattern."')"; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$j} = new $className(); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnName($columnConcat); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnAlias('legend_column'); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTable($slsGraphQueryTable); ${slsGraphQueryColumn.$j}->setSlsGraphQueryColumnTableAlias($slsGraphQueryTableAlias); # query column column # /query columns # query groups $tmp = explode('.', $slsGraphData['sls_graph_pivot_line']); $columnLine = $tmp[1]; $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup1 = new $className(); if(!$slsGraphQueryGroup1->setSlsGraphQueryGroupColumn($columnLine)) $errors['sls_graph_pivot_line'] = 'Champ Ligne invalide'; $tmp = explode('.', $slsGraphData['sls_graph_pivot_column']); $columnColumn = $tmp[1]; $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup2 = new $className(); if(!$slsGraphQueryGroup2->setSlsGraphQueryGroupColumn($columnColumn)) $errors['sls_graph_pivot_column'] = 'Champ colonne invalide'; # /query groups $joins = $this->getQueryJoin($slsGraphQueryTable, $slsGraphQueryTableAlias, array($slsGraphData['sls_graph_pivot_column'])); } else if($slsGraphData['sls_graph_type'] == 'list') { # columns $i = 1; $j = 1; $joins = array(); foreach($slsGraphQueryData['sls_graph_query_column'] as $col) { $column = $col['sls_graph_query_column_value']; $path = explode('|', $column); $nbJoins = count($path); $data = explode('.', $path[$nbJoins-1]); $table = $data[0]; $column = $data[1]; $joinBefore = null; # joins for($k = 0; $k<$nbJoins ; $k++) { if($k == 0) { $columns = $sql->showColumns($slsGraphQueryTable); $columnSource = array_shift(array_filter($columns, array($this,'filterPK'))); $columnSourcePK = $columnSource->Field; $join = array( 'sls_graph_query_join_table_source' => $slsGraphQueryTable, 'sls_graph_query_join_column_source' => $columnSourcePK ); } else { $dataSource = explode('.', $path[$k]); $dataTarget = explode('.', $path[$k-1]); $tableSource = $dataSource[0]; $tableTarget = $dataTarget[0]; $columnSource = $dataSource[1]; $columnTarget = $dataTarget[1]; $columns = $sql->showColumns($tableSource); $columnSourcePK = array_shift(array_filter($columns, array($this,'filterPK')))->Field; $columns = $sql->showColumns($tableTarget); $this->columnTarget = $columnTarget; $columnTargetComment = array_shift(array_filter($columns, array($this,'filterFieldTarget')))->Comment; $join = array( 'sls_graph_query_join_table_target' => $tableTarget, 'sls_graph_query_join_column_target' =>$columnTarget, 'sls_graph_query_join_table_comment_target' => empty($columnTargetComment) ? $columnTarget : $columnTargetComment, 'sls_graph_query_join_table_source' => $tableSource, 'sls_graph_query_join_column_source' => $columnSourcePK ); } $joinSearch = $this->array_search_multi($join, $joins); if(empty($joinSearch)) { $join['sls_graph_query_join_table_alias_source'] = ($k == 0) ? $slsGraphQueryTableAlias : $this->getTableAlias($join['sls_graph_query_join_table_source']); /*$join['sls_graph_query_join_table_source'].$aliasIndex++*/; if($k > 0) { $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; ${slsGraphQueryJoin.$j} = new $className(); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableSource($join['sls_graph_query_join_table_source']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableAliasSource($join['sls_graph_query_join_table_alias_source']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinColumnSource($join['sls_graph_query_join_column_source']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableTarget($join['sls_graph_query_join_table_target']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinTableAliasTarget($joinBefore['sls_graph_query_join_table_alias_source']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinColumnTarget($join['sls_graph_query_join_column_target']); ${slsGraphQueryJoin.$j}->setSlsGraphQueryJoinMode('left'); $j++; } array_push($joins, $join); } else $join = $joinSearch; $joinBefore = $join; } # /joins $columns = $sql->showColumns($table); $this->column = $column; $columnComment = array_shift(array_filter($columns, array($this,'filterColumnField')))->Comment; $tableComment = $join['sls_graph_query_join_table_comment_target']; if(empty($tableComment)) { $tables = $sql->showTables(); $this->table = $table; $tableComment = array_shift(array_filter($tables, array($this,'filterTable4')))->Comment; } $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; ${slsGraphQueryColumn.$i} = new $className(); ${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnTable($join['sls_graph_query_join_table_source']); ${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnTableAlias($join['sls_graph_query_join_table_alias_source']); ${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnName($column); ${slsGraphQueryColumn.$i}->setSlsGraphQueryColumnAlias($tableComment.' - '.$columnComment); $i++; } # /columns } # query where if(!empty($slsGraphQueryData['sls_graph_query_where'])) { $i = 0; $j = 0; $this->iterateSetSlsGraphQueryWhere($slsGraphQueryData['sls_graph_query_where'], $i, $j, $slsGraphQueryWheres, $errors, $joins); } # /query where if (empty($errors)) { $sql->changeDb($this->defaultDb); # query $this->deleteQuery($slsGraphQueryCurrent->sls_graph_query_id); $slsGraphQuery->create(); # /query # graph $slsGraph->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id); $slsGraph->save(); # /graph # query joins $i = 1; //$slsGraphQueryJoin1 while(${slsGraphQueryJoin.$i}) { ${slsGraphQueryJoin.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id); ${slsGraphQueryJoin.$i}->create(); $i++; } # /query joins # query columns $i = 1; while(${slsGraphQueryColumn.$i}) { ${slsGraphQueryColumn.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id); ${slsGraphQueryColumn.$i}->create(); $i++; } # /query columns # query groups $i = 1; while(${slsGraphQueryGroup.$i}) { ${slsGraphQueryGroup.$i}->setSlsGraphQueryGroupTable($slsGraphQueryTable); ${slsGraphQueryGroup.$i}->setSlsGraphQueryGroupTableAlias($slsGraphQueryTableAlias); ${slsGraphQueryGroup.$i}->setSlsGraphQueryId($slsGraphQuery->sls_graph_query_id); ${slsGraphQueryGroup.$i}->create(); $i++; } # /query groups # query where if(!empty($slsGraphQueryData['sls_graph_query_where'])) { $i = 0; $this->iterateCreateQueryWhere($slsGraphQueryData['sls_graph_query_where'], 0, $i, $slsGraphQueryWheres, $slsGraphQuery->sls_graph_query_id); } # /query where $this->forward('SLS_Bo', 'ReportingBo'); } else { $xml->startTag("errors"); foreach($errors as $key => $error) { if($key == 'sls_graph_query_where') { foreach($error as $slsGraphQueryWhereIndex => $slsGraphQueryWhereErrors) { foreach($slsGraphQueryWhereErrors as $slsGraphQueryWhereKey => $slsGraphQueryWhereError) { $xml->addFullTag("error", $slsGraphQueryWhereError, true, array("num" => $slsGraphQueryWhereIndex, "column" => $slsGraphQueryWhereKey)); } } } else $xml->addFullTag("error", $error, true, array("column" => $key)); } $xml->endTag("errors"); } $slsGraphQueryData = $this->_http->getParam('sls_graph_query'); } # /reload # load else { $this->useModel('Sls_graph_query',$this->defaultDb,"sls"); $this->useModel('Sls_graph',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_column',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_join',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_group',$this->defaultDb,"sls"); $this->useModel('Sls_graph_query_where',$this->defaultDb,"sls"); $className = ucfirst($this->defaultDb)."_Sls_graph_query_column"; $slsGraphQueryColumn = new $className(); $className = ucfirst($this->defaultDb)."_Sls_graph_query_join"; $slsGraphQueryJoin = new $className(); $className = ucfirst($this->defaultDb)."_Sls_graph_query_where"; $slsGraphQueryWhere = new $className(); $className = ucfirst($this->defaultDb)."_Sls_graph_query_group"; $slsGraphQueryGroup = new $className(); $slsGraphQueryId = $slsGraphQueryCurrent->sls_graph_query_id; $tables = array($slsGraphQueryCurrent->sls_graph_query_table => !empty($slsGraphQueryCurrent->sls_graph_query_alias) ? $slsGraphQuery->sls_graph_query_alias : $slsGraphQueryCurrent->sls_graph_query_table); $columns = $slsGraphQueryColumn->searchModels("sls_graph_query_column",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_column_id","order"=>"asc"))); $joins = $slsGraphQueryJoin->searchModels("sls_graph_query_join",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_join_id","order"=>"asc"))); $wheres = $slsGraphQueryWhere->searchModels("sls_graph_query_where",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_where_id","order"=>"asc"))); $groups = $slsGraphQueryGroup->searchModels("sls_graph_query_group",array(),array(0=>array("column"=>"sls_graph_query_id","value"=>$slsGraphQueryId,"mode"=>"equal")),array(),array(array("column"=>"sls_graph_query_group_id","order"=>"asc"))); if($slsGraph->sls_graph_type == 'pie') { $slsGraphData['sls_graph_pie_group_by'] = !empty($groups) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : ''; } else if($slsGraph->sls_graph_type == 'bar') { $slsGraphData['sls_graph_bar_aggregation'] = !empty($columns) ? $columns[0]->sls_graph_query_column_aggregation : ''; $slsGraphData['sls_graph_bar_aggregation_field'] = !empty($columns) && !empty($columns[0]->sls_graph_query_column_name) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$columns[0]->sls_graph_query_column_name : ''; $slsGraphData['sls_graph_bar_group_by'] = !empty($groups) && !empty($groups[0]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : ''; $slsGraphData['sls_graph_bar_stacked_field'] = !empty($groups) && !empty($groups[1]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[1]->sls_graph_query_group_column : ''; } else if($slsGraph->sls_graph_type == 'pivot') { $slsGraphData['sls_graph_pivot_aggregation'] = !empty($columns) ? $columns[0]->sls_graph_query_column_aggregation : ''; $slsGraphData['sls_graph_pivot_aggregation_field'] = !empty($columns) && !empty($columns[0]->sls_graph_query_column_name) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$columns[0]->sls_graph_query_column_name : ''; $slsGraphData['sls_graph_pivot_line'] = !empty($groups) && !empty($groups[0]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[0]->sls_graph_query_group_column : ''; $slsGraphData['sls_graph_pivot_column'] = !empty($groups) && !empty($groups[1]->sls_graph_query_group_column) ? $slsGraphQueryCurrent->sls_graph_query_table_alias.'.'.$groups[1]->sls_graph_query_group_column : ''; } foreach($slsGraph->getParams() as $key => $value) $slsGraphData[$key] = $value; if ($slsGraphQueryCurrent->sls_graph_query_db_alias != $sql->getCurrentDb()) $sql->changeDb($slsGraphQueryCurrent->sls_graph_query_db_alias); $tableFields = $sql->showColumns($slsGraphQueryCurrent->sls_graph_query_table); foreach($slsGraphQueryCurrent->getParams() as $key => $value) { if($key == 'sls_graph_query_table') $value = $slsGraphQueryCurrent->sls_graph_query_db_alias.'.'.$value; $slsGraphQueryData[$key] = $value; } $slsGraphQueryData['sls_graph_query_column'] = $this->iterateFormatQueryColumnToArray($columns, $joins); $slsGraphQueryData['sls_graph_query_where'] = $this->iterateFormatQueryWhereToArray($wheres, 0); } # /load # graph $xml->startTag('sls_graph'); foreach($slsGraphData as $key => $value) $xml->addFullTag($key, $value, true); $xml->addFullTag('graph_table_fields_class', empty($tableFields) ? 'hide' : '', true); $xml->startTag('sls_graph_query'); foreach($slsGraphQueryData as $key => $value) { if($key == 'sls_graph_query_where') { $i = 0; $j = 0; $this->iterateAddXmlQueryWhere($value, $i, $j, $xml); } else if($key == 'sls_graph_query_column') { $xml->startTag('sls_graph_query_columns'); foreach($value as $column) { $xml->startTag('sls_graph_query_column'); $xml->addFullTag('sls_graph_query_column_value', $column['sls_graph_query_column_value'], true); $xml->addFullTag('sls_graph_query_column_label', $column['sls_graph_query_column_label'], true); $xml->endTag('sls_graph_query_column'); } $xml->endTag('sls_graph_query_columns'); } else $xml->addFullTag($key, $value, true); } $xml->endTag('sls_graph_query'); $xml->endTag('sls_graph'); # /graph $labels = array( 'SLS_GRAPH_TYPE_PIE' => "Pie Chart", 'SLS_GRAPH_TYPE_BAR' => "Bar Chart", 'SLS_GRAPH_TYPE_PIVOT' => "Pivot Table", 'SLS_GRAPH_TYPE_LIST' => "List", 'SLS_AGGREGATION_TYPE_SUM' => "SUM", 'SLS_AGGREGATION_TYPE_AVG' => "AVG", 'SLS_AGGREGATION_TYPE_COUNT' => "COUNT", 'SLS_AGGREGATION_TYPE_SUM_LABEL' => "Sum", 'SLS_AGGREGATION_TYPE_AVG_LABEL' => "Average", 'SLS_AGGREGATION_TYPE_COUNT_LABEL' => "Total", 'SLS_QUERY_OPERATOR_LIKE' => "LIKE", 'SLS_QUERY_OPERATOR_NOTLIKE' => "NOT LIKE", 'SLS_QUERY_OPERATOR_STARTWITH' => "START WITH", 'SLS_QUERY_OPERATOR_ENDWITH' => "END WITH", 'SLS_QUERY_OPERATOR_EQUAL' => "EQUAL", 'SLS_QUERY_OPERATOR_NOTEQUAL' => "NOT EQUAL", 'SLS_QUERY_OPERATOR_IN' => "IN", 'SLS_QUERY_OPERATOR_NOTIN' => "NOT IN", 'SLS_QUERY_OPERATOR_LT' => "LESS THAN", 'SLS_QUERY_OPERATOR_LTE' => "LESS THAN EQUAL", 'SLS_QUERY_OPERATOR_GT' => "GREATER THAN", 'SLS_QUERY_OPERATOR_GTE' => "GREATER THAN EQUAL", 'SLS_QUERY_OPERATOR_NULL' => "IS NULL", 'SLS_QUERY_OPERATOR_NOTNULL' => "IS NOT NULL" ); # graph types $xml->startTag('sls_graph_types'); foreach($slsGraphTypes as $slsGraphType){ $xml->startTag('sls_graph_type'); $xml->addFullTag('sls_graph_type_value', $slsGraphType, true); $xml->addFullTag('sls_graph_type_label', $labels['SLS_GRAPH_TYPE_'.mb_strtoupper($slsGraphType, 'UTF-8')], true); $xml->endTag('sls_graph_type'); } $xml->endTag('sls_graph_types'); # /graph types # aggregation types $xml->startTag('sls_graph_aggregation_types'); foreach($slsGraphAggregationTypes as $slsGraphAggregationType){ $xml->startTag('sls_graph_aggregation_type'); $xml->addFullTag('sls_graph_aggregation_type_value', $slsGraphAggregationType, true); $xml->addFullTag('sls_graph_aggregation_type_label', $labels['SLS_AGGREGATION_TYPE_'.mb_strtoupper($slsGraphAggregationType, 'UTF-8')], true); $xml->endTag('sls_graph_aggregation_type'); } $xml->endTag('sls_graph_aggregation_types'); # /aggregation types # query operators $xml->startTag('sls_graph_query_operators'); foreach($slsGraphQueryOperators as $slsGraphQueryOperator){ $xml->startTag('sls_graph_query_operator'); $xml->addFullTag('sls_graph_query_operator_value', $slsGraphQueryOperator, true); $xml->addFullTag('sls_graph_query_operator_label', $labels['SLS_QUERY_OPERATOR_'.mb_strtoupper($slsGraphQueryOperator, 'UTF-8')], true); $xml->endTag('sls_graph_query_operator'); } $xml->endTag('sls_graph_query_operators'); # /query operators # tables $xml->startTag('tables'); $dbs = $sql->getDbs(); foreach($dbs as $db) { $sql->changeDb($db); $tables = $sql->showTables(); usort($tables, array($this,'cmpTables')); foreach($tables as $table) { $xml->startTag('table'); $xml->addFullTag('table_name', $db.'.'.$table->Name, true); $xml->addFullTag('table_label', $db.' - '.$table->Name, true); $xml->endTag('table'); } } $xml->endTag('tables'); # /tables $xml->addFullTag("url_reporting_getfields",$this->_generic->getFullPath("SLS_Bo","ReportingBoGetFields"),true); $xml->addFullTag("url_reporting_getfieldsfrommutipletables",$this->_generic->getFullPath("SLS_Bo","ReportingBoGetFieldsFromMultipleTables"),true); $xml->addFullTag("url_report",$this->_generic->getFullPath("SLS_Bo","ReportingBo"),true); $xml->addFullTag("url_delete",$this->_generic->getFullPath("SLS_Bo","ReportingBoDelete",array("id" => $slsGraphId)),true); $xml->addFullTag("url_status",$this->_generic->getFullPath("SLS_Bo","ReportingBoStatus",array("id" => $slsGraphId)),true); $this->saveXML($xml); }
/** * Action Home * */ public function action() { $this->secureURL(); $this->_generic->registerLink('GlobalSettings', 'SLS_Init', 'GlobalSettings'); $handle = file_get_contents($this->_generic->getPathConfig("configSls").'charset.xml'); $handle2 = file_get_contents($this->_generic->getPathConfig("configSls").'timezone.xml'); $xml = $this->getXML(); $xml->addFullTag("charsets", SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterFirstDelimiter($handle, "<sls_configs>"), "</sls_configs>"), false); $xml->addFullTag("timezones", SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterFirstDelimiter($handle2, "<sls_configs>"), "</sls_configs>"), false); $errors = array(); $domain = SLS_String::trimSlashesFromString($this->_http->getParam('settings_domain')); $protocol = SLS_String::trimSlashesFromString($this->_http->getParam('settings_protocol')); $project = SLS_String::trimSlashesFromString($this->_http->getParam('settings_project')); $description = SLS_String::trimSlashesFromString($this->_http->getParam('settings_description')); $keywords = SLS_String::trimSlashesFromString($this->_http->getParam('settings_keywords')); $author = SLS_String::trimSlashesFromString($this->_http->getParam('settings_author')); $copyright = SLS_String::trimSlashesFromString($this->_http->getParam('settings_copyright')); $extension = ($this->_http->getParam('settings_extension') == "") ? "sls" : SLS_String::trimSlashesFromString($this->_http->getParam('settings_extension')); $charset = SLS_String::trimSlashesFromString($this->_http->getParam('settings_charset')); $doctype = SLS_String::trimSlashesFromString($this->_http->getParam('settings_doctype')); $bo = SLS_String::trimSlashesFromString($this->_http->getParam('settings_bo')); $timezone_area = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area')); $timezone_city = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area_'.$timezone_area)); $xmlTmp = new SLS_XMLToolbox($handle); $allowedCharsets = $xmlTmp->getTags("//sls_configs/charset/code"); if ($this->_http->getParam('globalSettings_reload') == "true") { if (empty($domain)) array_push($errors,"You must fill your main domain name"); if ($protocol != 'http' && $protocol != 'https') array_push($errors,"You must choose a correct Protocol"); if (empty($project)) array_push($errors,"You must fill your project name"); if (empty($description)) array_push($errors,"You must fill your project description"); if (empty($author)) $author = $project; if (empty($copyright)) $copyright = $domain; if (empty($extension)) array_push($errors,"You must fill your default extension"); if (empty($bo)) array_push($errors,"You must fill your access to your SillySmart's Back-Office"); if (!in_array($charset,$allowedCharsets)) array_push($errors,"You must choose a valid charset"); if (empty($doctype)) array_push($errors,"You must choose your default doctype"); if (empty($timezone_area) || empty($timezone_city)) array_push($errors,"You must choose your default timezone"); if (empty($errors)) { $key = substr(md5($domain).sha1($project).uniqid(microtime()),mt_rand(5,10),mt_rand(20,32)); $coreXml = $this->_generic->getSiteXML(); $coreXml->setTag('//configs/domainName', "<domain alias='__default' default='1' js='true' isSecure='false' lang=''><![CDATA[".$domain."]]></domain>", false); $coreXml->setTag('//configs/protocol',$protocol); $coreXml->setTag('//configs/defaultExtension',$extension); $coreXml->setTag('//configs/projectName',$project); $coreXml->setTag('//configs/versionName',date("Ymd")."-dev"); $coreXml->setTag('//configs/metaDescription',$description); $coreXml->setTag('//configs/metaKeywords',$keywords); $coreXml->setTag('//configs/metaAuthor',$author); $coreXml->setTag('//configs/metaCopyright',$copyright); $coreXml->setTag('//configs/privateKey',$key); $coreXml->setTag('//configs/defaultCharset',strtoupper($charset)); $coreXml->setTag('//configs/defaultDoctype',$doctype); $coreXml->setTag('//configs/defaultTimezone',$timezone_area."/".$timezone_city); file_put_contents($this->_generic->getPathConfig("configSecure")."site.xml", $coreXml->getXML()); $controllersXml = $this->_generic->getControllersXML(); $controllersXml->setTag("//controllers/controller[@name='SLS_Bo']/controllerLangs/controllerLang",$bo); $uniqs = array(); $metas = array(); // Generate Controllers IDS $slsControllers = $controllersXml->getTags("//controllers/controller[@side='sls']/@name"); $slsLangs = $controllersXml->getTags("//controllers/controller[@side='sls'][1]/scontrollers/scontroller[1]/scontrollerLangs/scontrollerLang/@lang"); foreach ($slsControllers as $slsController) { // Take a random id and set it $uniq = uniqid("c_"); while(in_array($uniq, $uniqs)) $uniq = uniqid("c_"); array_push($uniqs, $uniq); $controllersXml->setTagAttributes("//controllers/controller[@name='".$slsController."' and @side='sls']", array("id"=>$uniq)); // Generate Actions IDS $slsActions = $controllersXml->getTags("//controllers/controller[@side='sls' and @name='".$slsController."']/scontrollers/scontroller/@name"); foreach ($slsActions as $slsAction) { // Take a random id and set it $uniq = uniqid("a_"); while(in_array($uniq, $uniqs)) $uniq = uniqid("a_"); array_push($uniqs, $uniq); $controllersXml->setTagAttributes("//controllers/controller[@name='".$slsController."' and @side='sls']/scontrollers/scontroller[@name='".$slsAction."']", array("id"=>$uniq)); // Get title attribute, save it into array and delete this attribute $tmpArray = array(); foreach ($slsLangs as $lang) { $tmpArray[$lang] = array_shift($controllersXml->getTags("//controllers/controller[@name='".$slsController."' and @side='sls']/scontrollers/scontroller[@name='".$slsAction."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']/@title")); $controllersXml->deleteTagAttribute("//controllers/controller[@name='".$slsController."' and @side='sls']/scontrollers/scontroller[@name='".$slsAction."']/scontrollerLangs/scontrollerLang[@lang='".$lang."']","title"); } $metas[$uniq] = $tmpArray; } } // Update metas.xml $metaXml = ''; foreach($metas as $key => $value) { $metaXml .= '<action id="'.$key.'">'; foreach ($value as $lang => $title) $metaXml .= '<title lang="'.$lang.'"><![CDATA['.$title.']]></title>'; $metaXml .= '<robots><![CDATA[noindex, nofollow]]></robots>'; $metaXml .= '</action>'; } $metaO = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."metas.xml")); $metaO->appendXML("//sls_configs",$metaXml); $metaO->saveXML($this->_generic->getPathConfig("configSls")."metas.xml"); // Overwrite template __default $this->createXslTemplate("__default",$doctype); file_put_contents($this->_generic->getPathConfig("configSecure")."controllers.xml", $controllersXml->getXML()); $this->setInstallationStep(array(0=>"SLS_Init",1=>"Initialization"), array(0=>"International",1=>"International")); return $this->_generic->dispatch("SLS_Init", "International"); } else { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); $xml->addFullTag("domain",$domain,true); $xml->addFullTag("protocol",$protocol,true); $xml->addFullTag("project",$project,true); $xml->addFullTag("description",$description,true); $xml->addFullTag("keywords",$keywords,true); $xml->addFullTag("author",$author,true); $xml->addFullTag("copyright",$copyright,true); $xml->addFullTag("extension",$extension,true); $xml->addFullTag("charset",$charset,true); $xml->addFullTag("doctype",$doctype,true); $xml->addFullTag("bo",$bo,true); $xml->startTag("timezone"); $xml->addFullTag("area",$timezone_area,true); $xml->addFullTag("city",$timezone_city,true); $xml->endTag("timezone"); } } else { $timezone = date_default_timezone_get(); $xml->addFullTag("domain",$_SERVER['HTTP_HOST'].(($_SERVER['SCRIPT_NAME'] != "/index.php") ? SLS_String::substrBeforeFirstDelimiter($_SERVER['SCRIPT_NAME'],"/index.php") : ""),true); $xml->addFullTag("protocol",(SLS_String::startsWith($_SERVER['SERVER_PROTOCOL'],'HTTPS')) ? 'https' : 'http',true); $xml->addFullTag("author","SillySmart",true); $xml->addFullTag("extension","sls",true); $xml->startTag("timezone"); $xml->addFullTag("area",(empty($timezone) || !SLS_String::contains($timezone,'/')) ? 'Europe' : SLS_String::substrBeforeFirstDelimiter($timezone,'/'),true); $xml->addFullTag("city",(empty($timezone) || !SLS_String::contains($timezone,'/')) ? 'Paris' : SLS_String::substrAfterFirstDelimiter($timezone,'/'),true); $xml->endTag("timezone"); $xml->addFullTag("bo","Manage",true); } $this->saveXML($xml); }
/** * Format XML for the current recordset * * @access public * @param SLS_XMLToolbox $xml current controller's XML * @param array $options transformations on some columns - delimited by ":". each function can be methods of SLS' classes or php standard function * <code> * // Complete example * $xml = $news->toXML($xml, array( "news_excerpt" => array("php:strip_tags", "SLS_String:trimStringToLength:100"), * "news_date" => array("SLS_Date:getDate:FULL_LITTERAL_TIME", "php:ucwords"), * "news_photo" => "SLS_String:getUrlFileImg:_0", * "news_pdf" => "SLS_String:getUrlFile", * "news_title" => "php:trim", * "news_link" => array("/Item/", * "news_title" => "SLS_String:stringToUrl:_", * "-", * "news_id" => array("php:intval","php:pow:2"), * "/User/", * "user_id")) * , true, "news"); * </code> * @param mixed $fks (bool: if true all fks, if false only current Model) - array fks you want to extract params * @param string $nodeName the root node of your model, by default it's your classname in lowercase * @param array $properties all columns/values of your choice if you don't want to take it from getParams() function of the current instance * @return SLS_XMLToolbox $xml current controller's XML updated * @see SLS_FrontModel::getParams * @see SLS_FrontModel::pdoToXML * @since 1.0.8 */ public function toXML($xml,$options=array(),$fks=false,$nodeName="",$properties=array()) { $nodeName = (empty($nodeName)) ? strtolower($this->getTable()) : $nodeName; $properties = (empty($properties)) ? $this->getParams($fks) : $properties; $xml->startTag($nodeName); foreach($properties as $column => $value) { if (in_array($column,$columns=array_keys($options))) { $filters = (is_array($options[$column])) ? $options[$column] : array($options[$column]); foreach($filters as $filter) { $option = explode(":",$filter); switch($option[0]) { case SLS_String::startsWith($option[0],"SLS_"): if (!class_exists($option[0])) SLS_Tracing::addTrace(new Exception("Error: you want to use an undefined class `".$option[0]."` for the column `".$column."` of `".$this->getTable()."` table")); else { if (!method_exists($option[0],((count($option)> 1) ? $option[1] : ""))) SLS_Tracing::addTrace(new Exception("Error: you want to use an undefined function `".$option[1]."` of class `".$option[0]."` for the column `".$column."` of `".$this->getTable()."` table")); else { $ref = new ReflectionMethod($option[0],$option[1]); $nbRequiredParams = $ref->getNumberOfRequiredParameters(); if ($nbRequiredParams > (count($option)-1)) SLS_Tracing::addTrace(new Exception("Error: function `".$option[1]."` of class `".$option[0]."` needs ".$nbRequiredParams." required parameters for the column `".$column."` of `".$this->getTable()."` table"),true); else { $params = array_slice($option,2); array_unshift($params,$value); // Case "SLS_Date::getDate" if ($option[0] == "SLS_Date" && $option[1] == "getDate") { $option[0] = new SLS_Date($value); array_shift($params); } // Case "SLS_String::getUrlFileImg" if ($option[0] == "SLS_String" && $option[1] == "getUrlFileImg" && count($option) > 2) { $xml->addFullTag($column."_original",SLS_String::getUrlFile($value,(count($option) > 3) ? $option[3] : ""),true); $column = $column.$option[2]; } $value = $ref->invokeArgs(($ref->isStatic()) ? null : $option[0],$params); } } } break; case "php": if (count($option) < 2) SLS_Tracing::addTrace(new Exception("Error: you must specify the name of the PHP's function you want to apply on the column `".$column."` of `".$this->getTable()."` table")); else { if (function_exists($option[1])) { $ref = new ReflectionFunction($option[1]); $nbRequiredParams = $ref->getNumberOfRequiredParameters(); if ($nbRequiredParams > (count($option)-1)) SLS_Tracing::addTrace(new Exception("Error: the PHP's function `".$option[1]."` needs ".$nbRequiredParams." required parameters for the column `".$column."` of `".$this->getTable()."` table"),true); else { $params = array_slice($option,2); array_unshift($params,$value); $value = $ref->invokeArgs($params); } } else SLS_Tracing::addTrace(new Exception("Error: the PHP's function '".$option[1]."' you want to use on the column `".$column."` of `".$this->getTable()."` table doesn't exist")); } break; default: SLS_Tracing::addTrace(new Exception("Error: you want to apply an unknown filter on the column `".$column."` of `".$this->getTable()."` table doesn't exist")); break; } } } $xml->addFullTag($column,$value,true); } foreach($options as $col => $concat) { if (!in_array($col,array_keys($properties)) && is_array($concat)) { $values = array(); foreach($concat as $column => $filter) { if (is_int($column) && !empty($filter) && !is_array($filter)) { $column = $filter; $filter = ""; } $value = ""; $filters = (is_array($filter)) ? $filter : ((empty($filter)) ? "" : array($filter)); if (in_array($column,array_keys($properties))) $value .= $properties[$column]; else $value .= $column; if (!empty($filters)) { foreach($filters as $filter) { $option = explode(":",$filter); switch($option[0]) { case SLS_String::startsWith($option[0],"SLS_"): if (!class_exists($option[0])) SLS_Tracing::addTrace(new Exception("Error: you want to use an undefined class `".$option[0]."` for the column `".$column."` of `".$this->getTable()."` table")); else { if (!method_exists($option[0],((count($option)> 1) ? $option[1] : ""))) SLS_Tracing::addTrace(new Exception("Error: you want to use an undefined function `".$option[1]."` of class `".$option[0]."` for the column `".$column."` of `".$this->getTable()."` table")); else { $ref = new ReflectionMethod($option[0],$option[1]); $nbRequiredParams = $ref->getNumberOfRequiredParameters(); if ($nbRequiredParams > (count($option)-1)) SLS_Tracing::addTrace(new Exception("Error: function `".$option[1]."` of class `".$option[0]."` needs ".$nbRequiredParams." required parameters for the column `".$column."` of `".$this->getTable()."` table"),true); else { $params = array_slice($option,2); array_unshift($params,$value); // Case "SLS_Date::getDate" if ($option[0] == "SLS_Date" && $option[1] == "getDate") { $option[0] = new SLS_Date($value); array_shift($params); } // Case "SLS_String::getUrlFileImg" if ($option[0] == "SLS_String" && $option[1] == "getUrlFileImg" && count($option) > 2) { $xml->addFullTag($column."_original",SLS_String::getUrlFile($value),true); $column = $column.$option[2]; } $value = $ref->invokeArgs(($ref->isStatic()) ? null : $option[0],$params); } } } break; case "php": if (count($option) < 2) SLS_Tracing::addTrace(new Exception("Error: you must specify the name of the PHP's function you want to apply on the column `".$column."` of `".$this->getTable()."` table")); else { if (function_exists($option[1])) { $ref = new ReflectionFunction($option[1]); $nbRequiredParams = $ref->getNumberOfRequiredParameters(); if ($nbRequiredParams > (count($option)-1)) SLS_Tracing::addTrace(new Exception("Error: the PHP's function `".$option[1]."` needs ".$nbRequiredParams." required parameters for the column `".$column."` of `".$this->getTable()."` table"),true); else { $params = array_slice($option,2); array_unshift($params,$value); $value = $ref->invokeArgs($params); } } else SLS_Tracing::addTrace(new Exception("Error: the PHP's function '".$option[1]."' you want to use on the column `".$column."` of `".$this->getTable()."` table doesn't exist")); } break; default: SLS_Tracing::addTrace(new Exception("Error: you want to apply an unknown filter on the column `".$column."` of `".$this->getTable()."` table doesn't exist")); break; } } } $values[] = $value; } $xml->addFullTag($col,implode("",$values),true); } } $xml->endTag($nodeName); return $xml; }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $langs = $this->_generic->getObjectLang()->getSiteLangs(); $listing = true; $errors = array(); $protocol = $this->_generic->getProtocol(); $siteXML = $this->_generic->getSiteXML(); $aliasesSelected = array(); $componentsSelected = array(); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginMobile = $plugin->getTag("//plugins/plugin[@code='mobile']"); $pluginMobile = (!empty($pluginMobile)) ? true : false; $controllersXML = $this->_generic->getControllersXML(); $controller = SLS_String::trimSlashesFromString($this->_http->getParam("Controller")); $controllers = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']"); if (count($controllers) == 1) { $controllerID = array_shift($controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/@id")); $protocol = $this->_generic->getControllerProtocol($controllerID); $listing = false; $xml->addFullTag('request', 'AddAction', true); if ($this->_http->getParam('reload') == 'true') { // Get the form informations $newAction = SLS_String::stringToUrl(ucwords(SLS_String::trimSlashesFromString($this->_http->getParam("actionName"))), "", false); $needDynamic = SLS_String::trimSlashesFromString($this->_http->getParam("dynamic")); $needOffline = SLS_String::trimSlashesFromString($this->_http->getParam("offline")); $needDefault = SLS_String::trimSlashesFromString($this->_http->getParam("default")); $searchEngine = SLS_String::trimSlashesFromString($this->_http->getParam("indexes")); $postProtocol = SLS_String::trimSlashesFromString($this->_http->getParam("protocol")); $tpl = SLS_String::trimSlashesFromString($this->_http->getParam('template')); $aliases = SLS_String::trimSlashesFromString($this->_http->getParam('domains')); $components = SLS_String::trimSlashesFromString($this->_http->getParam('components')); $cache_visibility = SLS_String::trimSlashesFromString($this->_http->getParam('cache_visibility')); $cache_scope = SLS_String::trimSlashesFromString($this->_http->getParam('cache_scope')); $cache_expiration = SLS_String::trimSlashesFromString($this->_http->getParam('cache_expiration')); $cache_responsive = SLS_String::trimSlashesFromString($this->_http->getParam('cache_responsive')); if (empty($postProtocol)) $postProtocol = "http"; $postActionsLang = array(); $postTitlesLang = array(); $postDescriptionsLang = array(); $postKeywordsLang = array(); $toCache = (in_array($cache_visibility,array("public","private"))) ? true : false; // If responsive wanted if ($cache_responsive == "true" && !$pluginMobile) { // Force Mobile plugin download file_get_contents($this->_generic->getFullPath("SLS_Bo", "SearchPlugin", array("Action" => "Download", "Server" => "4", "Plugin" => "20", "token" => sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))), true)); } if (empty($newAction)) array_push($errors, "Action name can't be empty"); $actionExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@name='".$newAction."']"); if (count($actionExist) == 0) { if (empty($postProtocol) || ($postProtocol != 'http' && $postProtocol != 'https')) array_push($errors, "Protocol must be http or https"); else $protocol = $postProtocol; if (!empty($aliases) && is_array($aliases)) foreach($aliases as $alias) array_push($aliasesSelected,$alias); if (!empty($components) && is_array($components)) foreach($components as $component) array_push($componentsSelected,$component); $siteLangs = $this->_generic->getObjectLang()->getSiteLangs(); foreach ($siteLangs as $lang) { // Check Url $postLang = trim(SLS_String::stringToUrl(SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-action")), "", false)); $translationExist = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/scontrollerLangs[scontrollerLang = '".$postLang."']"); if (empty($postLang)) array_push($errors, "You need to fill the ".$lang." url translations"); elseif(count($translationExist) != 0) array_push($errors, "You URL translation in ".$lang." is already in use on another action in the same controller"); else $postActionsLang[$lang] = $postLang; // Get Titles $postTitlesLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-title")); // Get Description $postDescriptionsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-description")); // Get Keywords $postKeywordsLang[$lang] = SLS_String::trimSlashesFromString($this->_http->getParam(strtolower($lang)."-keywords")); } if ($toCache && (!is_numeric($cache_expiration) || $cache_expiration < 0)) array_push($errors, "Your expiration cache must be a positive time or 0"); if ($toCache && (!in_array($cache_scope,array("full","partial")))) array_push($errors, "Your must describe your cache scope"); if (count($errors) == 0) { // If an error existing and the controller directory wasn't created if (!is_dir($this->_generic->getPathConfig("actionsControllers").$controller)) mkdir($this->_generic->getPathConfig("actionsControllers").$controller); if (!is_file($this->_generic->getPathConfig("actionsControllers").$controller."/__".$controller.".protected.php")) { $strControllerProtected = '<?php'."\n". '/**'."\n". '* Class generic for the controller '.$newControllerName.''."\n". '* Write here all your generic functions you need in your '.$newControllerName.' Actions'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Controllers.'.$newControllerName.''."\n". '* @see Mvc.Controllers.SiteProtected'."\n". '* @see Sls.Controllers.Core.SLS_GenericController'."\n". '* @since 1.0'."\n". '*/'."\n". 'class '.$newControllerName.'ControllerProtected extends SiteProtected'."\n". '{'."\n". t(1).'public function init()'."\n". t(1).'{'."\n". t(2).'parent::init();'."\n". t(1).'}'."\n". '}'."\n". '?>'; file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/__".$controller.".protected.php", $strControllerProtected); } // Create Controller File $strControllerAction = '<?php'."\n". '/**'."\n". '* Class '.$newAction.' into '.$controller.' Controller'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Controllers.'.$controller."\n". '* @see Mvc.Controllers.'.$controller.'.ControllerProtected'."\n". '* @see Mvc.Controllers.SiteProtected'."\n". '* @see Sls.Controllers.Core.SLS_GenericController'."\n". '* @since 1.0'."\n". '*'."\n". '*/'."\n". 'class '.$controller.$newAction.' extends '.$controller.'ControllerProtected'."\n". '{'."\n". t(1).'public function init()'."\n". t(1).'{'."\n". t(2).'parent::init();'."\n". t(1).'}'."\n\n". t(1).'public function action()'."\n". t(1).'{'."\n". t(2)."\n". t(1).'}'."\n". "}\n". '?>'; file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/".$newAction.".controller.php", $strControllerAction); // Create Lang Files if (!is_dir($this->_generic->getPathConfig("langs")."Actions/".$controller)) mkdir($this->_generic->getPathConfig("langs")."Actions/".$controller); $langsFiles = array(); foreach ($siteLangs as $lang) { $strLang = '<?php'."\n". '/**'."\n". '* '.strtoupper($lang).' File for the action '.$newAction.' into '.$controller.' Controller'."\n". '* You can create all your sentences variables here. To create it, follow the exemple :'."\n". '* '."\t".'Access it with JS and XSL variable : $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'KEY_OF_YOUR_VARIABLE\'] = "value of your sentence in '.strtoupper($lang).'";'."\n". '* '."\t".'Access it with XSL variable only : $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'XSL\'][\'KEY_OF_YOUR_VARIABLE\'] = "value of your sentence in '.strtoupper($lang).'";'."\n". '*'."\n". '* '."\t".'You can customise the value \'KEY_OF_YOUR_VARIABLE\' and "value of your sentence in '.strtoupper($lang).'" '."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Langs.Actions.'.$controller."\n". '* @since 1.0'."\n". '*'."\n". '*/'."\n". '?>'; file_put_contents($this->_generic->getPathConfig("langs")."Actions/".$controller."/".$newAction.".".strtolower($lang).".lang.php", $strLang); } // Create Views File if (!is_dir($this->_generic->getPathConfig("viewsBody").$controller)) mkdir($this->_generic->getPathConfig("viewsBody").$controller); if (!is_dir($this->_generic->getPathConfig("viewsHeaders").$controller)) mkdir($this->_generic->getPathConfig("viewsHeaders").$controller); $strBody = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n". t(1).'<xsl:template name="'.$newAction.'">'."\n". t(2).'<h1>Customize the body of this page in <i>'.$this->_generic->getPathConfig('viewsBody').$controller.'/'.$newAction.'.xsl</i></h1>'."\n". t(2).'<h2>And your headers in <i>'.$this->_generic->getPathConfig('viewsHeaders').$controller.'/'.$newAction.'.xsl</i></h2>'."\n". t(1).'</xsl:template>'."\n". '</xsl:stylesheet>'; $strHeader = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n". t(1).'<xsl:template name="Header'.$newAction.'">'."\n". t(1).'</xsl:template>'."\n". '</xsl:stylesheet>'; file_put_contents($this->_generic->getPathConfig("viewsBody").$controller.'/'.$newAction.'.xsl', $strBody); file_put_contents($this->_generic->getPathConfig("viewsHeaders").$controller.'/'.$newAction.'.xsl', $strHeader); // End of files creation // XML Modifications $metasXML = $this->_generic->getCoreXML('metas'); // Get the titles // If default, reset other in current controller if (!empty($needDefault)) { $actions = $controllersXML->getTags("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller/@id"); foreach($actions as $curActionId) $controllersXML->setTagAttributes("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers/scontroller[@id='".$curActionId."']", array('default' => '0')); } $actionId = $this->_generic->generateActionId(); $xmlAction = "<scontroller name=\"".$newAction."\" needParam=\""; $xmlAction .= ($this->_http->getParam("dynamic") == "on") ? "1" : "0"; $xmlAction .= "\" id=\"".$actionId."\" protocol=\"".$protocol."\""; if ($tpl != -1) $xmlAction .= " tpl=\"".$tpl."\""; if (!empty($aliases)) $xmlAction .= " domains=\"".implode(",",$aliases)."\""; if (!empty($components)) $xmlAction .= " components=\"".implode(",",$components)."\""; if (!empty($needOffline)) $xmlAction .= " disable=\"1\""; if (!empty($needDefault)) $xmlAction .= " default=\"1\""; if ($toCache) $xmlAction .= " cache=\"".$cache_visibility."|".$cache_scope."|".(($cache_responsive == "true") ? "responsive" : "no_responsive")."|".$cache_expiration."\""; $xmlAction .= "><scontrollerLangs>"; $strMetas = "<action id=\"".$actionId."\" />"; $metasXML->appendXMLNode("//sls_configs", $strMetas); foreach ($siteLangs as $lang) { $xmlAction .= "<scontrollerLang lang=\"".$lang."\"><![CDATA[".$postActionsLang[$lang]."]]></scontrollerLang>"; // Metas $metas = "<title lang=\"".$lang."\"><![CDATA[".$postTitlesLang[$lang]."]]></title>"; $metas .= "<description lang=\"".$lang."\"><![CDATA[".$postDescriptionsLang[$lang]."]]></description>"; $metas .= "<keywords lang=\"".$lang."\"><![CDATA[".$postKeywordsLang[$lang]."]]></keywords>"; $metasXML->appendXMLNode("//sls_configs/action[@id=\"".$actionId."\"]", $metas); } $xmlAction .= "</scontrollerLangs></scontroller>"; if (!SLS_String::contains($searchEngine,", ")) $searchEngine = str_replace(",",", ",$searchEngine); if ($searchEngine != "index, follow" && $searchEngine != "noindex, follow" && $searchEngine != "noindex, nofollow" && $searchEngine != "index, nofollow") $searchEngine = "index, follow"; $metasXML->appendXMLNode("//sls_configs/action[@id='".$actionId."']", "<robots><![CDATA[".$searchEngine."]]></robots>"); $controllersXML->appendXMLNode("//controllers/controller[@side='user' and @name='".$controller."']/scontrollers", $xmlAction); file_put_contents($this->_generic->getPathConfig("configSecure")."controllers.xml", $controllersXML->getXML()); file_put_contents($this->_generic->getPathConfig("configSls")."metas.xml", $metasXML->getXML()); $controllers = $this->_generic->getTranslatedController("SLS_Bo", "Controllers"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller'].".sls"); } } else array_push($errors, "This generic name is already in use for this controller"); if (!empty($errors)) { $xml->startTag("errors"); foreach ($errors as $error) $xml->addFullTag("error", $error, true); $xml->endTag("errors"); $xml->startTag('form'); $xml->addFullTag("controllerName", $postControllerName); foreach ($postActionsLang as $key=>$value) $xml->addFullTag($key."-action", $value, true); $xml->endTag('form'); $xml->addFullTag("default",(empty($needDefault)) ? "false" : "true",true); $xml->addFullTag("dynamic",(empty($needDynamic)) ? "false" : "true",true); $xml->addFullTag("offline",(empty($needOffline)) ? "false" : "true",true); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", $cache_visibility,true); $xml->addFullTag("cache_scope", $cache_scope,true); $xml->addFullTag("cache_responsive", $cache_responsive,true); $xml->addFullTag("cache_expiration", $cache_expiration,true); $xml->endTag("cache"); } } else { $defaultExists = $controllersXML->getTag("//controllers/controller[@name='".$controller."']/scontrollers/scontroller[@default='1']/@name"); $xml->addFullTag("default",(empty($defaultExists)) ? "true" : "false",true); $xml->startTag("cache"); $xml->addFullTag("cache_visibility", "",true); $xml->addFullTag("cache_scope", "",true); $xml->addFullTag("cache_responsive","",true); $xml->addFullTag("cache_expiration", 0,true); $xml->endTag("cache"); } // Build all tpls $tpls = $this->getAppTpls(); $xml->startTag("tpls"); foreach($tpls as $template) $xml->addFullTag("tpl",$template,true); $xml->endTag("tpls"); $xml->startTag('controller'); $xml->addFullTag("name", $controller, true); $xml->startTag('translations'); foreach ($langs as $lang) { $xml->startTag('translation'); $xml->addFullTag("lang", $lang, true); $xml->addFullTag("name", $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/controllerLangs/controllerLang[@lang='".$lang."']"), true); $xml->endTag('translation'); } $xml->endTag('translations'); $xml->endTag('controller'); $xml->addFullTag('request', 'addAction', true); } else { $this->_generic->dispatch('SLS_Bo', 'Controllers'); } if (empty($tpl)) $tpl = $controllersXML->getTag("//controllers/controller[@name='".$controller."' and @side='user']/@tpl"); $xml->addFullTag('protocol', $protocol, true); $xml->addFullTag('template', $tpl, true); $aliases = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); $xml->startTag("aliases"); for($i=0 ; $i<$count=count($aliases) ; $i++) { $xml->startTag("alias"); $xml->addFullTag("name",$aliases[$i]["attributes"][0]["value"],true); $xml->addFullTag("selected",(in_array($aliases[$i]["attributes"][0]["value"],$aliasesSelected)) ? "true" : "false",true); $xml->endTag("alias"); } $xml->endTag("aliases"); $components = $this->_generic->recursiveReadDir($this->_generic->getPathConfig("componentsControllers"), array(), array(0=>"php")); $xml->startTag("components"); foreach ($components as $component) { $xml->startTag("component"); $xml->addFullTag("name", SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),true); $xml->addFullTag("selected",(in_array(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterLastDelimiter($component, "/"), ".controller.php"),$componentsSelected)) ? "true" : "false",true); $xml->endTag("component"); } $xml->endTag("components"); $this->saveXML($xml); }
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('‹![CDATA[',']]›'), $value), true); $xml->endTag("current_values"); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $siteXML = $this->_generic->getSiteXML(); $errors = array(); $aliases = array(); $domains = array(); // Prod Deployment $env = $this->_http->getParam("Env"); if (empty($env)) $env = "prod"; $finalFile = ($this->_http->getParam("ProdDeployment") == "true") ? "site_".$env.".xml" : "site.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); $xml->addFullTag("env",$env,true); // Get default values if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) { $xmlSite = new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")); $defaultDomain = $xmlSite->getTag("//configs/domainName/domain"); $defaultProject = $xmlSite->getTag("//configs/projectName"); $defaultVersion = $xmlSite->getTag("//configs/versionName"); $defaultExtension = $xmlSite->getTag("//configs/defaultExtension"); $defaultCharset = $xmlSite->getTag("//configs/defaultCharset"); $defaultDoctype = $xmlSite->getTag("//configs/defaultDoctype"); $timezone_area = SLS_String::substrBeforeFirstDelimiter($xmlSite->getTag("//configs/defaultTimezone"),"/"); $timezone_city = SLS_String::substrAfterFirstDelimiter($xmlSite->getTag("//configs/defaultTimezone"),"/"); $defaultLang = $xmlSite->getTag("//configs/defaultLang"); $defaultdomainSessionShare = $xmlSite->getTag("//configs/domainSession"); } else { $defaultDomain = $this->_generic->getSiteConfig("domainName"); $defaultProject = $this->_generic->getSiteConfig("projectName"); $defaultVersion = $this->_generic->getSiteConfig("versionName"); $defaultExtension = $this->_generic->getSiteConfig("defaultExtension"); $defaultCharset = $this->_generic->getSiteConfig("defaultCharset"); $defaultDoctype = $this->_generic->getSiteConfig("defaultDcotype"); $timezone_area = SLS_String::substrBeforeFirstDelimiter($this->_generic->getSiteConfig("defaultTimezone"),"/"); $timezone_city = SLS_String::substrAfterFirstDelimiter($this->_generic->getSiteConfig("defaultTimezone"),"/"); $defaultLang = $this->_generic->getSiteConfig("defaultLang"); $defaultdomainSessionShare = $this->_generic->getSiteConfig("domainSession"); } $reload = $this->_http->getParam("reload"); $charsetsXML = new SLS_XMLToolBox(file_get_contents($this->_generic->getPathConfig('configSls')."charset.xml")); $charsets = array_map('strtoupper', $charsetsXML->getTags('//sls_configs/charset/code')); $handle2 = file_get_contents($this->_generic->getPathConfig("configSls").'timezone.xml'); $xml->addFullTag("timezones", SLS_String::substrBeforeLastDelimiter(SLS_String::substrAfterFirstDelimiter($handle2, "<sls_configs>"), "</sls_configs>"), false); $langs = $this->_generic->getSiteXML()->getTags('//configs/langs/name'); if ($reload == "true") { $domains = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias")); for($i=0 ; $i<$count=count($domains) ; $i++) array_push($aliases,$domains[$i]["attributes"][0]["value"]); // Get New Parameters $exportConfig = $this->_http->getParam('export'); $domains = array(); foreach($aliases as $alias) { $domain = SLS_String::trimSlashesFromString($this->_http->getParam("domain_".$alias, "post")); if (SLS_String::endsWith(trim($domain),"/")) $domain = SLS_String::substrBeforeLastDelimiter(trim($domain),"/"); $domains[$alias]= $domain; } $postProject = SLS_String::trimSlashesFromString($this->_http->getParam("project", "post")); $postVersion = SLS_String::trimSlashesFromString($this->_http->getParam("version", "post")); $postExtension = SLS_String::trimSlashesFromString($this->_http->getParam("extension", "post")); $postCharset = SLS_String::trimSlashesFromString($this->_http->getParam("charset", "post")); $postDoctype = SLS_String::trimSlashesFromString($this->_http->getParam("doctype", "post")); $timezone_area = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area')); $timezone_city = SLS_String::trimSlashesFromString($this->_http->getParam('settings_timezone_area_'.$timezone_area)); $postLang = SLS_String::trimSlashesFromString($this->_http->getParam("lang", "post")); $domainSessionShare = SLS_String::trimSlashesFromString($this->_http->getParam("domainSession", "post")); if ($this->_http->getParam("domainSessionActive") == "") $domainSessionShare = ""; foreach($domains as $alias => $domain) if (empty($domain)) array_push($errors, "The Domain name is required for the domain alias ".$alias); if (empty($postProject)) array_push($errors, "The project Name is required"); if (empty($postVersion)) array_push($errors, "The version Name is required"); if (empty($postExtension)) array_push($errors, "The extension is required"); if (!in_array($postCharset, $charsets)) array_push($errors, "The Charset selected is incorrect"); if (empty($postDoctype)) array_push($errors, "The doctype is required"); if (empty($timezone_area) || empty($timezone_city)) array_push($errors,"You must choose your default timezone"); if (!in_array($postLang, $langs)) array_push($errors, "The Default lang selected is incorrect"); if ($this->_http->getParam("domainSessionActive") != "" && empty($domainSessionShare)) array_push($errors,"You need to fill the domain pattern from which you want to share session"); if (empty($errors)) { foreach($domains as $alias => $domain) $siteXML->setTag("//configs/domainName/domain[@alias='".$alias."']", $domain, true); if ($defaultProject != $postProject) $siteXML->setTag("//configs/projectName", $postProject, true); if ($defaultVersion != $postVersion) $siteXML->setTag("//configs/versionName", $postVersion, true); if ($defaultExtension != $postExtension) $siteXML->setTag("//configs/defaultExtension", $postExtension, true); if ($defaultCharset != $postCharset) $siteXML->setTag("//configs/defaultCharset", $postCharset, true); if ($defaultDoctype != $postDoctype) $siteXML->setTag("//configs/defaultDoctype", $postDoctype, true); if ($defaultTimezone != $timezone_area."/".$timezone_city) $siteXML->setTag("//configs/defaultTimezone", $timezone_area."/".$timezone_city, true); if ($defaultLang != $postLang) $siteXML->setTag("//configs/defaultLang", $postLang, true); if ($defaultdomainSessionShare != $domainSessionShare) $siteXML->setTag("//configs/domainSession", $domainSessionShare, true); if ($exportConfig == "on") { $date = gmdate('D, d M Y H:i:s'); header("Content-Type: text/xml"); header('Content-Disposition: attachment; filename='.$finalFile); header('Last-Modified: '.$date. ' GMT'); header('Expires: ' .$date); // For This F**k'in Browser if(preg_match('/msie|(microsoft internet explorer)/i', $_SERVER['HTTP_USER_AGENT'])) { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else header('Pragma: no-cache'); print($siteXML->getXML()); exit; } else { $siteXML->refresh(); @file_put_contents($this->_generic->getPathConfig("configSecure").$finalFile, $siteXML->getXML()); if ($isInBatch) $this->_generic->forward("SLS_Bo","DataBaseSettings",array(array("key"=>"ProdDeployment","value"=>"true"),array("key"=>"CompleteBatch","value"=>"true"),array("key"=>"Env","value"=>$env))); else if ($this->_http->getParam("ProdDeployment") == "true") $this->_generic->forward("SLS_Bo","ProductionDeployment"); } } else { $xml->startTag('errors'); foreach ($errors as $error) $xml->addFullTag('error', $error); $xml->endTag('errors'); } } $this->_generic->eraseCache('Site'); $xml->startTag("charsets"); foreach ($charsets as $charset) $xml->addFullTag('charset', $charset, true); $xml->endTag("charsets"); $xml->startTag("langs"); foreach ($langs as $lang) $xml->addFullTag('lang', $lang, true); $xml->endTag("langs"); $xmlSite = (file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? new SLS_XMLToolbox(file_get_contents($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) : null; $xml->startTag("current_values"); if ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) $domains = $xmlSite->getTagsAttributes("//configs/domainName/domain",array("alias","default","lang")); else $domains = $siteXML->getTagsAttributes("//configs/domainName/domain",array("alias","default","lang")); $xml->startTag("domains"); for($i=0 ; $i<$count=count($domains) ; $i++) { $alias = $domains[$i]["attributes"][0]["value"]; $default = ($domains[$i]["attributes"][1]["value"] == 1) ? true : false; $domain_lang = $domains[$i]["attributes"][2]["value"]; $xml->startTag("domain"); $xml->addFullTag("alias",$alias,true); $xml->addFullTag("default",($default) ? "true" : "false",true); $xml->addFullTag("domain",$domains[$i]["value"],true); $xml->addFullTag("lang",$domain_lang,true); $xml->addFullTag("delete_url",$this->_generic->getFullPath("SLS_Bo","DeleteDomain",array(array("key"=>"alias","value"=>$alias))),true); $xml->endTag("domain"); } $xml->endTag("domains"); $xml->addFullTag("project", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/projectName") : $this->_generic->getSiteConfig("projectName"), true); $xml->addFullTag("version", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/versionName") : $this->_generic->getSiteConfig("versionName"), true); $xml->addFullTag("extension", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultExtension") :$this->_generic->getSiteConfig("defaultExtension"), true); $xml->addFullTag("charset", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultCharset") :$this->_generic->getSiteConfig("defaultCharset"), true); $xml->addFullTag("doctype", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultDoctype") :$this->_generic->getSiteConfig("defaultDoctype"), true); $xml->addFullTag("lang", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/defaultLang") :$this->_generic->getSiteConfig("defaultLang"), true); $xml->addFullTag("domain_session", ($this->_http->getParam("ProdDeployment") == "true" && file_exists($this->_generic->getRoot().$this->_generic->getPathConfig("configSecure")."/site_".$env.".xml")) ? $xmlSite->getTag("//configs/domainSession") : ((is_null($this->_generic->getSiteConfig("domainSession"))) ? "" : $this->_generic->getSiteConfig("domainSession")), true); $xml->startTag("timezone"); $xml->addFullTag("area",$timezone_area,true); $xml->addFullTag("city",$timezone_city,true); $xml->endTag("timezone"); $xml->endTag("current_values"); $xml->addFullTag("add_domain_url",$this->_generic->getFullPath("SLS_Bo","AddDomain"),true); $environments = $this->getEnvironments(); $xml->startTag("environments"); foreach($environments as $environment) $xml->addFullTag("environment",$environment,true); $xml->endTag("environments"); $this->saveXML($xml); }