diff options
-rw-r--r-- | config.php | 2 | ||||
-rw-r--r-- | index.php | 4 | ||||
-rw-r--r-- | lang/de/administration/_page.json | 1 | ||||
-rw-r--r-- | lang/de/administration/template.json | 1 | ||||
-rw-r--r-- | lang/de/messages.json | 3 | ||||
-rw-r--r-- | lang/en/administration/_page.json | 1 | ||||
-rw-r--r-- | lang/en/administration/template.json | 1 | ||||
-rw-r--r-- | lang/en/messages.json | 3 | ||||
-rw-r--r-- | lang/i18n.php | 11 | ||||
-rw-r--r-- | lang/pt/administration/_page.json | 1 | ||||
-rw-r--r-- | lang/pt/administration/template.json | 1 | ||||
-rw-r--r-- | lang/pt/messages.json | 3 | ||||
-rw-r--r-- | lang/pt/sysconfig/_page.json | 1 | ||||
-rw-r--r-- | modules/admin.inc.php | 160 | ||||
-rw-r--r-- | templates/administration/_page.html | 34 | ||||
-rw-r--r-- | templates/administration/template.html | 37 | ||||
-rw-r--r-- | templates/main-menu-login.html | 1 | ||||
-rw-r--r-- | templates/main-menu-logout.html | 1 |
18 files changed, 257 insertions, 9 deletions
@@ -14,7 +14,7 @@ define('CONFIG_SQL_PASS', 'geheim'); define('CONFIG_SQL_FORCE_UTF8', false); //define('CONFIG_SQL_DB', 'openslx'); -define('LANG', $language); +define ("SITE_LANGUAGES", serialize (array ("de", "en", "pt"))); define('CONFIG_TGZ_LIST_DIR', '/opt/openslx/configs'); @@ -1,9 +1,9 @@ <?php -require_once 'lang/i18n.php'; - require_once 'config.php'; +require_once 'lang/i18n.php'; + Dictionary::build(); require_once('inc/user.inc.php'); diff --git a/lang/de/administration/_page.json b/lang/de/administration/_page.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/de/administration/_page.json @@ -0,0 +1 @@ +{} diff --git a/lang/de/administration/template.json b/lang/de/administration/template.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/de/administration/template.json @@ -0,0 +1 @@ +{} diff --git a/lang/de/messages.json b/lang/de/messages.json index 2947db55..64ffcb58 100644 --- a/lang/de/messages.json +++ b/lang/de/messages.json @@ -35,5 +35,6 @@ "news-save-success": "News erfolgreich aktualisiert", "news-empty": "Es wurde keine News in der Datenbank gefunden", "news-del-success": "News gelöscht", - "reboot-unconfirmed": "Sicherheitsabfrage zum Reboot nicht bestätigt" + "reboot-unconfirmed": "Sicherheitsabfrage zum Reboot nicht bestätigt", + "invalid-template":"Ausgewählte Template ist nicht gültig" } diff --git a/lang/en/administration/_page.json b/lang/en/administration/_page.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/en/administration/_page.json @@ -0,0 +1 @@ +{} diff --git a/lang/en/administration/template.json b/lang/en/administration/template.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/en/administration/template.json @@ -0,0 +1 @@ +{} diff --git a/lang/en/messages.json b/lang/en/messages.json index 4e70c3a2..60e6baba 100644 --- a/lang/en/messages.json +++ b/lang/en/messages.json @@ -35,5 +35,6 @@ "news-save-success": "News updated successfully", "news-empty": "There was no news found in the database", "news-del-success": "News deleted", - "reboot-unconfirmed": "Confirmation prompt to reboot not confirmed" + "reboot-unconfirmed": "Confirmation prompt to reboot not confirmed", + "invalid-template":"Selected template is not valid" } diff --git a/lang/i18n.php b/lang/i18n.php index 82da12a1..1f7731f2 100644 --- a/lang/i18n.php +++ b/lang/i18n.php @@ -7,9 +7,11 @@ class Dictionary{ self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"),true); } - public static function getArrayTemplate($template){ + public static function getArrayTemplate($template,$lang = false){ $language = array('lang'=>LANG); - return array_merge($language,json_decode(file_get_contents("lang/" . LANG . "/" . $template . ".json"),true)); + if(!$lang) + return array_merge($language,json_decode(file_get_contents("lang/" . LANG . "/" . $template . ".json"),true)); + return array_merge($language,json_decode(file_get_contents("lang/" . $lang . "/" . $template . ".json"),true)); } public static function translate($string){ @@ -23,7 +25,8 @@ class Dictionary{ } //Array containing the allowed languages for the website - $langArray = array("de","en","pt"); + $langArray = unserialize(SITE_LANGUAGES); + //Changes the language in case there is a request to if(isset($_GET['lang'])) @@ -44,4 +47,6 @@ class Dictionary{ }else if(in_array($langBrowser,$langArray)){ $language = $langBrowser; } + + define('LANG', $language); ?> diff --git a/lang/pt/administration/_page.json b/lang/pt/administration/_page.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/pt/administration/_page.json @@ -0,0 +1 @@ +{} diff --git a/lang/pt/administration/template.json b/lang/pt/administration/template.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/lang/pt/administration/template.json @@ -0,0 +1 @@ +{} diff --git a/lang/pt/messages.json b/lang/pt/messages.json index 345a5398..3eee3f9c 100644 --- a/lang/pt/messages.json +++ b/lang/pt/messages.json @@ -35,5 +35,6 @@ "news-save-success": "Notícia atualizada com sucesso", "news-empty": "Não havia notícias no banco de dados", "news-del-success": "Notícia excluída", - "reboot-unconfirmed": "Confirmação para reinicializar não foi confirmada" + "reboot-unconfirmed": "Confirmação para reinicializar não foi confirmada", + "invalid-template":"Template selecionado não é válido" } diff --git a/lang/pt/sysconfig/_page.json b/lang/pt/sysconfig/_page.json index e40a277d..f1e862bc 100644 --- a/lang/pt/sysconfig/_page.json +++ b/lang/pt/sysconfig/_page.json @@ -12,5 +12,6 @@ "lang_newModule":"Novo Módulo", "lang_systemConfiguration":"Confguração do Sistema", "lang_helpSystemConfiguration":"A localização fundamental do sistema bwLehrpool é feita através de uma configuração de sistema. Isso inclui aspectos como o método de autenticação de usuários (por exemplo, Diretório Ativo, LDAP), configuração de impressora, diretórios home, etc. Uma configuração de sistema é composta por um ou mais módulo de configuração, que podem ser gerenciados na parte inferior da página.", + "lang_moduleConfiguration":"Configuração do Módulo", "lang_helpModuleConfiguration":"Módulos de configuração são as peças fundamentais para a criação de uma configuração de sistema. Aqui você pode criar tanto módulos genéricos através de nossa interface, tanto quanto criar módulos completamente customizados (é necessário conhecimento de Linux avançado)." } diff --git a/modules/admin.inc.php b/modules/admin.inc.php new file mode 100644 index 00000000..b74b5ef5 --- /dev/null +++ b/modules/admin.inc.php @@ -0,0 +1,160 @@ +<?php + +class Page_Admin extends Page +{ + + private $template = false; + private $files = false; + private $table = false; + private $tags = false; + + /** + * Implementation of the abstract doPreprocess function + * + * Checks if the user is logged in and processes any + * action if one was specified in the request. + * + */ + protected function doPreprocess() + { + // load user, we will need it later + User::load(); + + // only admins should be able to access the administration page + if (!User::hasPermission('superadmin')) { + Message::addError('no-permission'); + Util::redirect('?do=Main'); + } + + if(Request::any('template')){ + $this->template = Request::any('template'); + } + + } + + /** + * Implementation of the abstract doRender function + * + * Fetch the list of news from the database and paginate it. + * + */ + protected function doRender() + { + if(!$this->template || !$this->templateAnalysis($this->template)){ + $this->initTable(); + Render::addTemplate('administration/_page', array( + 'token' => Session::get('token'), + 'adminMessage' => $this->message, + 'table' => $this->table + )); + }else{ + Render::addTemplate('administration/template', array( + 'template' => $this->template, + 'tags' => $this->tags + )); + } + + + } + + private function initTable(){ + $this->listTemplates(); + $de = $this->listJson('de/'); + $en = $this->listJson('en/'); + $pt = $this->listJson('pt/'); + + foreach($this->files as $key => $value){ + + $this->table[] = array( + 'template' => $value, + 'link' => $key, + 'de' => $this->checkJson($de[$key],'de'), + 'en' => $this->checkJson($en[$key],'en'), + 'pt' => $this->checkJson($pt[$key],'pt') + ); + } + + } + + private function listTemplates(){ + $this->files = array(); + $dir = 'templates/'; + $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); + foreach($objects as $name => $object){ + if(array_pop(explode('.',$name)) === 'html'){ + $key = str_replace($dir, '', $name); + $key = str_replace('.html', '', $key); + $this->files[$key] = $name; + } + } + } + + private function listJson($lang){ + $json = array(); + $dir = 'lang/' . $lang; + $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); + foreach($objects as $name => $object){ + if(array_pop(explode('.',$name)) === 'json'){ + $key = str_replace($dir, '', $name); + $key = str_replace('.json', '', $key); + $json[$key] = $key; + } + } + return $json; + } + + private function checkJson($path,$lang){ + if($path){ + $htmlTemplate = file_get_contents('templates/' . $path . '.html'); + $json = Dictionary::getArrayTemplate($path,$lang); + $htmlCount = substr_count($htmlTemplate, 'lang_'); + $matchCount = 0; + + foreach($json as $key => $value){ + if($key != 'lang'){ + $key = $key . '}}'; + $matchCount += substr_count($htmlTemplate, $key); + } + } + + $diff = $htmlCount - $matchCount; + + //allright + if($diff == 0) return "OK"; + if($diff > 0) return $diff . " JSON tag(s) are missing"; + if($diff < 0) return ($diff * -1) . " extra JSON tag(s)"; + }else{ + return "JSON file is missing"; + } + + } + + private function templateAnalysis($path){ + if(!file_exists('templates/' . $path . '.html')){ + Message::addError('invalid-template'); + return false; + } + $htmlTemplate = file_get_contents('templates/' . $path . '.html'); + preg_match_all('/{{lang_(.*?)}}/s', $htmlTemplate, $matches); + + $tags = $matches[1]; + + foreach($tags as $tag){ + $this->tags[] = array( + 'tag' => 'lang_' . $tag, + 'de' => $this->checkJsonTag($path,$tag,'de/'), + 'en' => $this->checkJsonTag($path,$tag,'en/'), + 'pt' => $this->checkJsonTag($path,$tag,'pt/') + ); + } + + return true; + } + + private function checkJsonTag($path,$tag,$lang){ + if($json = Dictionary::getArrayTemplate($path,$lang)){ + return $json['lang_' . $tag]; + } + return ''; + } +} diff --git a/templates/administration/_page.html b/templates/administration/_page.html new file mode 100644 index 00000000..b6d11cd6 --- /dev/null +++ b/templates/administration/_page.html @@ -0,0 +1,34 @@ +<div class="container"> + <div class="panel panel-default"> + <div class="panel-heading"> + Language Administration + </div> + <div class="panel-body"> + <table class="table table-hover"> + <thead> + <tr> + <th>Template</th> + <th style='text-align:center;'>{{lang_german}}</th> + <th style='text-align:center;'>{{lang_english}}</th> + <th style='text-align:center;'>Português</th> + <tr> + </thead> + <tbody> + {{#table}} + <tr onclick="goTo('{{link}}');"> + <td>{{template}}</td> + <td style='width:200px;text-align:center;'>{{de}}</td> + <td style='width:200px;text-align:center;'>{{en}}</td> + <td style='width:200px;text-align:center;'>{{pt}}</td> + </tr> + {{/table}} + </tbody> + </table> + </div> + </div> +</div> +<script> +function goTo(link){ + window.location.href = "?do=Admin&template=" + link; +} +</script> diff --git a/templates/administration/template.html b/templates/administration/template.html new file mode 100644 index 00000000..02317472 --- /dev/null +++ b/templates/administration/template.html @@ -0,0 +1,37 @@ +<div class="container"> + <div class="panel panel-default"> + <div class="panel-heading"> + {{template}} + </div> + <div class="panel-body"> + <table class="table table-hover"> + <thead> + <tr> + <th>Mustache Tag</th> + <th style='text-align:center;'>German JSON</th> + <th style='text-align:center;'>English JSON</th> + <th style='text-align:center;'>Portuguese JSON</th> + </tr> + </thead> + <tbody> + {{#tags}} + <tr> + <td>{{tag}}</td> + <td style='width:250px;text-align:center;'> + <input type="text" class="form-control" placeholder="German TAG" value="{{de}}"> + </td> + <td style='width:250px;text-align:center;'> + <input type="text" class="form-control" placeholder="English TAG" value="{{en}}"> + </td> + <td style='width:250px;text-align:center;'> + <input type="text" class="form-control" placeholder="Portuguese TAG" value="{{pt}}"> + </td> + </tr> + {{/tags}} + </tbody> + </table> + <a class="btn btn-primary" href='?do=Admin' >Back</a> + <a class="btn btn-primary" href='#' >Update</a> + </div> + </div> +</div> diff --git a/templates/main-menu-login.html b/templates/main-menu-login.html index e9459e90..2b165fb5 100644 --- a/templates/main-menu-login.html +++ b/templates/main-menu-login.html @@ -19,6 +19,7 @@ <li><a href="?do=SysConfig">{{lang_localization}}</a></li> <li><a href="?do=MiniLinux">bwLehrpool Mini-Linux</a></li> <li><a href="?do=BaseConfig">{{lang_configurationVariables}}</a></li> + <li><a href="?do=Admin">Admin</a></li> <li class="divider"></li> <li class="dropdown-header">{{lang_server}}</li> <li><a href="?do=ServerSetup">{{lang_configurationBasic}}</a></li> diff --git a/templates/main-menu-logout.html b/templates/main-menu-logout.html index eab8bfa1..abe2c516 100644 --- a/templates/main-menu-logout.html +++ b/templates/main-menu-logout.html @@ -19,6 +19,7 @@ <li><a href="?do=SysConfig">{{lang_localization}}</a></li> <li><a href="?do=MiniLinux">bwLehrpool Mini-Linux</a></li> <li><a href="?do=BaseConfig">{{lang_configurationVariables}}</a></li> + <li><a href="?do=Admin">Admin</a></li> <li class="divider"></li> <li class="dropdown-header">{{lang_server}}</li> <li><a href="?do=ServerSetup">{{lang_configurationBasic}}</a></li> |