diff --git a/app/Http/Controllers/Web/Auth/LoginController.php b/app/Http/Controllers/Web/Auth/LoginController.php index 5c453a2..cc7361d 100644 --- a/app/Http/Controllers/Web/Auth/LoginController.php +++ b/app/Http/Controllers/Web/Auth/LoginController.php @@ -44,7 +44,7 @@ class LoginController extends Controller $throttles = (bool) setting('throttle_enabled'); //Redirect URL that can be passed as hidden field. - $to = $request->has('to') ? '?to='.$request->get('to') : ''; + $to = $request->has('to') ? '?to=' . $request->get('to') : ''; if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); @@ -60,20 +60,20 @@ class LoginController extends Controller $this->incrementLoginAttempts($request); } - return redirect()->to('login'.$to) + return redirect()->to('login' . $to) ->withErrors(trans('auth.failed')); } $user = Auth::getProvider()->retrieveByCredentials($credentials); if ($user->isBanned()) { - return redirect()->to('login'.$to) + return redirect()->to('login' . $to) ->withErrors(trans('auth.banned')); } $maxSessions = setting('max_active_sessions'); if ($maxSessions && $sessions->getActiveSessionsCount($user->id) >= $maxSessions) { - return redirect()->to('login'.$to) + return redirect()->to('login' . $to) ->withErrors(trans('auth.max_sessions_reached')); } @@ -94,21 +94,22 @@ class LoginController extends Controller $this->clearLoginAttempts($request); } - $redirectPage = $request->get('to'); - - if (setting('2fa.enabled') && $user->twoFactorEnabled()) { - return $this->logoutAndRedirectToTokenPage($request, $user, $redirectPage); + // Redirezione basata sul ruolo con la prima lettera maiuscola e prefisso 'userarea/' + if ($user->hasRole('Admin')) { + return redirect()->to('userarea/admin.php'); + } elseif ($user->hasRole('User')) { + return redirect()->to('userarea/index.php'); + } elseif ($user->hasRole('teacher')) { + return redirect()->to('userarea/teacher.php'); + } elseif ($user->hasRole('school_owner')) { + return redirect()->to('userarea/school.php'); } - event(new LoggedIn); - - if ($redirectPage) { - return redirect()->to($redirectPage); - } - - return redirect()->intended(); + // Fallback nel caso il ruolo non corrisponda + return redirect()->intended('userarea/default.php'); } + protected function logoutAndRedirectToTokenPage(Request $request, $user, ?string $redirectPage): RedirectResponse { Auth::logout(); diff --git a/composer.json b/composer.json index a77fd58..a6ced3f 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "ext-json": "*", "akaunting/laravel-setting": "^1.2.9", "anhskohbo/no-captcha": "3.*", + "endroid/qr-code": "^6.0", "guzzlehttp/guzzle": "^7.2", "intervention/image": "^2.3", "jenssegers/agent": "^2.5", diff --git a/composer.lock b/composer.lock index 2723507..93fc043 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ed20966daeba17c2b7fec1306f6026f", + "content-hash": "e88a79d9daab1216f18318680b38681e", "packages": [ { "name": "akaunting/laravel-setting", @@ -741,6 +741,78 @@ ], "time": "2023-10-06T06:47:41+00:00" }, + { + "name": "endroid/qr-code", + "version": "6.0.6", + "source": { + "type": "git", + "url": "https://github.com/endroid/qr-code.git", + "reference": "11e6a94458dab8dd18736c11892130ec788b5028" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/endroid/qr-code/zipball/11e6a94458dab8dd18736c11892130ec788b5028", + "reference": "11e6a94458dab8dd18736c11892130ec788b5028", + "shasum": "" + }, + "require": { + "bacon/bacon-qr-code": "^3.0", + "php": "^8.2" + }, + "require-dev": { + "endroid/quality": "dev-main", + "ext-gd": "*", + "khanamiryan/qrcode-detector-decoder": "^2.0.2", + "setasign/fpdf": "^1.8.2" + }, + "suggest": { + "ext-gd": "Enables you to write PNG images", + "khanamiryan/qrcode-detector-decoder": "Enables you to use the image validator", + "roave/security-advisories": "Makes sure package versions with known security issues are not installed", + "setasign/fpdf": "Enables you to use the PDF writer" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Endroid\\QrCode\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeroen van den Enden", + "email": "info@endroid.nl" + } + ], + "description": "Endroid QR Code", + "homepage": "https://github.com/endroid/qr-code", + "keywords": [ + "code", + "endroid", + "php", + "qr", + "qrcode" + ], + "support": { + "issues": "https://github.com/endroid/qr-code/issues", + "source": "https://github.com/endroid/qr-code/tree/6.0.6" + }, + "funding": [ + { + "url": "https://github.com/endroid", + "type": "github" + } + ], + "time": "2025-03-14T23:29:08+00:00" + }, { "name": "firebase/php-jwt", "version": "v6.10.1", diff --git a/public/phototeachers/qrcodes/2-df968f3ff71def10.png b/public/phototeachers/qrcodes/2-df968f3ff71def10.png new file mode 100644 index 0000000..32dd3b7 Binary files /dev/null and b/public/phototeachers/qrcodes/2-df968f3ff71def10.png differ diff --git a/public/userarea/assets/css/header-colors.css b/public/userarea/assets/css/header-colors.css index 1fe4042..97e9860 100644 --- a/public/userarea/assets/css/header-colors.css +++ b/public/userarea/assets/css/header-colors.css @@ -1,109 +1,111 @@ html.color-header .topbar .navbar-nav .nav-link { - color: #fff + color: #fff; } html.color-header .topbar .navbar .navbar-nav .nav-link:hover, html.color-header .topbar .navbar .navbar-nav .nav-link:focus { - background-color: rgb(255 255 255 / 12%); + background-color: rgb(255 255 255 / 12%); color: #ffffff; } html.color-header .search-bar a.btn, -html.color-header .search-bar a.btn:focus{ +html.color-header .search-bar a.btn:focus { color: #221f1f; background-color: #ffffff; } html.color-header::placeholder { - color: #08090a!important; - opacity: .5!important + color: #08090a !important; + opacity: 0.5 !important; } html.color-header .search-show { - color: #221f1f + color: #221f1f; } html.color-header .user-info .user-name { - color: #fff + color: #fff; } html.color-header .user-info .designattion { - color: #fff + color: #fff; } html.color-header .user-box { - border-left: 1px solid rgb(255 255 255 / .15) !important; - border-right: 1px solid rgb(255 255 255 / .15) !important; + border-left: 1px solid rgb(255 255 255 / 0.15) !important; + border-right: 1px solid rgb(255 255 255 / 0.15) !important; } - html.color-header .mobile-toggle-menu { - color: #fff + color: #fff; } .switcher-body .headercolor1 { - background: #0727d7!important + background: #0727d7 !important; } .switcher-body .headercolor2 { - background: #23282c!important + background: #23282c !important; } .switcher-body .headercolor3 { - background: #e10a1f!important + background: #e10a1f !important; } .switcher-body .headercolor4 { - background: #157d4c!important + background: #157d4c !important; } .switcher-body .headercolor5 { - background: #673ab7!important + background: #673ab7 !important; } .switcher-body .headercolor6 { - background: #795548!important + background: #795548 !important; } .switcher-body .headercolor7 { - background: #d3094e!important + background: #d3094e !important; } .switcher-body .headercolor8 { - background: #ff9800!important + background: #ff9800 !important; +} +.switcher-body .headercolor9 { + background: #9e5f00 !important; } html.headercolor1 .topbar { - background: #0727d7 + background: #0727d7; } html.headercolor2 .topbar { - background: #23282c + background: #23282c; } html.headercolor3 .topbar { - background: #e10a1f + background: #e10a1f; } html.headercolor4 .topbar { - background: #157d4c + background: #157d4c; } html.headercolor5 .topbar { - background: #673ab7 + background: #673ab7; } html.headercolor6 .topbar { - background: #795548 + background: #795548; } html.headercolor7 .topbar { - background: #d3094e + background: #d3094e; } html.headercolor8 .topbar { - background: #ff9800 + background: #ff9800; +} +html.headercolor9 .topbar { + background: #f7c77f; } - - /* sidebar color */ - -html.color-sidebar .sidebar-wrapper{ - background-color: #171717; +html.color-sidebar .sidebar-wrapper { + background-color: #171717; border-right: 1px solid rgb(228 228 228 / 0%); } -html.color-sidebar .sidebar-header{ - background-color: transparent; +html.color-sidebar .sidebar-header { + background-color: transparent; border-right: 1px solid #e4e4e400; border-bottom: 1px solid rgb(255 255 255 / 15%); - position: absolute; + position: absolute; } html.color-sidebar .logo-icon { filter: invert(1) grayscale(100%) brightness(200%); } -html.color-sidebar .menu-label{ - color: rgb(255 255 255 / 65%); +html.color-sidebar .menu-label { + color: rgb(255 255 255 / 65%); } html.color-sidebar .sidebar-wrapper .sidebar-header .logo-text { @@ -115,10 +117,13 @@ html.color-sidebar .sidebar-wrapper .sidebar-header .toggle-icon { } html.color-sidebar .simplebar-scrollbar:before { - background: rgba(255, 255, 255, .4) + background: rgba(255, 255, 255, 0.4); } -html.color-sidebar .sidebar-wrapper .metismenu .mm-active>a, html.color-sidebar .sidebar-wrapper .metismenu a:active, html.color-sidebar .sidebar-wrapper .metismenu a:focus, html.color-sidebar .sidebar-wrapper .metismenu a:hover { +html.color-sidebar .sidebar-wrapper .metismenu .mm-active > a, +html.color-sidebar .sidebar-wrapper .metismenu a:active, +html.color-sidebar .sidebar-wrapper .metismenu a:focus, +html.color-sidebar .sidebar-wrapper .metismenu a:hover { color: #fff; text-decoration: none; background: rgb(255 255 255 / 15%); @@ -133,7 +138,6 @@ html.color-sidebar .sidebar-wrapper .metismenu ul { background: rgb(255 255 255 / 0%); } - html.color-sidebar .sidebar-wrapper { background-size: 100% 100%; background-attachment: fixed; @@ -141,35 +145,31 @@ html.color-sidebar .sidebar-wrapper { background-repeat: no-repeat; } - .switcher-wrapper .sidebarcolor1 { - background-image: url(../images/bg-themes/1.png); + background-image: url(../images/bg-themes/1.png); } .switcher-wrapper .sidebarcolor2 { - background-image: url(../images/bg-themes/2.png); + background-image: url(../images/bg-themes/2.png); } .switcher-wrapper .sidebarcolor3 { - background-image: url(../images/bg-themes/3.png); + background-image: url(../images/bg-themes/3.png); } .switcher-wrapper .sidebarcolor4 { - background-image: url(../images/bg-themes/4.png); + background-image: url(../images/bg-themes/4.png); } .switcher-wrapper .sidebarcolor5 { - background-image: url(../images/bg-themes/5.png); + background-image: url(../images/bg-themes/5.png); } .switcher-wrapper .sidebarcolor6 { - background-image: url(../images/bg-themes/6.png); + background-image: url(../images/bg-themes/6.png); } .switcher-wrapper .sidebarcolor7 { - background-image: url(../images/bg-themes/7.png); + background-image: url(../images/bg-themes/7.png); } .switcher-wrapper .sidebarcolor8 { - background-image: url(../images/bg-themes/8.png); + background-image: url(../images/bg-themes/8.png); } - - - html.color-sidebar.sidebarcolor1 .sidebar-wrapper { background-image: url(../images/bg-themes/1.png); } @@ -201,10 +201,3 @@ html.color-sidebar.sidebarcolor7 .sidebar-wrapper { html.color-sidebar.sidebarcolor8 .sidebar-wrapper { background-image: url(../images/bg-themes/8.png); } - - - - - - - diff --git a/public/userarea/assets/js/app.js b/public/userarea/assets/js/app.js index 0b30ded..218f4ec 100644 --- a/public/userarea/assets/js/app.js +++ b/public/userarea/assets/js/app.js @@ -1,202 +1,235 @@ -$("html").attr("class", "semi-dark color-header headercolor2"); +$("html").attr( + "class", + "semi-dark color-header " + + (localStorage.getItem("headerColor") || "headercolor4") + + " color-sidebar " + + (localStorage.getItem("sidebarColor") || "sidebarcolor9"), +); $(function () { - "use strict"; - new PerfectScrollbar(".app-container"), - new PerfectScrollbar(".header-message-list"), - new PerfectScrollbar(".header-notifications-list"), - $(".mobile-search-icon").on("click", function () { - $(".search-bar").addClass("full-search-bar"); - }), - $(".search-close").on("click", function () { - $(".search-bar").removeClass("full-search-bar"); - }), - $(".mobile-toggle-menu").on("click", function () { - $(".wrapper").addClass("toggled"); - }), - $(".dark-mode").on("click", function () { - if ($(".dark-mode-icon i").attr("class") == "bx bx-sun") { - $(".dark-mode-icon i").attr("class", "bx bx-moon"); - $("html").attr("class", "light-theme"); - } else { - $(".dark-mode-icon i").attr("class", "bx bx-sun"); - $("html").attr("class", "dark-theme"); - } - }), - $(".toggle-icon").click(function () { - $(".wrapper").hasClass("toggled") - ? ($(".wrapper").removeClass("toggled"), - $(".sidebar-wrapper").unbind("hover")) - : ($(".wrapper").addClass("toggled"), - $(".sidebar-wrapper").hover( - function () { - $(".wrapper").addClass("sidebar-hovered"); - }, - function () { - $(".wrapper").removeClass("sidebar-hovered"); + "use strict"; + new PerfectScrollbar(".app-container"), + new PerfectScrollbar(".header-message-list"), + new PerfectScrollbar(".header-notifications-list"), + $(".mobile-search-icon").on("click", function () { + $(".search-bar").addClass("full-search-bar"); + }), + $(".search-close").on("click", function () { + $(".search-bar").removeClass("full-search-bar"); + }), + $(".mobile-toggle-menu").on("click", function () { + $(".wrapper").addClass("toggled"); + }), + $(".dark-mode").on("click", function () { + if ($(".dark-mode-icon i").attr("class") == "bx bx-sun") { + $(".dark-mode-icon i").attr("class", "bx bx-moon"); + $("html").attr("class", "light-theme"); + } else { + $(".dark-mode-icon i").attr("class", "bx bx-sun"); + $("html").attr("class", "dark-theme"); } - )); - }), - $(document).ready(function () { - $(window).on("scroll", function () { - $(this).scrollTop() > 300 - ? $(".back-to-top").fadeIn() - : $(".back-to-top").fadeOut(); - }), - $(".back-to-top").on("click", function () { - return ( - $("html, body").animate( - { - scrollTop: 0, - }, - 600 - ), - !1 - ); - }); - }), - $(function () { - for ( - var e = window.location, - o = $(".metismenu li a") - .filter(function () { - return this.href == e; - }) - .addClass("") - .parent() - .addClass("mm-active"); - o.is("li"); + }), + $(".toggle-icon").click(function () { + $(".wrapper").hasClass("toggled") + ? ($(".wrapper").removeClass("toggled"), + $(".sidebar-wrapper").unbind("hover")) + : ($(".wrapper").addClass("toggled"), + $(".sidebar-wrapper").hover( + function () { + $(".wrapper").addClass("sidebar-hovered"); + }, + function () { + $(".wrapper").removeClass("sidebar-hovered"); + }, + )); + }), + $(document).ready(function () { + $(window).on("scroll", function () { + $(this).scrollTop() > 300 + ? $(".back-to-top").fadeIn() + : $(".back-to-top").fadeOut(); + }), + $(".back-to-top").on("click", function () { + return ( + $("html, body").animate( + { + scrollTop: 0, + }, + 600, + ), + !1 + ); + }); + }), + $(function () { + for ( + var e = window.location, + o = $(".metismenu li a") + .filter(function () { + return this.href == e; + }) + .addClass("") + .parent() + .addClass("mm-active"); + o.is("li"); + + ) + o = o + .parent("") + .addClass("mm-show") + .parent("") + .addClass("mm-active"); + }), + $(function () { + $("#menu").metisMenu(); + }), + $(".chat-toggle-btn").on("click", function () { + $(".chat-wrapper").toggleClass("chat-toggled"); + }), + $(".chat-toggle-btn-mobile").on("click", function () { + $(".chat-wrapper").removeClass("chat-toggled"); + }), + $(".email-toggle-btn").on("click", function () { + $(".email-wrapper").toggleClass("email-toggled"); + }), + $(".email-toggle-btn-mobile").on("click", function () { + $(".email-wrapper").removeClass("email-toggled"); + }), + $(".compose-mail-btn").on("click", function () { + $(".compose-mail-popup").show(); + }), + $(".compose-mail-close").on("click", function () { + $(".compose-mail-popup").hide(); + }), + $(".switcher-btn").on("click", function () { + $(".switcher-wrapper").toggleClass("switcher-toggled"); + }), + $(".close-switcher").on("click", function () { + $(".switcher-wrapper").removeClass("switcher-toggled"); + }), + $("#lightmode").on("click", function () { + $("html").attr("class", "light-theme"); + }), + $("#darkmode").on("click", function () { + $("html").attr("class", "dark-theme"); + }), + $("#semidark").on("click", function () { + $("html").attr("class", "semi-dark"); + }), + $("#minimaltheme").on("click", function () { + $("html").attr("class", "minimal-theme"); + }), + $("#headercolor1").on("click", function () { + $("html").addClass("color-header headercolor1"), + $("html").removeClass( + "headercolor2 headercolor3 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor1"); + }); - ) - o = o.parent("").addClass("mm-show").parent("").addClass("mm-active"); - }), - $(function () { - $("#menu").metisMenu(); - }), - $(".chat-toggle-btn").on("click", function () { - $(".chat-wrapper").toggleClass("chat-toggled"); - }), - $(".chat-toggle-btn-mobile").on("click", function () { - $(".chat-wrapper").removeClass("chat-toggled"); - }), - $(".email-toggle-btn").on("click", function () { - $(".email-wrapper").toggleClass("email-toggled"); - }), - $(".email-toggle-btn-mobile").on("click", function () { - $(".email-wrapper").removeClass("email-toggled"); - }), - $(".compose-mail-btn").on("click", function () { - $(".compose-mail-popup").show(); - }), - $(".compose-mail-close").on("click", function () { - $(".compose-mail-popup").hide(); - }), - $(".switcher-btn").on("click", function () { - $(".switcher-wrapper").toggleClass("switcher-toggled"); - }), - $(".close-switcher").on("click", function () { - $(".switcher-wrapper").removeClass("switcher-toggled"); - }), - $("#lightmode").on("click", function () { - $("html").attr("class", "light-theme"); - }), - $("#darkmode").on("click", function () { - $("html").attr("class", "dark-theme"); - }), - $("#semidark").on("click", function () { - $("html").attr("class", "semi-dark"); - }), - $("#minimaltheme").on("click", function () { - $("html").attr("class", "minimal-theme"); - }), - $("#headercolor1").on("click", function () { - $("html").addClass("color-header headercolor1"), - $("html").removeClass( - "headercolor2 headercolor3 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8" - ); - }), $("#headercolor2").on("click", function () { - $("html").addClass("color-header headercolor2"), - $("html").removeClass( - "headercolor1 headercolor3 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8" - ); - }), - $("#headercolor3").on("click", function () { - $("html").addClass("color-header headercolor3"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8" - ); - }), - $("#headercolor4").on("click", function () { - $("html").addClass("color-header headercolor4"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor3 headercolor5 headercolor6 headercolor7 headercolor8" - ); - }), - $("#headercolor5").on("click", function () { - $("html").addClass("color-header headercolor5"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor4 headercolor3 headercolor6 headercolor7 headercolor8" - ); - }), - $("#headercolor6").on("click", function () { - $("html").addClass("color-header headercolor6"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor4 headercolor5 headercolor3 headercolor7 headercolor8" - ); - }), - $("#headercolor7").on("click", function () { - $("html").addClass("color-header headercolor7"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor3 headercolor8" - ); - }), - $("#headercolor8").on("click", function () { - $("html").addClass("color-header headercolor8"), - $("html").removeClass( - "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor7 headercolor3" - ); + $("html").addClass("color-header headercolor2"), + $("html").removeClass( + "headercolor1 headercolor3 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor2"); }); - // sidebar colors - $("#sidebarcolor1").click(theme1); - $("#sidebarcolor2").click(theme2); - $("#sidebarcolor3").click(theme3); - $("#sidebarcolor4").click(theme4); - $("#sidebarcolor5").click(theme5); - $("#sidebarcolor6").click(theme6); - $("#sidebarcolor7").click(theme7); - $("#sidebarcolor8").click(theme8); + $("#headercolor3").on("click", function () { + $("html").addClass("color-header headercolor3"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor3"); + }); - function theme1() { - $("html").attr("class", "color-sidebar sidebarcolor1"); - } + $("#headercolor4").on("click", function () { + $("html").addClass("color-header headercolor4"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor3 headercolor5 headercolor6 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor4"); + }); - function theme2() { - $("html").attr("class", "color-sidebar sidebarcolor2"); - } + $("#headercolor5").on("click", function () { + $("html").addClass("color-header headercolor5"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor4 headercolor3 headercolor6 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor5"); + }); - function theme3() { - $("html").attr("class", "color-sidebar sidebarcolor3"); - } + $("#headercolor6").on("click", function () { + $("html").addClass("color-header headercolor6"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor4 headercolor5 headercolor3 headercolor7 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor6"); + }); - function theme4() { - $("html").attr("class", "color-sidebar sidebarcolor4"); - } + $("#headercolor7").on("click", function () { + $("html").addClass("color-header headercolor7"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor3 headercolor8 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor7"); + }); - function theme5() { - $("html").attr("class", "color-sidebar sidebarcolor5"); - } + $("#headercolor8").on("click", function () { + $("html").addClass("color-header headercolor8"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor4 headercolor5 headercolor6 headercolor7 headercolor3 headercolor9", + ); + localStorage.setItem("headerColor", "headercolor8"); + }); - function theme6() { - $("html").attr("class", "color-sidebar sidebarcolor6"); - } + $("#headercolor9").on("click", function () { + $("html").addClass("color-header headercolor9"), + $("html").removeClass( + "headercolor1 headercolor2 headercolor3 headercolor4 headercolor5 headercolor6 headercolor7 headercolor8", + ); + localStorage.setItem("headerColor", "headercolor9"); + }); - function theme7() { - $("html").attr("class", "color-sidebar sidebarcolor7"); - } + // sidebar colors + $("#sidebarcolor1").click(theme1); + $("#sidebarcolor2").click(theme2); + $("#sidebarcolor3").click(theme3); + $("#sidebarcolor4").click(theme4); + $("#sidebarcolor5").click(theme5); + $("#sidebarcolor6").click(theme6); + $("#sidebarcolor7").click(theme7); + $("#sidebarcolor8").click(theme8); - function theme8() { - $("html").attr("class", "color-sidebar sidebarcolor8"); - } + function theme1() { + $("html").attr("class", "color-sidebar sidebarcolor1"); + } + + function theme2() { + $("html").attr("class", "color-sidebar sidebarcolor2"); + } + + function theme3() { + $("html").attr("class", "color-sidebar sidebarcolor3"); + } + + function theme4() { + $("html").attr("class", "color-sidebar sidebarcolor4"); + } + + function theme5() { + $("html").attr("class", "color-sidebar sidebarcolor5"); + } + + function theme6() { + $("html").attr("class", "color-sidebar sidebarcolor6"); + } + + function theme7() { + $("html").attr("class", "color-sidebar sidebarcolor7"); + } + + function theme8() { + $("html").attr("class", "color-sidebar sidebarcolor8"); + } }); diff --git a/public/userarea/class_categories.php b/public/userarea/class_categories.php new file mode 100644 index 0000000..3e39fe8 --- /dev/null +++ b/public/userarea/class_categories.php @@ -0,0 +1,277 @@ +getConnection(); + +// Gestione delle azioni (aggiunta, modifica, cancellazione) +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['action'])) { + $action = $_POST['action']; + + // Aggiunta di una nuova categoria + if ($action === 'add') { + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + if (empty($name)) { + $error = "Il nome della categoria è obbligatorio."; + } else { + $stmt = $pdo->prepare(" + INSERT INTO class_categories (name, description, status) + VALUES (?, ?, ?) + "); + $success = $stmt->execute([$name, $description, $status]); + + if ($success) { + $success_message = "Categoria aggiunta con successo!"; + } else { + $error = "Errore durante l'aggiunta della categoria."; + } + } + } + + // Modifica di una categoria esistente + if ($action === 'edit') { + $id = $_POST['id'] ?? 0; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + if (empty($name)) { + $error = "Il nome della categoria è obbligatorio."; + } else { + $stmt = $pdo->prepare(" + UPDATE class_categories + SET name = ?, description = ?, status = ? + WHERE id = ? + "); + $success = $stmt->execute([$name, $description, $status, $id]); + + if ($success) { + $success_message = "Categoria aggiornata con successo!"; + } else { + $error = "Errore durante l'aggiornamento della categoria."; + } + } + } + + // Cancellazione di una categoria + if ($action === 'delete') { + $id = $_POST['id'] ?? 0; + $stmt = $pdo->prepare("DELETE FROM class_categories WHERE id = ?"); + $success = $stmt->execute([$id]); + + if ($success) { + $success_message = "Categoria eliminata con successo!"; + } else { + $error = "Errore durante l'eliminazione della categoria."; + } + } + + // Reindirizza per evitare il doppio invio del form + header("Location: class_categories.php"); + exit; + } +} + +// Recupera tutte le categorie +$stmt = $pdo->prepare("SELECT * FROM class_categories ORDER BY created_at DESC"); +$stmt->execute(); +$categories = $stmt->fetchAll(); +?> + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
Gestione Categorie Classi
+
+
+ +
+
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
IDNomeDescrizioneStatoData CreazioneUltimo AggiornamentoAzioni
+ + + + + +
+ + + +
+
+
+
+
+
+
+ + + + + + + +
+ + +
+ + + + + + + \ No newline at end of file diff --git a/public/userarea/class_types.php b/public/userarea/class_types.php new file mode 100644 index 0000000..45ba6ed --- /dev/null +++ b/public/userarea/class_types.php @@ -0,0 +1,612 @@ +getConnection(); + +// Verifica che iduserlogin sia definito +if (!isset($iduserlogin)) { + die("Errore: ID utente non definito."); +} + +// Recupera l'ID della scuola in base all'utente loggato +$stmt = $pdo->prepare("SELECT id, name FROM schools WHERE owner_id = ?"); +$stmt->execute([$iduserlogin]); +$school = $stmt->fetch(); +if (!$school) { + die("Errore: Nessuna scuola trovata per l'utente loggato."); +} +$school_id = $school['id']; +$school_name = $school['name']; + +// Recupera tutte le categorie disponibili +$stmt = $pdo->prepare("SELECT id, name FROM class_categories WHERE status = 'active' ORDER BY name"); +$stmt->execute(); +$categories = $stmt->fetchAll(); + +// Funzione per ridimensionare l'immagine +function resizeImage($source_path, $dest_path, $max_width = 800) +{ + list($width, $height, $type) = getimagesize($source_path); + if ($width <= $max_width) { + copy($source_path, $dest_path); + return; + } + + $new_width = $max_width; + $new_height = (int)(($height * $new_width) / $width); + + switch ($type) { + case IMAGETYPE_JPEG: + $source = imagecreatefromjpeg($source_path); + break; + case IMAGETYPE_PNG: + $source = imagecreatefrompng($source_path); + break; + case IMAGETYPE_GIF: + $source = imagecreatefromgif($source_path); + break; + default: + throw new Exception("Formato immagine non supportato."); + } + + $dest = imagecreatetruecolor($new_width, $new_height); + if ($type == IMAGETYPE_PNG) { + imagealphablending($dest, false); + imagesavealpha($dest, true); + } + imagecopyresampled($dest, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + + switch ($type) { + case IMAGETYPE_JPEG: + imagejpeg($dest, $dest_path, 90); + break; + case IMAGETYPE_PNG: + imagepng($dest, $dest_path); + break; + case IMAGETYPE_GIF: + imagegif($dest, $dest_path); + break; + } + + imagedestroy($source); + imagedestroy($dest); +} + +// Gestione delle azioni (aggiunta, modifica, cancellazione) +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['action'])) { + $action = $_POST['action']; + + // Aggiunta di una nuova classe + if ($action === 'add') { + $class_category_id = $_POST['class_category_id'] ?? 0; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $requirements = $_POST['requirements'] ?? null; + $level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner'; + $typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null; + $days_of_week = $_POST['days_of_week'] ?? ''; + $start_time = $_POST['start_time'] ?? ''; + $period_start = $_POST['period_start'] ?? ''; + $period_end = $_POST['period_end'] ?? ''; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time) || empty($period_start) || empty($period_end)) { + $error = "I campi obbligatori non sono stati compilati."; + } else { + $photo = null; + if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['photo']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "photoclass/{$school_id}-{$timestamp}-{$original_name}"; + $temp_path = $file['tmp_name']; + try { + resizeImage($temp_path, $new_filename); + $photo = $new_filename; + } catch (Exception $e) { + $error = "Errore durante il ridimensionamento della foto: " . $e->getMessage(); + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + if (!isset($error)) { + $stmt = $pdo->prepare(" + INSERT INTO class_types (school_id, class_category_id, name, description, photo, requirements, level, typical_duration, days_of_week, start_time, period_start, period_end, status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + "); + $success = $stmt->execute([ + $school_id, + $class_category_id, + $name, + $description, + $photo, + $requirements, + $level, + $typical_duration, + $days_of_week, + $start_time, + $period_start, + $period_end, + $status + ]); + + if ($success) { + $success_message = "Classe aggiunta con successo!"; + } else { + $error = "Errore durante l'aggiunta della classe."; + } + } + } + } + + // Modifica di una classe esistente + if ($action === 'edit') { + $id = $_POST['id'] ?? 0; + $class_category_id = $_POST['class_category_id'] ?? 0; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $requirements = $_POST['requirements'] ?? null; + $level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner'; + $typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null; + $days_of_week = $_POST['days_of_week'] ?? ''; + $start_time = $_POST['start_time'] ?? ''; + $period_start = $_POST['period_start'] ?? ''; + $period_end = $_POST['period_end'] ?? ''; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time) || empty($period_start) || empty($period_end)) { + $error = "I campi obbligatori non sono stati compilati."; + } else { + // Recupera la classe esistente per ottenere il percorso della foto attuale + $stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$id, $school_id]); + $class = $stmt->fetch(); + if (!$class) { + $error = "Classe non trovata."; + } else { + $photo = $class['photo']; + if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['photo']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "photoclass/{$school_id}-{$timestamp}-{$original_name}"; + $temp_path = $file['tmp_name']; + try { + resizeImage($temp_path, $new_filename); + $photo = $new_filename; + if ($class['photo'] && file_exists($class['photo'])) { + unlink($class['photo']); + } + } catch (Exception $e) { + $error = "Errore durante il ridimensionamento della foto: " . $e->getMessage(); + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + if (!isset($error)) { + $stmt = $pdo->prepare(" + UPDATE class_types + SET class_category_id = ?, name = ?, description = ?, photo = ?, requirements = ?, level = ?, + typical_duration = ?, days_of_week = ?, start_time = ?, period_start = ?, period_end = ?, status = ? + WHERE id = ? AND school_id = ? + "); + $success = $stmt->execute([ + $class_category_id, + $name, + $description, + $photo, + $requirements, + $level, + $typical_duration, + $days_of_week, + $start_time, + $period_start, + $period_end, + $status, + $id, + $school_id + ]); + + if ($success) { + $success_message = "Classe aggiornata con successo!"; + } else { + $error = "Errore durante l'aggiornamento della classe."; + } + } + } + } + } + + // Cancellazione di una classe + if ($action === 'delete') { + $id = $_POST['id'] ?? 0; + $stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$id, $school_id]); + $class = $stmt->fetch(); + if ($class) { + if ($class['photo'] && file_exists($class['photo'])) { + unlink($class['photo']); + } + $stmt = $pdo->prepare("DELETE FROM class_types WHERE id = ? AND school_id = ?"); + $success = $stmt->execute([$id, $school_id]); + + if ($success) { + $success_message = "Classe eliminata con successo!"; + } else { + $error = "Errore durante l'eliminazione della classe."; + } + } else { + $error = "Classe non trovata."; + } + } + + // Reindirizza per evitare il doppio invio del form + header("Location: class_types.php"); + exit; + } +} + +// Recupera tutte le classi della scuola +$stmt = $pdo->prepare(" + SELECT ct.*, cc.name AS category_name + FROM class_types ct + LEFT JOIN class_categories cc ON ct.class_category_id = cc.id + WHERE ct.school_id = ? + ORDER BY ct.created_at DESC +"); +$stmt->execute([$school_id]); +$classes = $stmt->fetchAll(); +?> + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
Classi della scuola:
+
+
+ +
+
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDCategoriaNomeDescrizioneFotoLivelloDurata (min)GiorniOrarioInizioFineStatoData CreazioneUltimo AggiornamentoAzioni
+ + Foto Classe + + Nessuna foto + + + + + + + +
+ + + +
+
+
+
+
+
+
+ + + + + + + +
+ + +
+ + + + + + + \ No newline at end of file diff --git a/public/userarea/cssinclude.php b/public/userarea/cssinclude.php index 72f35cd..24e32f7 100644 --- a/public/userarea/cssinclude.php +++ b/public/userarea/cssinclude.php @@ -15,4 +15,6 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/public/userarea/day_off.php b/public/userarea/day_off.php new file mode 100644 index 0000000..648d2c2 --- /dev/null +++ b/public/userarea/day_off.php @@ -0,0 +1,318 @@ +getConnection(); + +// Verifica che iduserlogin sia definito +if (!isset($iduserlogin)) { + die("Errore: ID utente non definito."); +} + +// Recupera i dati della scuola in base all'utente loggato +$stmt = $pdo->prepare("SELECT id, name FROM schools WHERE owner_id = ?"); +$stmt->execute([$iduserlogin]); +$school = $stmt->fetch(); +if (!$school) { + die("Errore: Nessuna scuola trovata per l'utente loggato."); +} +$school_id = $school['id']; +$school_name = $school['name']; + +// Gestione delle azioni (aggiunta, modifica, cancellazione) +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['action'])) { + $action = $_POST['action']; + + // Aggiunta di un giorno di chiusura + if ($action === 'add') { + $start_date = $_POST['start_date'] ?? ''; + $end_date = $_POST['end_date'] ?? ''; + $description = $_POST['description'] ?? null; + + // Validazione: assicurarsi che end_date >= start_date + if (empty($start_date) || empty($end_date)) { + $error = "Le date di inizio e fine sono obbligatorie."; + } elseif (strtotime($end_date) < strtotime($start_date)) { + $error = "La data di fine non può essere precedente alla data di inizio."; + } else { + $stmt = $pdo->prepare(" + INSERT INTO day_off (school_id, start_date, end_date, description) + VALUES (?, ?, ?, ?) + "); + $success = $stmt->execute([ + $school_id, + $start_date, + $end_date, + $description + ]); + + if ($success) { + $success_message = "Giorno di chiusura aggiunto con successo!"; + } else { + $error = "Errore durante l'aggiunta del giorno di chiusura."; + } + } + } + + // Modifica di un giorno di chiusura + if ($action === 'edit') { + $id = $_POST['id'] ?? 0; + $start_date = $_POST['start_date'] ?? ''; + $end_date = $_POST['end_date'] ?? ''; + $description = $_POST['description'] ?? null; + + // Validazione: assicurarsi che end_date >= start_date + if (empty($start_date) || empty($end_date)) { + $error = "Le date di inizio e fine sono obbligatorie."; + } elseif (strtotime($end_date) < strtotime($start_date)) { + $error = "La data di fine non può essere precedente alla data di inizio."; + } else { + $stmt = $pdo->prepare(" + UPDATE day_off + SET start_date = ?, end_date = ?, description = ? + WHERE id = ? AND school_id = ? + "); + $success = $stmt->execute([ + $start_date, + $end_date, + $description, + $id, + $school_id + ]); + + if ($success) { + $success_message = "Giorno di chiusura aggiornato con successo!"; + } else { + $error = "Errore durante l'aggiornamento del giorno di chiusura."; + } + } + } + + // Cancellazione di un giorno di chiusura + if ($action === 'delete') { + $id = $_POST['id'] ?? 0; + $stmt = $pdo->prepare("DELETE FROM day_off WHERE id = ? AND school_id = ?"); + $success = $stmt->execute([$id, $school_id]); + + if ($success) { + $success_message = "Giorno di chiusura eliminato con successo!"; + } else { + $error = "Errore durante l'eliminazione del giorno di chiusura."; + } + } + + // Reindirizza per evitare il doppio invio del form + header("Location: day_off.php"); + exit; + } +} + +// Recupera tutti i giorni di chiusura della scuola +$stmt = $pdo->prepare(" + SELECT * + FROM day_off + WHERE school_id = ? + ORDER BY start_date +"); +$stmt->execute([$school_id]); +$days_off = $stmt->fetchAll(); +?> + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+
+
+
+
+
Giorni di Chiusura -
+
+
+ + Torna alla Dashboard +
+
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + +
Data InizioData FineDescrizioneAzioni
+ +
+ + + +
+
+
+
+
+
+
+ + +
+ + + + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userarea/include/headscript.php b/public/userarea/include/headscript.php new file mode 100644 index 0000000..ce74be8 --- /dev/null +++ b/public/userarea/include/headscript.php @@ -0,0 +1,60 @@ +getConnection(); + +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL | E_STRICT); +// This should be equal to: PATH_TO_VANGUARD_FOLDER/extra/auth.php +include('../../extra/auth.php'); +//require_once __DIR__ . '/extra/auth.php'; + +// Here we just check if user is not +// logged in, and in that case we redirect +// the user to vanguard login page. + +if (! Auth::check()) { + + redirectTo('../../public/login'); +} + +$user = Auth::user(); + +$iduserlogin = $user->present()->id; +$nameuser = $user->present()->first_name; +$surnameuser = $user->present()->last_name; +$emailuser = $user->present()->email; +$avatar = $user->present()->avatar; + +$kindofrole = $user->present()->role_id; + + + +//$user = "1"; +//$iduserlogin="1"; +//$nameuser="Claudio"; +//$emailuser="info@claudiosironi.com"; +?> + + + + diff --git a/public/userarea/include/navbar.php b/public/userarea/include/navbar.php index 2770c83..ca92263 100644 --- a/public/userarea/include/navbar.php +++ b/public/userarea/include/navbar.php @@ -4,7 +4,7 @@ logo icon
-

