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() { // 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() { $user = $this->hasAuthorative(); // Objects $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $xmlBearer = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bearers.xml")); // Get the table & class name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $result = array_shift($xmlBearer->getTagsAttributes("//sls_configs/entry[@tableBearer='".$class."']",array("table1"))); if (!empty($result)) $xmlBearer->saveXML($this->_generic->getPathConfig("configSls")."/bearers.xml",$xmlBearer->deleteTags("//sls_configs/entry[@tableBearer='".$class."']")); $this->_generic->forward("SLS_Bo","EditModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); }
public function action() { $user = $this->hasAuthorative(); $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); }
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); } }
public function action() { set_time_limit(0); $user = $this->hasAuthorative(); $errors = array(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); // Get all models $models = array(); $handle = opendir($this->_generic->getPathConfig("models")); while (false !== ($file = readdir($handle))) { if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") { $modelExploded = explode(".",$file); array_push($models,strtolower($modelExploded[0]).".".$modelExploded[1]); } } // If reload if ($this->_http->getParam("reload")=="true") { // Get the tables dude wants to generate $tablesG = ($this->_http->getParam("tables")=="") ? array() : $this->_http->getParam("tables"); // Foreach tables, generate model foreach($tablesG as $tableG) { $db = Sls_String::substrBeforeFirstDelimiter($tableG,"."); $table = Sls_String::substrAfterFirstDelimiter($tableG,"."); // Change db if it's required if ($sql->getCurrentDb() != $db) $sql->changeDb($db); // If table exists if ($sql->tableExists($table)) { $columns = $sql->showColumns($table); $tableName = $table; $currentTable = array("table"=>$db.".".$tableName,"errors"=>array()); $fieldsOk = true; $className = ucfirst($db)."_".SLS_String::tableToClass($tableName); $fileName = ucfirst($db).".".SLS_String::tableToClass($table).".model.php"; for($i=0 ; $i<$count=count($columns) ; $i++) { // Check forbidden chars if (SLS_String::removePhpChars($columns[$i]->Field) != $columns[$i]->Field) { $error = array("column"=>$columns[$i]->Field,"column_clean"=>SLS_String::removePhpChars($columns[$i]->Field)); array_push($currentTable["errors"],$error); $fieldsOk = false; } } // If all ok with special chars for the current model if ($fieldsOk) { // Check real fks $create = array_shift($sql->select("SHOW CREATE TABLE `".$table."`")); $queries = array_map("trim",explode("\n",$create->{Create." ".Table})); foreach($queries as $query) { if (SLS_String::startsWith($query,"CONSTRAINT")) { $tableFk = strtolower($db."_".$tableName); $columnFk = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"FOREIGN KEY (`"),"`)"); $tablePk = $db."_".SLS_String::tableToClass(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`")); $onDelete = strtolower(SLS_String::stringToUrl(trim(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"ON DELETE"),"ON UPDATE")),"_")); $labelPk = ""; $columns = $sql->showColumns(SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`")); for($i=0 ; $i<$count=count($columns) ; $i++) { if ($columns[$i]->Key != "PRI" && $columns[$i]->Field != "pk_lang" && SLS_String::contains($columns[$i]->Type,"char")) { $labelPk = $columns[$i]->Field; break; } } if (empty($labelPk)) $labelPk = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `".SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter($query,"REFERENCES `"),"`")."` (`"),"`)"); $xmlNode = '<entry tableFk="'.$tableFk.'" columnFk="'.$columnFk.'" multilanguage="false" ondelete="'.$onDelete.'" labelPk="'.$labelPk.'" tablePk="'.$tablePk.'" />'; $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); $result = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$tableFk."' and @columnFk='".$columnFk."' and @tablePk='".$tablePk."']"); if (!empty($result)) { $xmlTmp = $xmlFk->deleteTags("//sls_configs/entry[@tableFk='".$tableFk."' and @columnFk='".$columnFk."' and @tablePk='".$tablePk."']"); $xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlTmp); $xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml")); } $xmlFk->appendXMLNode("//sls_configs",$xmlNode); $xmlFk->saveXML($this->_generic->getPathConfig("configSls")."/fks.xml",$xmlFk->getXML()); } } // Generate Model $contentM = $this->getModelSource($tableName,$db); $status = touch($this->_generic->getPathConfig("models")."/".$fileName); if ($status) file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM); // Create SQL $fileNameS = ucfirst($db).".".SLS_String::tableToClass($table).".sql.php"; $contentS = '<?php'."\n". '/**'."\n". '* Object '.$className.'Sql'."\n". '* @author SillySmart'."\n". '* @copyright SillySmart'."\n". '* @package Mvc.Models.Objects'."\n". '* @see Sls.Models.Core.SLS_FrontModel'."\n". '* @since 1.0'."\n". '*/'."\n". 'class '.$className.'Sql extends SLS_FrontModelSql'."\n". '{'."\n". ''."\n". '}'."\n". '?>'; if ($status) $status2 = touch($this->_generic->getPathConfig("modelsSql")."/".$fileNameS); if ($status2) file_put_contents($this->_generic->getPathConfig("modelsSql")."/".$fileNameS,$contentS); } else array_push($errors,$currentTable); } } // If no errors if (empty($errors)) { $controllers = $this->_generic->getTranslatedController("SLS_Bo","Models"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']); } else { // Get all models $models = array(); $handle = opendir($this->_generic->getPathConfig("models")); while (false !== ($file = readdir($handle))) if (!is_dir($this->_generic->getPathConfig("models")."/".$file) && substr($file, 0, 1) != ".") { $modelExploded = explode(".",$file); array_push($models,strtolower($modelExploded[0]).".".$modelExploded[1]); } // Form errors $xml->startTag("errors"); for($i=0 ; $i<$count=count($errors) ; $i++) { $xml->startTag("error"); $xml->addFullTag("table",SLS_String::substrAfterFirstDelimiter($errors[$i]["table"],"."),true); $xml->addFullTag("db",SLS_String::substrBeforeFirstDelimiter($errors[$i]["table"],"."),true); $xml->startTag("columns"); for($j=0 ; $j<$count2=count($errors[$i]["errors"]) ; $j++) { $xml->startTag("column"); $xml->addFullTag("old",$errors[$i]["errors"][$j]["column"],true); $xml->addFullTag("new",$errors[$i]["errors"][$j]["column_clean"],true); $xml->endTag("column"); } $xml->endTag("columns"); $xml->endTag("error"); } $xml->endTag("errors"); } } // Foreach db $dbs = $sql->getDbs(); $allDbs = array(); foreach($dbs as $db) { $allDbs[$db] = array(); // Change db $sql->changeDb($db); // Get all tables $tables = $sql->showTables(); for($i=0 ; $i<$count=count($tables) ; $i++) { $allDbs[$db][$tables[$i]->Name] = array("name" => $tables[$i]->Name, "existed" => (in_array($db.".".SLS_String::tableToClass($tables[$i]->Name),$models)) ? 'true' : 'false'); } } asort($allDbs,SORT_REGULAR); uksort($allDbs,array($this, 'unshiftDefaultDb')); $xml->startTag("dbs"); foreach($allDbs as $key => $db) { asort($db,SORT_REGULAR); $xml->startTag("db"); $xml->addFullTag("name",$key,true); $xml->startTag("tables"); foreach($db as $tableCur) { if (!SLS_String::startsWith(strtolower($tableCur["name"]),"sls_graph")) { $xml->startTag("table"); $xml->addFullTag("name",$tableCur["name"]); $xml->addFullTag("existed",$tableCur["existed"]); $xml->endTag("table"); } } $xml->endTag("tables"); $xml->endTag("db"); } $xml->endTag("dbs"); $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $columnWanted = $this->_http->getParam("column"); $filterWanted = $this->_http->getParam("filter"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $result = $xmlFilter->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."' and @filter='".$filterWanted."']"); // If an entry already exists in the XML, delete this record if (!empty($result)) { $xmlTmp = $xmlFilter->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."' and @filter='".$filterWanted."']"); $xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlTmp); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); } if ($filterWanted == "hash") { $passwordHash = $this->_http->getParam("hash"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" hash="'.$passwordHash.'" filter="'.$filterWanted.'" />'; $xmlFilter->appendXMLNode("//sls_configs",$xmlNode); $xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlFilter->getXML()); } else { // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" filter="'.$filterWanted.'" />'; $xmlFilter->appendXMLNode("//sls_configs",$xmlNode); $xmlFilter->saveXML($this->_generic->getPathConfig("configSls")."/filters.xml",$xmlFilter->getXML()); } // Update model $this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); } // Get generic object $this->_generic->useModel($table,$db,"user"); $object = new $class(); // Get object's infos $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->startTag("columns"); foreach($columnsP as $column => $value) { $res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk"); if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res)) $xml->addFullTag("column",$column,true); } $xml->endTag("columns"); $xml->endTag("model"); } else { $xml->addFullTag("error","Sorry this table doesn't exist anymore",true); } $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $column= $this->_http->getParam("column"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $columnWanted = $this->_http->getParam("column"); $typeWanted = $this->_http->getParam("type"); $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); // If an entry already exists in the XML, delete this record if (!empty($result)) { $xmlTmp = $xmlType->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlTmp); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); } // If file type, check possible thumbs if ($typeWanted == "file") { $typeFile = $this->_http->getParam("file"); $file_thumb = $this->_http->getParam("file_thumb"); $multilang = $this->_http->getParam("multilanguage"); $thumbs = array(); $typeWanted = $typeWanted."_".$typeFile; if ($typeFile == "img" && !empty($file_thumb)) { for($i=0 ; $i<10 ; $i++) { $width = $this->_http->getParam("width".$i); $height = $this->_http->getParam("height".$i); $suffix = $this->_http->getParam("suffix".$i); if (!empty($suffix) && (!empty($width) || !empty($height))) array_push($thumbs,array('width' => $width, 'height' => $height, 'suffix' => $suffix)); } } $rules = "*|*|*"; if ($typeFile == "img") { $settings = $this->_http->getParam("imgSettings"); $ratio = str_replace(",",".",$settings["ratio"]); $minWidth = str_replace(",",".",$settings["min-width"]); $minHeight = str_replace(",",".",$settings["min-height"]); $ratio = (!is_numeric($ratio) || (is_numeric($ratio) && $ratio <= 0)) ? "*" : round($ratio,2); $minWidth = (!is_numeric($minWidth) || (is_numeric($minWidth) && $minWidth < 0)) ? "*" : round($minWidth,0); $minHeight = (!is_numeric($minHeight) || (is_numeric($minHeight) && $minHeight < 0)) ? "*" : round($minHeight,0); $rules = $ratio."|".$minWidth."|".$minHeight; } // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$rules.'" thumbs="'.str_replace('"','||#||',serialize($thumbs)).'" multilanguage="'.$multilang.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "ip") { $type = $this->_http->getParam("ip"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "complexity") { $complexity = $this->_http->getParam("complexity"); $complexityMin = $this->_http->getParam("complexity_min"); $complexity = (empty($complexity)) ? array() : $complexity; if (!empty($complexityMin) && is_numeric($complexityMin) && $complexityMin >= 0) $complexity[] = "min".$complexityMin; $complexity = implode("|",$complexity); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$complexity.'" type="complexity" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "num") { $type = $this->_http->getParam("num"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Else, it's email, url else { // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Update Model $fileName = ucfirst($db).".".SLS_String::tableToClass($table).".model.php"; $contentM = $this->getModelSource($table,$db); file_put_contents($this->_generic->getPathConfig("models").$fileName,$contentM); $controllers = $this->_generic->getTranslatedController("SLS_Bo","EditModel"); $this->_generic->redirect($controllers['controller']."/".$controllers['scontroller']."/name/".$db."_".$table); } // Get generic object $this->_generic->useModel($table,$db,"user"); $object = new $class(); // Get current entry $attributes = array_shift($xmlType->getTagsAttributes("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$column."']",array("type","thumbs","multilanguage","hash","rules"))); // Get object's infos $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->addFullTag("column",$column,true); $xml->addFullTag("type",$attributes["attributes"][0]["value"],true); $xml->startTag("thumbs"); $thumbs = unserialize(str_replace("||#||",'"',$attributes["attributes"][1]["value"])); if (!empty($thumbs)) { for($i=0 ; $i<$count=count($thumbs) ; $i++) { $xml->startTag("thumb"); $xml->addFullTag("width",$thumbs[$i]["width"],true); $xml->addFullTag("height",$thumbs[$i]["height"],true); $xml->addFullTag("suffix",$thumbs[$i]["suffix"],true); $xml->endTag("thumb"); } } $xml->endTag("thumbs"); $xml->addFullTag("multilanguage",($attributes["attributes"][2]["value"] == "true") ? "true" : "false",true); $xml->addFullTag("hash",$attributes["attributes"][3]["value"],true); $xml->addFullTag("rules",$attributes["attributes"][4]["value"],true); $xml->endTag("model"); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginImg = array_shift($plugin->getTags("//plugins/plugin[@code='image']")); $xml->addFullTag("plugin_img",empty($pluginImg) ? 'false' : 'true',true); $xml->addFullTag("plugin_url",$this->_generic->getFullPath("SLS_Bo","Plugins"),true); } else { $xml->addFullTag("error","Sorry this table doesn't exist anymore",true); } $this->saveXML($xml); }
public function action() { $user = $this->hasAuthorative(); $sql = SLS_Sql::getInstance(); $xml = $this->getXML(); $xml = $this->makeMenu($xml); $errors = array(); // Get the table name $table = SLS_String::substrAfterFirstDelimiter($this->_http->getParam("name"),"_"); $db = SLS_String::substrBeforeFirstDelimiter($this->_http->getParam("name"),"_"); $class = ucfirst($db)."_".SLS_String::tableToClass($table); $file = ucfirst($db).".".SLS_String::tableToClass($table); // If current db is not this one if ($sql->getCurrentDb() != $db) $sql->changeDb($db); if ($sql->tableExists($table)) { if ($this->_http->getParam("reload") == "true") { $columnWanted = $this->_http->getParam("column"); $typeWanted = $this->_http->getParam("type"); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"); $xmlFilter = new SLS_XMLToolbox($pathsHandle); $result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); // If an entry already exists in the XML, delete this record if (!empty($result)) { $xmlTmp = $xmlType->deleteTags("//sls_configs/entry[@table='".$db."_".$table."' and @column='".$columnWanted."']"); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlTmp); $xmlType->refresh(); $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"); $xmlType = new SLS_XMLToolbox($pathsHandle); } // If file type, check possible thumbs if ($typeWanted == "file") { $typeFile = $this->_http->getParam("file"); $file_thumb = $this->_http->getParam("file_thumb"); $multilang = $this->_http->getParam("multilanguage"); $thumbs = array(); $typeWanted = $typeWanted."_".$typeFile; if ($typeFile == "img" && !empty($file_thumb)) { for($i=0 ; $i<10 ; $i++) { $width = $this->_http->getParam("width".$i); $height = $this->_http->getParam("height".$i); $suffix = $this->_http->getParam("suffix".$i); if (!empty($suffix) && (!empty($width) || !empty($height))) array_push($thumbs,array('width' => $width, 'height' => $height, 'suffix' => $suffix)); } } $rules = "*|*|*"; if ($typeFile == "img") { $settings = $this->_http->getParam("imgSettings"); $ratio = str_replace(",",".",$settings["ratio"]); $minWidth = str_replace(",",".",$settings["min-width"]); $minHeight = str_replace(",",".",$settings["min-height"]); $ratio = (!is_numeric($ratio) || (is_numeric($ratio) && $ratio <= 0)) ? "*" : round($ratio,2); $minWidth = (!is_numeric($minWidth) || (is_numeric($minWidth) && $minWidth < 0)) ? "*" : round($minWidth,0); $minHeight = (!is_numeric($minHeight) || (is_numeric($minHeight) && $minHeight < 0)) ? "*" : round($minHeight,0); $rules = $ratio."|".$minWidth."|".$minHeight; } // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$rules.'" thumbs="'.str_replace('"','||#||',serialize($thumbs)).'" multilanguage="'.$multilang.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "ip") { $type = $this->_http->getParam("ip"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "complexity") { $complexity = $this->_http->getParam("complexity"); $complexityMin = $this->_http->getParam("complexity_min"); $complexity = (empty($complexity)) ? array() : $complexity; if (!empty($complexityMin) && is_numeric($complexityMin) && $complexityMin >= 0) $complexity[] = "min".$complexityMin; $complexity = implode("|",$complexity); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" rules="'.$complexity.'" type="complexity" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } else if ($typeWanted == "num") { $type = $this->_http->getParam("num"); // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted."_".$type.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Else, it's email, url, color, uniqid, position, address else { // Save it into the XML $xmlNode = '<entry table="'.$db.'_'.$table.'" column="'.$columnWanted.'" type="'.$typeWanted.'" />'; $xmlType->appendXMLNode("//sls_configs",$xmlNode); $xmlType->saveXML($this->_generic->getPathConfig("configSls")."/types.xml",$xmlType->getXML()); } // Disable UserBo quick-edit feature on this column if ($typeWanted == "file") { $xmlBo = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/bo.xml")); $boPath = "//sls_configs/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (empty($boExists)) $boPath = "//sls_configs/entry/entry[@type='table' and @name='".strtolower($db."_".$table)."']/columns/column[@name='".$columnWanted."']"; $boExists = $xmlBo->getTag($boPath."/@allowEdit"); if (!empty($boExists)) { $xmlBo->setTagAttributes($boPath,array("allowEdit" => "false")); $xmlBo->saveXML($this->_generic->getPathConfig("configSls")."/bo.xml",$xmlBo->getXML()); $xmlBo->refresh(); } } // Update model $this->_generic->goDirectTo("SLS_Bo","UpdateModel",array(array("key"=>"name","value"=>$this->_http->getParam("name")))); } // Get generic object $this->_generic->useModel($table,$db,"user"); $object = new $class(); // Get object's infos $pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"); $xmlFk = new SLS_XMLToolbox($pathsHandle); $columnsP = $object->getParams(); $pk = $object->getPrimaryKey(); $multilanguage = $object->isMultilanguage(); $xml->startTag("model"); $xml->addFullTag("table",$table,true); $xml->addFullTag("db",$db,true); $xml->addFullTag("class",$class,true); $xml->addFullTag("pk",$pk,true); $xml->addFullTag("multilanguage",($multilanguage) ? "true" : "false",true); $xml->startTag("columns"); foreach($columnsP as $column => $value) { $res = $xmlFk->getTags("//sls_configs/entry[@tableFk='".$db."_".$table."' and @columnFk='".$column."']/@tablePk"); if ($object->getPrimaryKey() != $column && $column != "pk_lang" && empty($res)) $xml->addFullTag("column",$column,true); } $xml->endTag("columns"); $xml->endTag("model"); $plugin = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configPlugins")."/plugins.xml")); $pluginImg = array_shift($plugin->getTags("//plugins/plugin[@code='image']")); $xml->addFullTag("plugin_img",empty($pluginImg) ? 'false' : 'true',true); $xml->addFullTag("plugin_url",$this->_generic->getFullPath("SLS_Bo","Plugins"),true); } else { $xml->addFullTag("error","Sorry this table doesn't exist anymore",true); } $this->saveXML($xml); }