Fixes in settings admin

This commit is contained in:
Antonio de la Rosa 2025-11-28 01:28:32 +01:00
parent 2df08a0e7d
commit e3775e1045
6 changed files with 597 additions and 14 deletions

View file

@ -24,6 +24,8 @@ class AppController extends TplController{
//Default admin page.
echo $this->tpl->load_template('layout', ['title' => 'Admin', 'path_module' => 'admin.home']);
}
else {
@ -319,6 +321,42 @@ class AppController extends TplController{
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin'));
break;
case 'change_theme':
if($this->check_login()) {
settype($_GET['theme'], 'integer');
if($_GET['theme']>1 || $_GET['theme']<0) {
$_GET['theme']=0;
}
$error=0;
$message='';
$this->db->connect();
if(!$this->db->update('useradmin', ['theme' => $_GET['theme']], 'WHERE id=?', [$_SESSION['admin_login']])) {
$error=1;
}
else {
$_SESSION['theme']=$_GET['theme'];
}
}
echo $this->json(['error' => $error, 'message' => $message]);
break;
}

View file

@ -0,0 +1,9 @@
<?php
namespace Admin\Settings;
class Config {
static public $config_admin=[];
}

View file

@ -12,7 +12,7 @@ class TplController extends PhangoApp\PhaRouter\Controller {
session_start();
$useradmin=new WPDO\WTable('useradmin', ['id', 'username', 'password', 'email', 'double_auth', 'auth_token']);
$useradmin=new WPDO\WTable('useradmin', ['id', 'username', 'password', 'email', 'double_auth', 'auth_token', 'theme']);
$login_tries=new WPDO\WTable('login_tries', ['ip', 'num_tries', 'date']);
@ -28,11 +28,6 @@ class TplController extends PhangoApp\PhaRouter\Controller {
if(isset($_SESSION['double_auth']) && $this->path_info!='/admin/app/check_auth') {
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['check_auth']));
die;
} else {
$now=date("Y-m-d H:i:s");
$timestamp_5_min=strtotime($now)-300;
@ -43,8 +38,16 @@ class TplController extends PhangoApp\PhaRouter\Controller {
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['logout']));
}
else {
}
header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['check_auth']));
}
die;
}
return true;

View file