Rocker

+

YogiBoook

diff --git a/public/userarea/include/themeswitcher.php b/public/userarea/include/themeswitcher.php index ea2db68..6b087b8 100644 --- a/public/userarea/include/themeswitcher.php +++ b/public/userarea/include/themeswitcher.php @@ -65,28 +65,57 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
+
+
Custom Colors
+
+
Custom Header Colors
+
+
+
+
+
+
+
+
+
+
+
+
Custom Sidebar Colors
+
+
+
+
+
+
+
diff --git a/public/userarea/include/topbar.php b/public/userarea/include/topbar.php index 0207e86..cf29af6 100644 --- a/public/userarea/include/topbar.php +++ b/public/userarea/include/topbar.php @@ -583,28 +583,22 @@ diff --git a/public/userarea/index.php b/public/userarea/index.php index 44279e1..4b200a2 100644 --- a/public/userarea/index.php +++ b/public/userarea/index.php @@ -1,3 +1,4 @@ + diff --git a/public/userarea/info.php b/public/userarea/info.php new file mode 100644 index 0000000..61ace19 --- /dev/null +++ b/public/userarea/info.php @@ -0,0 +1,2 @@ + + + diff --git a/public/userarea/photoclass/1-1743774607-Screenshot 2023-06-02 184213.png b/public/userarea/photoclass/1-1743774607-Screenshot 2023-06-02 184213.png new file mode 100644 index 0000000..8eb18f9 Binary files /dev/null and b/public/userarea/photoclass/1-1743774607-Screenshot 2023-06-02 184213.png differ diff --git a/public/userarea/photoschool/2-1743074782-aereo-costruzione-magnetico-legno-cgedu-centro-gioco-educativo_800x.jpg b/public/userarea/photoschool/2-1743074782-aereo-costruzione-magnetico-legno-cgedu-centro-gioco-educativo_800x.jpg new file mode 100644 index 0000000..950a7a1 Binary files /dev/null and b/public/userarea/photoschool/2-1743074782-aereo-costruzione-magnetico-legno-cgedu-centro-gioco-educativo_800x.jpg differ diff --git a/public/userarea/photoschool/ndphoto.png b/public/userarea/photoschool/ndphoto.png new file mode 100644 index 0000000..4b1e303 Binary files /dev/null and b/public/userarea/photoschool/ndphoto.png differ diff --git a/public/userarea/phototeachers/2-1743003400-Immagine WhatsApp 2024-04-14 ore 15.45.04_11e154cb.jpg b/public/userarea/phototeachers/2-1743003400-Immagine WhatsApp 2024-04-14 ore 15.45.04_11e154cb.jpg new file mode 100644 index 0000000..c3a33c4 Binary files /dev/null and b/public/userarea/phototeachers/2-1743003400-Immagine WhatsApp 2024-04-14 ore 15.45.04_11e154cb.jpg differ diff --git a/public/userarea/phototeachers/ndphoto.png b/public/userarea/phototeachers/ndphoto.png new file mode 100644 index 0000000..8026cfe Binary files /dev/null and b/public/userarea/phototeachers/ndphoto.png differ diff --git a/public/userarea/phototeachers/qrcodes/2-df968f3ff71def10.png b/public/userarea/phototeachers/qrcodes/2-df968f3ff71def10.png new file mode 100644 index 0000000..32dd3b7 Binary files /dev/null and b/public/userarea/phototeachers/qrcodes/2-df968f3ff71def10.png differ diff --git a/public/userarea/qr.php b/public/userarea/qr.php new file mode 100644 index 0000000..d907367 --- /dev/null +++ b/public/userarea/qr.php @@ -0,0 +1,22 @@ +build( + writer: new PngWriter(), + data: 'Test QR Code', // Sostituisci con il testo o URL che vuoi + size: 150, + margin: 10 + ); + + $qr_code_filename = __DIR__ . '/test-qr.png'; + $result->saveToFile($qr_code_filename); + + echo "QR Code generato con successo! Controlla il file: $qr_code_filename"; +} catch (Exception $e) { + echo "Errore: " . $e->getMessage(); +} diff --git a/public/userarea/qr_debug.txt b/public/userarea/qr_debug.txt new file mode 100644 index 0000000..3699337 --- /dev/null +++ b/public/userarea/qr_debug.txt @@ -0,0 +1,3 @@ +1 - Entrato nel blocco try +2 - Codice unico: df968f3ff71def10 +3 - QR non esiste, lo creo diff --git a/public/userarea/school_dashboard.php b/public/userarea/school_dashboard.php new file mode 100644 index 0000000..e6d2220 --- /dev/null +++ b/public/userarea/school_dashboard.php @@ -0,0 +1,1008 @@ +getConnection(); + +// Verifica che iduserlogin sia definito +if (!isset($iduserlogin)) { + die("Errore: ID utente non definito."); +} + +// Recupera i dati della scuola in base all'utente loggato +$stmt = $pdo->prepare(" + SELECT id, name, website, email, phone, description, address_street, address_city, address_postal_code, address_province, address_country, logo, status + FROM schools + WHERE owner_id = ? +"); +$stmt->execute([$iduserlogin]); +$school = $stmt->fetch(); +if (!$school) { + die("Errore: Nessuna scuola trovata per l'utente loggato."); +} +$school_id = $school['id']; +$school_name = $school['name']; + +// Recupera tutte le categorie disponibili +$stmt = $pdo->prepare("SELECT id, name FROM class_categories WHERE status = 'active' ORDER BY name"); +$stmt->execute(); +$categories = $stmt->fetchAll(); + +// Recupera tutti gli insegnanti della scuola +$stmt = $pdo->prepare("SELECT id, first_name, last_name FROM teachers WHERE user_id = ? AND status = 'active' ORDER BY first_name, last_name"); +$stmt->execute([$iduserlogin]); +$teachers = $stmt->fetchAll(); + +// Funzione per ridimensionare l'immagine +function resizeImage($source_path, $dest_path, $max_width = 800) +{ + list($width, $height, $type) = getimagesize($source_path); + if ($width <= $max_width) { + copy($source_path, $dest_path); + return; + } + + $new_width = $max_width; + $new_height = (int)(($height * $new_width) / $width); + + switch ($type) { + case IMAGETYPE_JPEG: + $source = imagecreatefromjpeg($source_path); + break; + case IMAGETYPE_PNG: + $source = imagecreatefrompng($source_path); + break; + case IMAGETYPE_GIF: + $source = imagecreatefromgif($source_path); + break; + default: + throw new Exception("Formato immagine non supportato."); + } + + $dest = imagecreatetruecolor($new_width, $new_height); + if ($type == IMAGETYPE_PNG) { + imagealphablending($dest, false); + imagesavealpha($dest, true); + } + imagecopyresampled($dest, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); + + switch ($type) { + case IMAGETYPE_JPEG: + imagejpeg($dest, $dest_path, 90); + break; + case IMAGETYPE_PNG: + imagepng($dest, $dest_path); + break; + case IMAGETYPE_GIF: + imagegif($dest, $dest_path); + break; + } + + imagedestroy($source); + imagedestroy($dest); +} + +// Gestione delle azioni (aggiunta, modifica, cancellazione) +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['action'])) { + $action = $_POST['action']; + + // Aggiunta di una nuova classe + if ($action === 'add') { + $class_category_id = $_POST['class_category_id'] ?? 0; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $requirements = $_POST['requirements'] ?? null; + $level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner'; + $typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null; + $max_capacity = $_POST['max_capacity'] ? (int)$_POST['max_capacity'] : 0; // Nuovo campo + $days_of_week = $_POST['days_of_week'] ?? ''; + $start_time = $_POST['start_time'] ?? ''; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + // Rimossi period_start e period_end dai controlli + if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time)) { + $error = "I campi obbligatori non sono stati compilati."; + } else { + $photo = null; + if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['photo']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "photoclass/{$school_id}-{$timestamp}-{$original_name}"; + $temp_path = $file['tmp_name']; + try { + resizeImage($temp_path, $new_filename); + $photo = $new_filename; + } catch (Exception $e) { + $error = "Errore durante il ridimensionamento della foto: " . $e->getMessage(); + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + if (!isset($error)) { + $stmt = $pdo->prepare(" + INSERT INTO class_types (school_id, class_category_id, name, description, photo, requirements, level, typical_duration, max_capacity, days_of_week, start_time, status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + "); + $success = $stmt->execute([ + $school_id, + $class_category_id, + $name, + $description, + $photo, + $requirements, + $level, + $typical_duration, + $max_capacity, // Nuovo campo + $days_of_week, + $start_time, + $status + ]); + + if ($success) { + $success_message = "Classe aggiunta con successo!"; + } else { + $error = "Errore durante l'aggiunta della classe."; + } + } + } + } + + // Modifica di una classe esistente + if ($action === 'edit') { + $id = $_POST['id'] ?? 0; + $class_category_id = $_POST['class_category_id'] ?? 0; + $name = $_POST['name'] ?? ''; + $description = $_POST['description'] ?? null; + $requirements = $_POST['requirements'] ?? null; + $level = in_array($_POST['level'], ['beginner', 'intermediate', 'advanced']) ? $_POST['level'] : 'beginner'; + $typical_duration = $_POST['typical_duration'] ? (int)$_POST['typical_duration'] : null; + $max_capacity = $_POST['max_capacity'] ? (int)$_POST['max_capacity'] : 0; // Nuovo campo + $days_of_week = $_POST['days_of_week'] ?? ''; + $start_time = $_POST['start_time'] ?? ''; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + // Rimossi period_start e period_end dai controlli + if (empty($name) || $class_category_id <= 0 || empty($days_of_week) || empty($start_time)) { + $error = "I campi obbligatori non sono stati compilati."; + } else { + // Recupera la classe esistente per ottenere il percorso della foto attuale + $stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$id, $school_id]); + $class = $stmt->fetch(); + if (!$class) { + $error = "Classe non trovata."; + } else { + $photo = $class['photo']; + if (isset($_FILES['photo']) && $_FILES['photo']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['photo']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "photoclass/{$school_id}-{$timestamp}-{$original_name}"; + $temp_path = $file['tmp_name']; + try { + resizeImage($temp_path, $new_filename); + $photo = $new_filename; + if ($class['photo'] && file_exists($class['photo'])) { + unlink($class['photo']); + } + } catch (Exception $e) { + $error = "Errore durante il ridimensionamento della foto: " . $e->getMessage(); + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + if (!isset($error)) { + $stmt = $pdo->prepare(" + UPDATE class_types + SET class_category_id = ?, name = ?, description = ?, photo = ?, requirements = ?, level = ?, + typical_duration = ?, max_capacity = ?, days_of_week = ?, start_time = ?, status = ? + WHERE id = ? AND school_id = ? + "); + $success = $stmt->execute([ + $class_category_id, + $name, + $description, + $photo, + $requirements, + $level, + $typical_duration, + $max_capacity, // Nuovo campo + $days_of_week, + $start_time, + $status, + $id, + $school_id + ]); + + if ($success) { + $success_message = "Classe aggiornata con successo!"; + } else { + $error = "Errore durante l'aggiornamento della classe."; + } + } + } + } + } + + // Cancellazione di una classe + if ($action === 'delete') { + $id = $_POST['id'] ?? 0; + $stmt = $pdo->prepare("SELECT photo FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$id, $school_id]); + $class = $stmt->fetch(); + if ($class) { + if ($class['photo'] && file_exists($class['photo'])) { + unlink($class['photo']); + } + $stmt = $pdo->prepare("DELETE FROM class_types WHERE id = ? AND school_id = ?"); + $success = $stmt->execute([$id, $school_id]); + + if ($success) { + $success_message = "Classe eliminata con successo!"; + } else { + $error = "Errore durante l'eliminazione della classe."; + } + } else { + $error = "Classe non trovata."; + } + } + + // Assegnazione di un insegnante + if ($action === 'assign_teacher') { + $class_id = $_POST['class_id'] ?? 0; + $teacher_id = !empty($_POST['teacher_id']) ? (int)$_POST['teacher_id'] : null; + + // Verifica che la classe appartenga alla scuola + $stmt = $pdo->prepare("SELECT id FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$class_id, $school_id]); + if (!$stmt->fetch()) { + $error = "Classe non trovata."; + } else { + // Se teacher_id è null, rimuoviamo l'assegnazione; altrimenti, assegniamo l'insegnante + $stmt = $pdo->prepare("UPDATE class_types SET teacher_id = ? WHERE id = ?"); + $success = $stmt->execute([$teacher_id, $class_id]); + + if ($success) { + $success_message = "Insegnante assegnato con successo!"; + } else { + $error = "Errore durante l'assegnazione dell'insegnante."; + } + } + } + // Propagazione delle sessioni + if ($action === 'propagate_sessions') { + $class_id = $_POST['class_id'] ?? 0; + $start_date = $_POST['start_date'] ?? ''; + $end_date = $_POST['end_date'] ?? ''; + + // Validazione delle date + if (empty($start_date) || empty($end_date)) { + $error = "Le date di inizio e fine sono obbligatorie."; + } elseif (strtotime($end_date) < strtotime($start_date)) { + $error = "La data di fine non può essere precedente alla data di inizio."; + } else { + // Verifica che la classe appartenga alla scuola + $stmt = $pdo->prepare(" + SELECT days_of_week, start_time, typical_duration, teacher_id + FROM class_types + WHERE id = ? AND school_id = ? + "); + $stmt->execute([$class_id, $school_id]); + $class = $stmt->fetch(); + if (!$class) { + $error = "Classe non trovata."; + } else { + // Recupera i giorni di chiusura della scuola + $stmt = $pdo->prepare(" + SELECT start_date, end_date + FROM day_off + WHERE school_id = ? AND ( + (start_date BETWEEN ? AND ?) OR + (end_date BETWEEN ? AND ?) OR + (start_date <= ? AND end_date >= ?) + ) + "); + $stmt->execute([ + $school_id, + $start_date, + $end_date, + $start_date, + $end_date, + $start_date, + $end_date + ]); + $days_off = $stmt->fetchAll(); + + // Crea un array di giorni di chiusura + $off_dates = []; + foreach ($days_off as $day_off) { + $current = new DateTime($day_off['start_date']); + $end = new DateTime($day_off['end_date']); + while ($current <= $end) { + $off_dates[] = $current->format('Y-m-d'); + $current->modify('+1 day'); + } + } + + // Converti i giorni della settimana in un array + $days_of_week = array_map('trim', explode(',', $class['days_of_week'])); + $days_map = [ + 'Lun' => 'Monday', + 'Mar' => 'Tuesday', + 'Mer' => 'Wednesday', + 'Gio' => 'Thursday', + 'Ven' => 'Friday', + 'Sab' => 'Saturday', + 'Dom' => 'Sunday' + ]; + + // Converti i giorni in formato inglese per il confronto + $days_of_week_english = []; + foreach ($days_of_week as $day) { + if (isset($days_map[$day])) { + $days_of_week_english[] = $days_map[$day]; + } + } + + // Calcola l'orario di fine + $start_time = new DateTime($class['start_time']); + $end_time = clone $start_time; + if ($class['typical_duration']) { + $end_time->modify("+{$class['typical_duration']} minutes"); + } else { + $end_time->modify("+60 minutes"); // Default: 1 ora se la durata non è specificata + } + + // Genera un propagation_id univoco + $propagation_id = uniqid('prop_', true); + + // Genera le sessioni + $current_date = new DateTime($start_date); + $end_date_dt = new DateTime($end_date); + $end_date_dt->setTime(23, 59, 59); // Include l'ultimo giorno + + $stmt = $pdo->prepare(" + INSERT INTO class_sessions (class_type_id, session_date, start_time, end_time, teacher_id, status, propagation_id) + VALUES (?, ?, ?, ?, ?, 'scheduled', ?) + "); + + $sessions_created = 0; + while ($current_date <= $end_date_dt) { + $day_of_week = $current_date->format('l'); // Giorno della settimana in inglese (es. Monday) + $current_date_str = $current_date->format('Y-m-d'); + + // Verifica se il giorno è un giorno di chiusura e se è nei giorni della settimana della classe + if (!in_array($current_date_str, $off_dates) && in_array($day_of_week, $days_of_week_english)) { + $session_date = $current_date->format('Y-m-d'); + $start_time_str = $start_time->format('H:i:s'); + $end_time_str = $end_time->format('H:i:s'); + + try { + $stmt->execute([ + $class_id, + $session_date, + $start_time_str, + $end_time_str, + $class['teacher_id'], + $propagation_id + ]); + $sessions_created++; + } catch (PDOException $e) { + // Ignora errori di chiave unica (sessioni già esistenti) + if ($e->getCode() != 23000) { + $error = "Errore durante la propagazione delle sessioni: " . $e->getMessage(); + break; + } + } + } + $current_date->modify('+1 day'); + } + + if (!isset($error)) { + $success_message = "Propagate $sessions_created sessioni con successo! (ID Propagazione: $propagation_id)"; + } + } + } + } + + // Rimozione di una propagazione + if ($action === 'remove_propagation') { + $propagation_id = $_POST['propagation_id'] ?? ''; + $class_id = $_POST['class_id'] ?? 0; + + if (empty($propagation_id) || $class_id <= 0) { + $error = "ID di propagazione o classe non validi."; + } else { + // Verifica che la classe appartenga alla scuola + $stmt = $pdo->prepare("SELECT id FROM class_types WHERE id = ? AND school_id = ?"); + $stmt->execute([$class_id, $school_id]); + if (!$stmt->fetch()) { + $error = "Classe non trovata."; + } else { + // Elimina tutte le sessioni associate a questa propagazione + $stmt = $pdo->prepare(" + DELETE FROM class_sessions + WHERE propagation_id = ? AND class_type_id = ? + "); + $stmt->execute([$propagation_id, $class_id]); + + $deleted_rows = $stmt->rowCount(); + $success_message = "Propagazione rimossa con successo! ($deleted_rows sessioni eliminate)"; + } + } + } + // Reindirizza per evitare il doppio invio del form + header("Location: school_dashboard.php"); + exit; + } +} + +// Recupera tutte le classi della scuola con il nome dell'insegnante +$stmt = $pdo->prepare(" + SELECT ct.*, cc.name AS category_name, t.first_name AS teacher_first_name, t.last_name AS teacher_last_name + FROM class_types ct + LEFT JOIN class_categories cc ON ct.class_category_id = cc.id + LEFT JOIN teachers t ON ct.teacher_id = t.id + WHERE ct.school_id = ? + ORDER BY ct.created_at DESC +"); +$stmt->execute([$school_id]); +$classes = $stmt->fetchAll(); +?> + + + + + + + + + + + + + +
+ + +
+
+ +
+
+
+
+ Logo Scuola +
+
+
+

+ Indirizzo: + +

+

Email:

+

Telefono:

+

Sito Web: + + + + Non specificato + +

+

Descrizione:

+
+ +
+
+
+ + + +
+
+
+
+
Classi della scuola
+
+
+ +
+
+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CategoriaNomeDescrizioneFotoLivelloDurata (min)Posti Massimi GiorniOrarioStatoInsegnanteAzioni
+ + Foto Classe + + Nessuna foto + + + + + + + + + + + + + +
+ + + +
+ + + + + +
+
+
+
+ + + +
+
+ + + + + + + + + + + + + + +
+ + +
+ + + + + + + \ No newline at end of file diff --git a/public/userarea/school_profile.php b/public/userarea/school_profile.php new file mode 100644 index 0000000..8921243 --- /dev/null +++ b/public/userarea/school_profile.php @@ -0,0 +1,332 @@ +getConnection(); + +// ID dell'utente loggato (assumiamo sia definito) +if (!isset($iduserlogin)) { + die("Errore: ID utente non definito."); +} + +// Recupera i dati della scuola associata all'utente +$stmt = $pdo->prepare(" + SELECT s.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN schools s ON s.owner_id = u.id + WHERE u.id = ? +"); +$stmt->execute([$iduserlogin]); +$school = $stmt->fetch(); + +if (!$school) { + die("Errore: Utente non trovato."); +} + +// Determina se è una nuova scuola +$is_new = !isset($school['id']); +if ($is_new) { + $school = [ + 'id' => null, + 'owner_id' => $iduserlogin, + 'name' => '', + 'website' => '', + 'email' => '', + 'phone' => '', + 'description' => '', + 'address_street' => '', + 'address_city' => '', + 'address_postal_code' => '', + 'address_province' => '', + 'address_country' => '', + 'latitude' => '', + 'longitude' => '', + 'owner_name' => '', + 'vat_number' => '', + 'logo' => '', + 'status' => 'active', + 'created_at' => '', + 'updated_at' => '', + 'first_name' => $school['first_name'], + 'last_name' => $school['last_name'], + 'email' => $school['email'] + ]; +} + +// Gestione del form +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $name = $_POST['name'] ?? ''; + $website = $_POST['website'] ?? null; + $email = $_POST['email'] ?? ''; + $phone = $_POST['phone'] ?? null; + $description = $_POST['description'] ?? null; + $address_street = $_POST['address_street'] ?? ''; + $address_city = $_POST['address_city'] ?? ''; + $address_postal_code = $_POST['address_postal_code'] ?? ''; + $address_province = $_POST['address_province'] ?? null; + $address_country = $_POST['address_country'] ?? ''; + $latitude = $_POST['latitude'] ? floatval($_POST['latitude']) : null; + $longitude = $_POST['longitude'] ? floatval($_POST['longitude']) : null; + $owner_name = $_POST['owner_name'] ?? ''; + $vat_number = $_POST['vat_number'] ?? ''; + $status = in_array($_POST['status'], ['active', 'inactive', 'suspended']) ? $_POST['status'] : 'active'; + + // Gestione del caricamento del logo + $logo = $school['logo']; + if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['logo']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "photoschool/{$iduserlogin}-{$timestamp}-{$original_name}"; + if (move_uploaded_file($file['tmp_name'], $new_filename)) { + $logo = $new_filename; + if ($school['logo'] && file_exists($school['logo']) && !$is_new) { + unlink($school['logo']); + } + } else { + $error = "Errore durante il caricamento del logo."; + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + // Aggiorna auth_users (opzionale, se vuoi aggiornare first_name e last_name) + $stmt = $pdo->prepare("UPDATE auth_users SET first_name = ?, last_name = ? WHERE id = ?"); + $stmt->execute([$school['first_name'], $school['last_name'], $iduserlogin]); + + if ($is_new) { + $stmt = $pdo->prepare(" + INSERT INTO schools (owner_id, name, website, email, phone, description, address_street, address_city, address_postal_code, address_province, address_country, latitude, longitude, owner_name, vat_number, logo, status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + "); + $success = $stmt->execute([ + $iduserlogin, + $name, + $website, + $email, + $phone, + $description, + $address_street, + $address_city, + $address_postal_code, + $address_province, + $address_country, + $latitude, + $longitude, + $owner_name, + $vat_number, + $logo, + $status + ]); + + if ($success) { + $success_message = "Scuola creata con successo!"; + $stmt = $pdo->prepare(" + SELECT s.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN schools s ON s.owner_id = u.id + WHERE u.id = ? + "); + $stmt->execute([$iduserlogin]); + $school = $stmt->fetch(); + $is_new = false; + } else { + $error = "Errore durante la creazione della scuola."; + } + } else { + $stmt = $pdo->prepare(" + UPDATE schools + SET name = ?, website = ?, email = ?, phone = ?, description = ?, address_street = ?, address_city = ?, + address_postal_code = ?, address_province = ?, address_country = ?, latitude = ?, longitude = ?, + owner_name = ?, vat_number = ?, logo = ?, status = ? + WHERE owner_id = ? + "); + $success = $stmt->execute([ + $name, + $website, + $email, + $phone, + $description, + $address_street, + $address_city, + $address_postal_code, + $address_province, + $address_country, + $latitude, + $longitude, + $owner_name, + $vat_number, + $logo, + $status, + $iduserlogin + ]); + + if ($success) { + $success_message = "Dati aggiornati con successo!"; + $stmt = $pdo->prepare(" + SELECT s.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN schools s ON s.owner_id = u.id + WHERE u.id = ? + "); + $stmt->execute([$iduserlogin]); + $school = $stmt->fetch(); + } else { + $error = "Errore durante l'aggiornamento dei dati."; + } + } +} +?> + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+ + + + + + +
+
+
+
+ Logo Scuola +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+ + +
+ + +
+
+
+
+
+
+
+
+ + +
+ + + + \ No newline at end of file diff --git a/public/userarea/siteinfo.php b/public/userarea/siteinfo.php new file mode 100644 index 0000000..7b710c2 --- /dev/null +++ b/public/userarea/siteinfo.php @@ -0,0 +1,2 @@ +YogiBoook - School Management + \ No newline at end of file diff --git a/public/userarea/teacher_profile.php b/public/userarea/teacher_profile.php new file mode 100644 index 0000000..f376593 --- /dev/null +++ b/public/userarea/teacher_profile.php @@ -0,0 +1,327 @@ +getConnection(); + +// ID dell'utente loggato (assumiamo sia definito) +if (!isset($iduserlogin)) { + die("Errore: ID utente non definito."); +} + +// Recupera i dati dell'insegnante +$stmt = $pdo->prepare(" + SELECT t.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN teachers t ON t.user_id = u.id + WHERE u.id = ? +"); +$stmt->execute([$iduserlogin]); +$teacher = $stmt->fetch(); + +if (!$teacher) { + die("Errore: Utente non trovato."); +} + +// Determina se è un nuovo insegnante +$is_new = !isset($teacher['id']); +if ($is_new) { + $teacher = [ + 'id' => null, + 'user_id' => $iduserlogin, + 'unique_code' => '', + 'phone' => '', + 'description' => '', + 'specializations' => '', + 'profile_picture' => '', + 'status' => 'active', + 'created_at' => '', + 'updated_at' => '', + 'first_name' => $teacher['first_name'], + 'last_name' => $teacher['last_name'], + 'email' => $teacher['email'] + ]; +} + +// Funzione per generare un codice univoco +function generateUniqueCode($pdo, $length = 16) +{ + do { + $code = bin2hex(random_bytes($length / 2)); + $stmt = $pdo->prepare("SELECT COUNT(*) FROM teachers WHERE unique_code = ?"); + $stmt->execute([$code]); + $count = $stmt->fetchColumn(); + } while ($count > 0); + return $code; +} + +// Generazione del QR Code +$qr_code_path = null; +if (!$is_new) { + try { + $unique_code = $teacher['unique_code']; + if (empty($unique_code)) { + throw new Exception("Errore: unique_code è vuoto."); + } + + $base_dir = __DIR__ . '/../../public/userarea/phototeachers/qrcodes/'; + $qr_code_filename = "{$base_dir}{$iduserlogin}-{$unique_code}.png"; + $qr_code_path = "phototeachers/qrcodes/{$iduserlogin}-{$unique_code}.png"; + + if (!file_exists($qr_code_filename)) { + if (!is_dir($base_dir)) { + mkdir($base_dir, 0755, true) or die("Errore: Impossibile creare la directory."); + } + if (!is_writable($base_dir)) { + die("Errore: La directory non è scrivibile."); + } + + $builder = new Builder(); + $result = $builder->build( + writer: new PngWriter(), + data: $unique_code, + size: 150, + margin: 10 + ); + $result->saveToFile($qr_code_filename); + } + } catch (Exception $e) { + $error = "Errore generazione QR Code: " . $e->getMessage(); + error_log($error); + } +} + +// Gestione del form +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $first_name = $_POST['first_name']; + $last_name = $_POST['last_name']; + $phone = $_POST['phone'] ?? null; + $description = $_POST['description'] ?? null; + $specializations = $_POST['specializations'] ?? null; + $status = $_POST['status'] === 'active' ? 'active' : 'inactive'; + + // Gestione del caricamento della foto + $profile_picture = $teacher['profile_picture']; + if (isset($_FILES['profile_picture']) && $_FILES['profile_picture']['error'] === UPLOAD_ERR_OK) { + $file = $_FILES['profile_picture']; + $timestamp = time(); + $original_name = basename($file['name']); + $extension = strtolower(pathinfo($original_name, PATHINFO_EXTENSION)); + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif']; + + if (in_array($extension, $allowed_extensions)) { + $new_filename = "phototeachers/{$iduserlogin}-{$timestamp}-{$original_name}"; + if (move_uploaded_file($file['tmp_name'], $new_filename)) { + $profile_picture = $new_filename; + if ($teacher['profile_picture'] && file_exists($teacher['profile_picture']) && !$is_new) { + unlink($teacher['profile_picture']); + } + } else { + $error = "Errore durante il caricamento della foto."; + } + } else { + $error = "Estensione del file non consentita. Usa JPG, JPEG, PNG o GIF."; + } + } + + // Aggiorna auth_users + $stmt = $pdo->prepare("UPDATE auth_users SET first_name = ?, last_name = ? WHERE id = ?"); + $stmt->execute([$first_name, $last_name, $iduserlogin]); + + if ($is_new) { + $unique_code = generateUniqueCode($pdo); + $stmt = $pdo->prepare(" + INSERT INTO teachers (user_id, unique_code, phone, description, specializations, profile_picture, status) + VALUES (?, ?, ?, ?, ?, ?, ?) + "); + $success = $stmt->execute([$iduserlogin, $unique_code, $phone, $description, $specializations, $profile_picture, $status]); + + if ($success) { + $success_message = "Insegnante creato con successo!"; + $stmt = $pdo->prepare(" + SELECT t.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN teachers t ON t.user_id = u.id + WHERE u.id = ? + "); + $stmt->execute([$iduserlogin]); + $teacher = $stmt->fetch(); + $is_new = false; + + // Genera QR Code per il nuovo insegnante + try { + $base_dir = __DIR__ . '/../../public/phototeachers/qrcodes/'; + $qr_code_filename = "{$base_dir}{$iduserlogin}-{$unique_code}.png"; + $qr_code_path = "phototeachers/qrcodes/{$iduserlogin}-{$unique_code}.png"; + + if (!file_exists($qr_code_filename)) { + if (!is_dir($base_dir)) { + mkdir($base_dir, 0755, true) or die("Errore: Impossibile creare la directory."); + } + $builder = new Builder(); + $result = $builder->build( + writer: new PngWriter(), + data: $unique_code, + size: 150, + margin: 10 + ); + $result->saveToFile($qr_code_filename); + } + } catch (Exception $e) { + $error = "Errore generazione QR Code: " . $e->getMessage(); + error_log($error); + } + } else { + $error = "Errore durante la creazione dell'insegnante."; + } + } else { + $stmt = $pdo->prepare(" + UPDATE teachers + SET phone = ?, description = ?, specializations = ?, profile_picture = ?, status = ? + WHERE user_id = ? + "); + $success = $stmt->execute([$phone, $description, $specializations, $profile_picture, $status, $iduserlogin]); + + if ($success) { + $success_message = "Dati aggiornati con successo!"; + $stmt = $pdo->prepare(" + SELECT t.*, u.first_name, u.last_name, u.email + FROM auth_users u + LEFT JOIN teachers t ON t.user_id = u.id + WHERE u.id = ? + "); + $stmt->execute([$iduserlogin]); + $teacher = $stmt->fetch(); + } else { + $error = "Errore durante l'aggiornamento dei dati."; + } + } +} +?> + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+ + + + + + +
+
+
+
+ Foto Profilo +
+
+ + +
+ +
+ + +
+
+
+ QR Code +
+ +
+
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ > + +
+
+ +
+ + +
+
+ + +
+ + +
+
+
+
+
+
+
+
+ + +
+ + + + \ No newline at end of file diff --git a/public/userarea/template.php b/public/userarea/template.php index ba9ecb2..bd45ed2 100644 --- a/public/userarea/template.php +++ b/public/userarea/template.php @@ -1,3 +1,4 @@ + @@ -8,7 +9,8 @@ - Rocker - Bootstrap 5 Admin Dashboard Template + + @@ -23,68 +25,7 @@
-
-
-
-
-
-
-

Total Orders

-

4805

-

+2.5% from last week

-
-
-
-
-
-
-
-
-
-
-
-
-

Total Revenue

-

$84,245

-

+5.4% from last week

-
-
-
-
-
-
-
-
-
-
-
-
-

Bounce Rate

-

34.6%

-

-4.5% from last week

-
-
-
-
-
-
-
-
-
-
-
-
-

Total Customers

-

8.4K

-

+8.4% from last week

-
-
-
-
-
-
-
-
+ diff --git a/public/userarea/test-qr.png b/public/userarea/test-qr.png new file mode 100644 index 0000000..e40647a Binary files /dev/null and b/public/userarea/test-qr.png differ diff --git a/storage/settings.json b/storage/settings.json index 80782f3..d69476a 100644 --- a/storage/settings.json +++ b/storage/settings.json @@ -1 +1 @@ -{"remember_me":"1","notifications_signup_email":"0","forgot_password":"1","login_reset_token_lifetime":"30","throttle_enabled":"1","throttle_attempts":"3","throttle_lockout_time":"2","reg_enabled":"1","reg_email_confirmation":"1","2fa":{"enabled":true},"app_name":"YogiBoook","registration":{"captcha":{"enabled":false}},"tos":"1","captcha":{"enabled":false},"max_active_sessions":"0"} \ No newline at end of file +{"remember_me":"1","notifications_signup_email":"1","forgot_password":"1","login_reset_token_lifetime":"30","throttle_enabled":"1","throttle_attempts":"3","throttle_lockout_time":"2","reg_enabled":"1","reg_email_confirmation":"1","2fa":{"enabled":true},"app_name":"YogiBoook","registration":{"captcha":{"enabled":false}},"tos":"1","captcha":{"enabled":false},"max_active_sessions":"0"} \ No newline at end of file