@ -1,28 +1,54 @@
/** {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}*/
body
{
margin:0px;
background-color:#f4f6f9;
font-family: "Roboto", sans, sans-serif, serif;
font-family: sans, sans-serif, serif;
font-size: 16px;
/*-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
-webkit-transition-property: background-color, color;
transition-property: background-color, color;*/
}
a
{
body.dark {
background-color: #232834;
color: #fbfbfb;
/*-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
-webkit-transition-property: background-color, color;
transition-property: background-color, color;*/
}
a {
color: #1c6280;
}
a:hover
{
a:hover {
color: #d54e21;
}
.dark a {
color: #5fa6c4;
}
#header
{
@ -39,6 +65,14 @@ a:hover
}
.dark #header {
background-color:#1e1412;
}
#title_phango
{
font-size:28px;
@ -99,6 +133,20 @@ h1 {
}
.dark h1 {
background-color:#000a22;
color: #fbfbfb;
border-color: #000;
}
.dark h2 {
color: #fbfbfb;
}
p {
border: solid #cbcbcb;
@ -142,6 +190,16 @@ p {
box-sizing: border-box;
/* padding-bottom: 100px;*/
overflow:hidden;
height:100%;
-webkit-box-shadow: 1px 1px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 1px 1px 5px 0px rgba(0,0,0,0.75);
box-shadow: 1px 1px 5px 0px rgba(0,0,0,0.75);
}
.dark #menu {
}
#menu a
@ -257,8 +315,23 @@ p {
border: solid #cbcbcb;
border-width: 0px 0px 1px 0px;
min-height: 90vh;
/*-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;*/
}
.dark .content_admin {
background-color: #1e202a;
/*-webkit-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;*/
border: solid #323232;
border-width: 0px 0px 1px 0px;
}
.content_admin i {
margin-right: 10px;
@ -271,8 +344,10 @@ p {
width:82%;
padding:0px 0px 0px 0px;
box-sizing: border-box;
}
.content
{
padding:0px 10px 5px 10px;
@ -320,6 +395,13 @@ p {
}
.dark .form {
background-color: #1e202a;
border-color: #323232;
}
.form textarea {
width:100%;
@ -327,6 +409,13 @@ p {
}
.dark .form textarea {
background-color: #1e202a;
color: #fbfbfb;
}
.form label {
display: block;
/*width: 150px;*/
@ -408,6 +497,12 @@ table {
}
.dark .table_list {
border: solid #323232 1px;
}
.title_list td, .fields_span_title {
margin:0px;
@ -423,6 +518,13 @@ table {
}
.dark .title_list td {
background-color:#000a22;
}
.fields_span_title, div.options_td , div.fields_span_table_data {
box-sizing: border-box;
@ -449,6 +551,13 @@ table {
}
.dark .row_list td {
background-color: #2d313b;
color: #fbfbfb;
}
div.fields_span_table_data {
box-sizing: border-box;
@ -472,6 +581,13 @@ div.fields_span_table_data {
}
.dark .cont_text, .dark .cont {
background-color: #2d313b;
border-color: #343434;
}
.cont_top {
border-width: 1px 1px 1px 1px;
@ -518,6 +634,12 @@ div.fields_span_table_data {
}
.dark .error {
color: #ff3232;
}
.hidden_form
{
@ -577,9 +699,11 @@ a:hover.no_choose_flag
#center_body input {
border: solid #bcbcbc;
border-width:1px;
border-width:2px;
border-radius:5px;
background: #eeeeee;
padding: 2px 4px;
font-size:16px;
}
@ -589,6 +713,13 @@ a:hover.no_choose_flag
}
.dark #center_body input {
background-color: #2d313b;
color: #fbfbfb;
}
#center_body input[type="submit"], #center_body input[type="button"], #center_body input[type="button"].button_blue
{
@ -611,6 +742,12 @@ a:hover.no_choose_flag
}
.dark #center_body input[type="button"] {
background: #d08b2c;
}
#center_body input:hover[type="submit"], #center_body input[type="button"].button_blue
{
@ -627,6 +764,15 @@ a:hover.no_choose_flag
}
#center_body input:hover[type="button"].button_blue
{
background: #215181;
cursor: pointer;
}
#center_body input[type="text"], #center_body input[type="password"]
{
@ -647,6 +793,16 @@ a:hover.no_choose_flag
border: solid #bcbcbc;
border-width:1px;
border-radius:5px;
padding: 2px 5px;
border: solid #cbcbcb 2px;
font-size: 16px;
}
.dark #center_body select {
background-color: #2d313b;
color: #fbfbfb;
}
@ -846,7 +1002,7 @@ a.form_button_tab:hover
#layer_loading {
z-index:50000;
z-index:99999;
/*background-color:rgba(0,0,0,0.4);*/
/*opacity:0.5;*/
position:absolute;
@ -880,6 +1036,7 @@ a.form_button_tab:hover
box-sizing: border-box;
/* border: solid #fff 1px;*/
float:left;
overflow:hidden;
}
@ -889,6 +1046,7 @@ a.form_button_tab:hover
box-sizing: border-box;
/* border: solid #fff 1px;*/
float:left;
overflow:hidden;
}
@ -899,6 +1057,7 @@ a.form_button_tab:hover
box-sizing: border-box;
/*border: solid #f00 1px;*/
float:left;
overflow:hidden;
}
@ -908,6 +1067,7 @@ a.form_button_tab:hover
box-sizing: border-box;
/*border: solid #f00 1px;*/
float:left;
overflow:hidden;
}
@ -969,6 +1129,14 @@ h2.title_container {
}
.dark h2.title_container {
background-color: #2d313b;
border-color: #343434;
color: #fbfbfb;
}
.container_warning h2.title_container {
background:#dc3545;
@ -1001,6 +1169,144 @@ h2.title_container {
}
.dark .container_content {
background-color: #2d313b;
border-color: #343434;
color: #fbfbfb;
}
/* Switch for dark mode */
/* switches css */
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 40px;
height: 16px;
}
/* Hide default HTML checkbox */
.switch input {display:none;}
/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
height: 16px;
width:38px;
box-sizing: border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing: border-box;
}
/* before is the checkbox */
.slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: -1px;
top: -3px;
background-color: #fbfbfb;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #447211;
}
input:focus + .slider {
box-shadow: 0 0 1px #447211;
}
input:checked + .slider:before {
-webkit-transform: translateX(21px);
-ms-transform: translateX(21px);
transform: translateX(21px);
background-color: #7ed321;
}
input:checked + .slider_grey {
background-color: #ccc;
}
input:focus + .slider_grey {
box-shadow: 0 0 1px #ccc;
}
input:checked + .slider_grey:before {
-webkit-transform: translateX(21px);
-ms-transform: translateX(21px);
transform: translateX(21px);
background-color: #fbfbfb;
}
/* Rounded sliders */
.slider.round {
border-radius: 34px;
}
.slider.round:before {
border-radius: 50%;
}
.container_switch {
margin-top:6px;
display:inline-block;
float:right;
}
.switch-btn {
position:absolute;
/*border: solid #f00 1px;*/
right:4px;
top:8px;
z-index:9999;
}
.switch-slider {
text-align:center;
display: inline-block;
}
.switch-text {
display: inline-block;
font-size: 12px;
position:relative;
top: -4px;
left:-2px;
color: #000;
}
.dark .switch-text {
color: #fbfbfb;
}
/* Media queries */

View file

@ -0,0 +1,9 @@
<?php
use Admin\Settings\Config;
Config::$config_admin[]=[_('Users Admin')];
Config::$config_admin[]=[_('Edit users'), $this->make_url('admin', 'users'), 'admin.users', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="24" style="fill: currentColor;display: inline-block;vertical-align: -.130em;position:relative;left:-6px;top:2px;"><!--!Font Awesome Free v7.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 312C386.3 312 440 258.3 440 192C440 125.7 386.3 72 320 72C253.7 72 200 125.7 200 192C200 258.3 253.7 312 320 312zM290.3 368C191.8 368 112 447.8 112 546.3C112 562.7 125.3 576 141.7 576L498.3 576C514.7 576 528 562.7 528 546.3C528 447.8 448.2 368 349.7 368L290.3 368z"/></svg>'];
//config_admin.append([users_edit, 'paramecio2.modules.admin.admin.ausers', 'admin_app.ausers', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="24" style="fill: currentColor;display: inline-block;vertical-align: -.130em;position:relative;left:-6px;top:2px;"><!--!Font Awesome Free v7.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M320 312C386.3 312 440 258.3 440 192C440 125.7 386.3 72 320 72C253.7 72 200 125.7 200 192C200 258.3 253.7 312 320 312zM290.3 368C191.8 368 112 447.8 112 546.3C112 562.7 125.3 576 141.7 576L498.3 576C514.7 576 528 562.7 528 546.3C528 447.8 448.2 368 349.7 368L290.3 368z"/></svg>'])

View file

@ -0,0 +1,218 @@
<?php
//use
$theme=$_SESSION['theme'] ?? 0;
$dark_checked='';
$dark_css='';
if($theme=='1') {
$dark_checked='checked';
$dark_css='dark';
}
foreach(PhangoApp\PhaRouter\Config::$modules_allowed as $module) {
//echo $module;
if(is_file($module.'/settings/config_admin.php')) {
include($module.'/settings/config_admin.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title><?=$title?></title>
<link href="<?=$this->make_media_url('modules/admin/media/css/admin.css')?>" rel="stylesheet" />
<link href="<?=$this->make_media_url('modules/admin/media/css/responsive-nav.css')?>" rel="stylesheet" />
<link href="<?=$this->make_media_url('modules/admin/media/css/tooltipster.bundle.min.css')?>" rel="stylesheet" />
<?=$this->section('extra_css')?>
<script language="Javascript" src="<?=$this->make_media_url('modules/admin/media/js/jquery.min.js')?>"></script>
<script language="Javascript" src="<?=$this->make_media_url('modules/admin/media/js/responsive-nav.min.js')?>"></script>
<script language="Javascript" src="<?=$this->make_media_url('modules/admin/media/js/tooltipster.bundle.min.js')?>"></script>
<?=$this->section('extra_js')?>
<?=$this->section('extra_header')?>
</head>
<body class="<?=$dark_css?>">
<div id="layer_loading"><div id="container_loading"><div class="lds-dual-ring"></div></div></div>
<div id="languages_general">
</div>
<div id="logout">
<a href="<?=$this->make_url('admin', 'app', ['logout'])?>"><i class="fa fa-power-off" aria-hidden="true"></i> <?=_('Logout')?></a>
</div>
<div id="center_body">
<div id="header">
<a href="#nav" id="toggle"><i class="fa fa-bars" aria-hidden="true"></i><span>Menu</span></a>
<span id="title_phango"><?=PhangoApp\PhaRouter\Config::$portal_name?></span>
</div>
<div class="content_admin">
<nav id="menu" class="nav-collapse">
<ul>
<li class="menu_title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="22" style="fill: currentColor;display: inline-block;vertical-align: -.130em;position:relative;left:-3px;top:2px;">
<!--!Font Awesome Free v7.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.-->
<path d="M259.1 73.5C262.1 58.7 275.2 48 290.4 48L350.2 48C365.4 48 378.5 58.7 381.5 73.5L396 143.5C410.1 149.5 423.3 157.2 435.3 166.3L503.1 143.8C517.5 139 533.3 145 540.9 158.2L570.8 210C578.4 223.2 575.7 239.8 564.3 249.9L511 297.3C511.9 304.7 512.3 312.3 512.3 320C512.3 327.7 511.8 335.3 511 342.7L564.4 390.2C575.8 400.3 578.4 417 570.9 430.1L541 481.9C533.4 495 517.6 501.1 503.2 496.3L435.4 473.8C423.3 482.9 410.1 490.5 396.1 496.6L381.7 566.5C378.6 581.4 365.5 592 350.4 592L290.6 592C275.4 592 262.3 581.3 259.3 566.5L244.9 496.6C230.8 490.6 217.7 482.9 205.6 473.8L137.5 496.3C123.1 501.1 107.3 495.1 99.7 481.9L69.8 430.1C62.2 416.9 64.9 400.3 76.3 390.2L129.7 342.7C128.8 335.3 128.4 327.7 128.4 320C128.4 312.3 128.9 304.7 129.7 297.3L76.3 249.8C64.9 239.7 62.3 223 69.8 209.9L99.7 158.1C107.3 144.9 123.1 138.9 137.5 143.7L205.3 166.2C217.4 157.1 230.6 149.5 244.6 143.4L259.1 73.5zM320.3 400C364.5 399.8 400.2 363.9 400 319.7C399.8 275.5 363.9 239.8 319.7 240C275.5 240.2 239.8 276.1 240 320.3C240.2 364.5 276.1 400.2 320.3 400z"/></svg><?=_('Applications')?></li>
<?php
foreach(Admin\Settings\Config::$config_admin as $admin) {
$class_selected='';
$link_text='';
if(count($admin)>=3) {
if($admin[2]==$path_module) {
$class_selected='selected_menu';
}
$icon_module='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640" width="22" style="fill: currentColor;display: inline-block;vertical-align: -.130em;position:relative;left:-3px;top:2px;"><!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.--><path d="M528 320C528 205.1 434.9 112 320 112C205.1 112 112 205.1 112 320C112 434.9 205.1 528 320 528C434.9 528 528 434.9 528 320zM64 320C64 178.6 178.6 64 320 64C461.4 64 576 178.6 576 320C576 461.4 461.4 576 320 576C178.6 576 64 461.4 64 320z"/></svg>';
if(count($admin)>3) {
$icon_module=$admin[3];
}
$link_text=$admin[0];
?>
<li><a href="<?=$this->make_url($admin[1])?>" class="<?=$class_selected?>">&nbsp;
<?=$icon_module?>
<?=$link_text?>
</a>
</li>
<?php
}
else if(count($admin)==1) {
$link_text=$admin[0];
?>
<li><div class="father_admin"><?=$link_text?></div></li>
<?php
}
}
?>
</ul>
</nav>
<div class="contents">
<h1><?=$title?></h1>
<div class="switch-btn">
<div class="switch-text">
<?=_('Dark theme')?>
</div>
<div class="switch-slider">
<label class="switch">
<input type="checkbox" name="theme" value="1" id="theme" <?=$dark_checked?>/>
<span class="slider round"></span>
</label>
</div>
</div>
<div class="content">
<?php
if(isset($_SESSION['flash'])) {
?>
<div class="flash"><?=$_SESSION['flash']?></div>
<?php
unset($_SESSION['flash']);
}
?>
<script>setTimeout(function () { $(".flash").fadeOut(); }, 3000);</script>
<?=$this->section('content')?>
</div>
</div>
</div>
<div id="loading_ajax">
</div>
<script>
var navigation = responsiveNav(".nav-collapse", {customToggle: "#toggle"});
$('.tooltip').tooltipster({
animation: 'fade',
delay: 100,
trigger: 'click'
});
const slider = document.querySelector('input[name="theme"]');
slider.addEventListener("change", function () {
//Block button while send to ajax.
$(this).prop("disabled",true);
var dark='';
if (this.checked) {
document.body.classList.add("dark");
dark='1';
} else {
document.body.classList.remove("dark");
dark='0';
}
$.ajax({
url: "<?=$this->make_url('admin', 'app', ['change_theme'])?>?theme="+dark,
type: 'GET',
data: {},
success: function (data) {
if(!data.error) {
console.log('Changed to dark in all pages');
}
else {
console.log('Cannot set dark theme in all pages!');
}
$(slider).prop("disabled",false);
},
error: function (data) {
alert('Error: '+data.status+' '+data.statusText);
$(slider).prop("disabled", false);
},
dataType: 'json'
});
});
$(document).ready(function () {
$('#layer_loading').hide();
});
</script>
<?=$this->section('footer_js')?>
</body>
</html>