Compare commits

...
3 Commits
Author SHA1 Message Date
sld-admin bb2602e0d2 Fixed adding new note 2026-08-25 16:42:26 +01:00
sld-admin ee6c739305 Added the email for the owner and changed the admin123 for the login page 2026-08-20 09:42:02 +01:00
sld-admin 1ea31362c4 Fixed First Start 2026-08-20 09:02:05 +01:00
9 changed files with 150 additions and 37 deletions
+11 -3
View File
@@ -4,7 +4,9 @@ mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
// Check if first_start.php installer file exists and database setup is needed
$first_start_path = ROOT_DIR . "first_start.php";
if (file_exists($first_start_path) && basename($_SERVER['SCRIPT_FILENAME'] ?? '') !== 'first_start.php') {
$first_start_completed = file_exists(ROOT_DIR . "first_start.php.completed") || file_exists(ROOT_DIR . "config/installed.lock");
if (file_exists($first_start_path) && !$first_start_completed && basename($_SERVER['SCRIPT_FILENAME'] ?? '') !== 'first_start.php') {
// Check connection first
try {
$test_conn = @new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
@@ -72,6 +74,7 @@ try {
// Seed default site settings if empty
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('site_title', 'sld-blocknotes')");
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('site_favicon', 'assets/img/favicon.png')");
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('admin_email', '[email protected]')");
// Seed default owner account if table is empty or ensure admin user is owner if no owner exists
$res = $conn->query("SELECT COUNT(*) AS total FROM users");
@@ -93,11 +96,16 @@ try {
}
} catch (mysqli_sql_exception $e) {
if (file_exists($first_start_path) && basename($_SERVER['SCRIPT_FILENAME'] ?? '') !== 'first_start.php') {
if (file_exists($first_start_path) && !$first_start_completed && basename($_SERVER['SCRIPT_FILENAME'] ?? '') !== 'first_start.php') {
header("Location: first_start.php");
exit;
}
include(PAGES_FOLD . "db-error.php");
$pages_fold = defined('PAGES_FOLD') ? PAGES_FOLD : ROOT_DIR . "pages/";
if (file_exists($pages_fold . "db-error.php")) {
include($pages_fold . "db-error.php");
} else {
echo "Database connection error: " . htmlspecialchars($e->getMessage());
}
debugStatusMes("Database setup error: " . $e->getMessage(), "High");
die();
}
+12 -4
View File
@@ -5,14 +5,22 @@
switch($env){
/*------ DON'T TOUCH THIS PART ------ */
case "generic":
$doc_root = !empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : dirname(__DIR__);
define('WEB_ROOT', $doc_root);
$app_dir = str_replace('\\', '/', dirname(__DIR__));
$doc_root = !empty($_SERVER['DOCUMENT_ROOT']) ? str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']) : '';
$base_url_path = '';
if (!empty($doc_root) && strpos($app_dir, $doc_root) === 0) {
$base_url_path = substr($app_dir, strlen($doc_root));
}
$base_url_path = rtrim(str_replace('\\', '/', $base_url_path), '/');
$host = !empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
define('DOMAIN', $host);
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://';
define('FULL_DOMAIN', $protocol . DOMAIN);
define("ROOT_URL", $protocol . DOMAIN );
define("ROOT_DIR", rtrim(WEB_ROOT, '/') . "/");
define("ROOT_URL", $protocol . DOMAIN . $base_url_path);
define("ROOT_DIR", $app_dir . "/");
define('WEB_ROOT', ROOT_DIR);
break;
/* ----------------------------------- */
default:
Regular → Executable
+24 -8
View File
@@ -11,6 +11,17 @@ if (session_status() === PHP_SESSION_NONE) {
define("ROOT_DIR", __DIR__ . "/");
require_once(__DIR__ . "/functions/lang.php");
// Check if installation is already completed or lock file exists
$installed_lock = __DIR__ . "/config/installed.lock";
$completed_file = __DIR__ . "/first_start.php.completed";
if (file_exists($completed_file) || file_exists($installed_lock)) {
header("Location: index.php?page=login");
exit;
}
// Handle language selection
if (isset($_GET['set_lang'])) {
set_active_lang($_GET['set_lang']);
@@ -22,7 +33,7 @@ $current_lang = get_current_lang();
$msg_error = "";
$msg_success = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') {
$db_host = trim($_POST['db_host'] ?? 'localhost');
$db_name = trim($_POST['db_name'] ?? 'sld_blocknotes_db');
$db_user = trim($_POST['db_user'] ?? '');
@@ -81,6 +92,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Insert site_settings default values
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('site_title', 'sld-blocknotes')");
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('site_favicon', 'assets/img/favicon.png')");
$conn->query("INSERT IGNORE INTO site_settings (setting_key, setting_value) VALUES ('admin_email', '[email protected]')");
// Create Owner account
$hash_owner = password_hash($owner_pass, PASSWORD_DEFAULT);
@@ -142,14 +154,18 @@ if ($db_needed == "yes"){
require_once(CONFIG_FOLD . "db.php");
}
?>';
file_put_contents(__DIR__ . "/config/settings.php", $settings_file_content);
if (@file_put_contents(__DIR__ . "/config/settings.php", $settings_file_content) === false) {
$msg_error = __('err_setup_write_permissions');
} else {
// Rename first_start.php to first_start.php.completed to prevent installer re-entry
if (!@rename(__FILE__, __DIR__ . "/first_start.php.completed")) {
@file_put_contents(__DIR__ . "/config/installed.lock", date('Y-m-d H:i:s'));
}
// Rename first_start.php to first_start.php.completed to prevent installer re-entry
@rename(__FILE__, __DIR__ . "/first_start.php.completed");
// Redirect to login page
header("Location: index.php?page=login&installed=1");
exit;
// Redirect to login page
header("Location: index.php?page=login&installed=1");
exit;
}
}
}
}
+28
View File
@@ -419,3 +419,31 @@ function delete_subnote($blocknote_id, $note_id, $sub_id, $username, $is_admin)
}
return ['success' => false, 'message' => 'Errore nel salvataggio.'];
}
/**
* Compatibility Aliases
*/
function add_note_to_blocknote($blocknote_id, $title, $description, $username, $is_admin) {
return add_note($blocknote_id, $title, $description, $username, $is_admin);
}
function edit_note_in_blocknote($blocknote_id, $note_id, $title, $description, $username, $is_admin) {
return edit_note($blocknote_id, $note_id, $title, $description, $username, $is_admin);
}
function delete_note_from_blocknote($blocknote_id, $note_id, $username, $is_admin) {
return delete_note($blocknote_id, $note_id, $username, $is_admin);
}
function add_subnote_to_note($blocknote_id, $note_id, $sub_title, $type, $content, $username, $is_admin) {
return add_subnote($blocknote_id, $note_id, $sub_title, $type, $content, $username, $is_admin);
}
function edit_subnote_in_note($blocknote_id, $note_id, $sub_id, $sub_title, $type, $content, $username, $is_admin) {
return edit_subnote($blocknote_id, $note_id, $sub_id, $sub_title, $type, $content, $username, $is_admin);
}
function delete_subnote_from_note($blocknote_id, $note_id, $sub_id, $username, $is_admin) {
return delete_subnote($blocknote_id, $note_id, $sub_id, $username, $is_admin);
}
+36 -11
View File
@@ -53,7 +53,8 @@ function get_translations() {
'placeholder_username' => 'Inserisci username',
'placeholder_password' => 'Inserisci password',
'btn_submit_login' => '🔑 Accedi',
'login_hint_footer' => 'Accredito predefinito per il primo accesso',
'login_hint_footer' => 'Richiedi un account all\'amministratore',
'login_request_account' => 'Se hai bisogno di un account, richiedilo all\'amministratore di sistema:',
'login_installed_success' => '🎉 Setup completato! Accedi con le credenziali create.',
// Navbar
@@ -152,6 +153,14 @@ function get_translations() {
'btn_reset_pass' => '🔑 Reset Pass',
'modal_create_user' => ' Registra Nuovo Utente',
'modal_reset_pass' => '🔑 Reset Password Utente',
'card_site_settings_title' => '⚙️ Impostazioni Sito (Esclusivo Owner)',
'label_site_title' => 'Titolo Globale Applicazione / Sito',
'label_favicon' => 'Favicon del Sito (Alta Risoluzione, min 64x64px)',
'btn_save_site_title' => '💾 Salva Titolo Sito',
'btn_upload_favicon' => '📤 Carica Nuova Favicon',
'label_admin_email' => 'Email Amministratore di Sistema',
'btn_save_admin_email' => '💾 Salva Email Admin',
'placeholder_admin_email' => 'es. [email protected]',
// Confirm Dialogs
'confirm_delete_blocknote' => 'Sei sicuro di voler eliminare questo blocknote e tutte le sue note?',
'confirm_delete_note' => 'Sei sicuro di voler eliminare questa nota e tutte le sue sottonote?',
@@ -200,7 +209,8 @@ function get_translations() {
'err_setup_db_fields' => 'Compila tutti i dati di connessione al Database MySQL.',
'err_setup_owner_fields' => 'Inserisci username e password per l\'utente Owner (Proprietario).',
'err_setup_admin_fields' => 'Inserisci username e password per il primo utente Admin.',
'err_setup_same_user' => 'L\'utente Owner e l\'utente Admin devono avere nomi utente differenti.'
'err_setup_same_user' => 'L\'utente Owner e l\'utente Admin devono avere nomi utente differenti.',
'err_setup_write_permissions' => 'Impossibile scrivere il file config/settings.php. Verifica i permessi di scrittura sulla cartella.'
],
'en' => [
@@ -316,6 +326,10 @@ function get_translations() {
'label_favicon' => 'Site Favicon (High Resolution, min 64x64px)',
'btn_save_site_title' => '💾 Save Site Title',
'btn_upload_favicon' => '📤 Upload New Favicon',
'label_admin_email' => 'System Administrator Email',
'btn_save_admin_email' => '💾 Save Admin Email',
'placeholder_admin_email' => 'e.g. [email protected]',
'login_request_account' => 'If you need an account, please contact the system administrator:',
// Confirm Dialogs
'confirm_delete_blocknote' => 'Are you sure you want to delete this blocknote and all its notes?',
@@ -365,7 +379,8 @@ function get_translations() {
'err_setup_db_fields' => 'Please fill in all MySQL database connection fields.',
'err_setup_owner_fields' => 'Please enter username and password for the Owner user.',
'err_setup_admin_fields' => 'Please enter username and password for the first Admin user.',
'err_setup_same_user' => 'Owner user and Admin user must have different usernames.'
'err_setup_same_user' => 'Owner user and Admin user must have different usernames.',
'err_setup_write_permissions' => 'Unable to write to config/settings.php file. Check folder write permissions.'
],
'es' => [
@@ -477,10 +492,14 @@ function get_translations() {
'modal_create_user' => ' Registrar Nuevo Usuario',
'modal_reset_pass' => '🔑 Resetear Contraseña',
'card_site_settings_title' => '⚙️ Ajustes del Sitio (Solo Propietario)',
'label_site_title' => 'Título del Sitio / Aplicación',
'label_favicon' => 'Favicon del Sitio (Alta resolución, mín 64x64px)',
'label_site_title' => 'Título Global de la Aplicación / Sitio',
'label_favicon' => 'Favicon del Sitio (Alta Resolución, min 64x64px)',
'btn_save_site_title' => '💾 Guardar Título',
'btn_upload_favicon' => '📤 Subir Nueva Favicon',
'btn_upload_favicon' => '📤 Subir Favicon',
'label_admin_email' => 'Correo del Administrador del Sistema',
'btn_save_admin_email' => '💾 Guardar Correo Admin',
'placeholder_admin_email' => 'ej. [email protected]',
'login_request_account' => 'Si necesitas una cuenta, contacta al administrador del sistema:',
// Confirm Dialogs
'confirm_delete_blocknote' => '¿Estás seguro de que quieres eliminar este blocknote y todas sus notas?',
@@ -530,7 +549,8 @@ function get_translations() {
'err_setup_db_fields' => 'Por favor completa todos los campos de conexión a la base de datos MySQL.',
'err_setup_owner_fields' => 'Por favor introduce nombre de usuario y contraseña para el Propietario.',
'err_setup_admin_fields' => 'Por favor introduce nombre de usuario y contraseña para el primer Admin.',
'err_setup_same_user' => 'El usuario Propietario y el usuario Admin deben tener nombres diferentes.'
'err_setup_same_user' => 'El usuario Propietario y el usuario Admin deben tener nombres diferentes.',
'err_setup_write_permissions' => 'No se pudo escribir en el archivo config/settings.php. Verifica los permisos de escritura.'
],
'fr' => [
@@ -642,10 +662,14 @@ function get_translations() {
'modal_create_user' => ' Enregistrer un Utilisateur',
'modal_reset_pass' => '🔑 Réinitialiser le Mot de Passe',
'card_site_settings_title' => '⚙️ Paramètres du Site (Propriétaire Uniquement)',
'label_site_title' => 'Titre Global du Site',
'label_favicon' => 'Favicon du Site (Haute résolution, min 64x64px)',
'label_site_title' => 'Titre Global del Application / Site',
'label_favicon' => 'Favicon du Site (Haute Résolution, min 64x64px)',
'btn_save_site_title' => '💾 Enregistrer le Titre',
'btn_upload_favicon' => '📤 Téléverser la Favicon',
'btn_upload_favicon' => '📤 Téléverser le Favicon',
'label_admin_email' => 'E-mail de l\'Administrateur Système',
'btn_save_admin_email' => '💾 Enregistrer l\'E-mail Admin',
'placeholder_admin_email' => 'ex. [email protected]',
'login_request_account' => 'Si vous avez besoin d\'un compte, contactez l\'administrateur système:',
// Confirm Dialogs
'confirm_delete_blocknote' => 'Êtes-vous sûr de vouloir supprimer ce blocknote et toutes ses notes?',
@@ -695,7 +719,8 @@ function get_translations() {
'err_setup_db_fields' => 'Veuillez remplir tous les champs de connexion à la base de données MySQL.',
'err_setup_owner_fields' => 'Veuillez entrer le nom d\'utilisateur et le mot de passe pour le Propriétaire.',
'err_setup_admin_fields' => 'Veuillez entrer le nom d\'utilisateur et le mot de passe pour le premier Admin.',
'err_setup_same_user' => 'L\'utilisateur Propriétaire et l\'utilisateur Admin doivent avoir des noms différents.'
'err_setup_same_user' => 'L\'utilisateur Propriétaire et l\'utilisateur Admin doivent avoir des noms différents.',
'err_setup_write_permissions' => 'Impossible d\'écrire dans le fichier config/settings.php. Vérifiez les permissions de dossier.'
]
];
}
+3 -1
View File
@@ -1,3 +1,5 @@
<script>
yearNow("year");
if (typeof yearNow === 'function') {
yearNow("year");
}
</script>
+21
View File
@@ -30,6 +30,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
} elseif ($action === 'upload_favicon' && is_owner()) {
$res = upload_site_favicon($_FILES['favicon_file'] ?? null);
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'update_admin_email' && is_owner()) {
$new_email = trim($_POST['admin_email'] ?? '');
if (!empty($new_email) && filter_var($new_email, FILTER_VALIDATE_EMAIL)) {
update_site_setting('admin_email', $new_email);
$msg_success = "Email dell'amministratore di sistema aggiornata con successo!";
} else {
$msg_error = "Inserisci un indirizzo email valido per l'amministratore di sistema.";
}
}
}
@@ -48,6 +56,7 @@ foreach ($all_blocknotes as $bn) {
$site_title = get_site_setting('site_title', 'sld-blocknotes');
$site_favicon = get_site_setting('site_favicon', 'assets/img/favicon.png');
$admin_email = get_site_setting('admin_email', '[email protected]');
?>
<main class="main-content">
@@ -96,6 +105,18 @@ $site_favicon = get_site_setting('site_favicon', 'assets/img/favicon.png');
</button>
</form>
<!-- Modifica Email Amministratore -->
<form action="index.php?page=admin_users" method="POST">
<input type="hidden" name="action" value="update_admin_email">
<div class="form-group">
<label for="admin_email"><?= __('label_admin_email') ?></label>
<input type="email" name="admin_email" id="admin_email" class="form-control" value="<?= htmlspecialchars($admin_email) ?>" required placeholder="<?= htmlspecialchars(__('placeholder_admin_email')) ?>">
</div>
<button type="submit" class="btn btn-primary" style="margin-top: 0.5rem;">
<?= __('btn_save_admin_email') ?>
</button>
</form>
<!-- Caricamento Favicon -->
<form action="index.php?page=admin_users" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="upload_favicon">
+9 -4
View File
@@ -62,10 +62,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</button>
</form>
<div style="margin-top: 1.5rem; text-align: center; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.82rem; color: #64748b;">
<?= __('login_hint_footer') ?>:<br>
<strong style="color: #94a3b8;"><?= __('label_username') ?>:</strong> admin | <strong style="color: #94a3b8;"><?= __('label_password') ?>:</strong> admin123
</div>
<?php $admin_email = get_site_setting('admin_email', '[email protected]'); ?>
<?php if (!empty($admin_email)): ?>
<div style="margin-top: 1.5rem; text-align: center; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.08); font-size: 0.85rem; color: #94a3b8;">
<?= __('login_request_account') ?><br>
<a href="mailto:<?= htmlspecialchars($admin_email) ?>" style="color: #7dd3fc; font-weight: 600; text-decoration: underline; margin-top: 0.35rem; display: inline-block;">
✉️ <?= htmlspecialchars($admin_email) ?>
</a>
</div>
<?php endif; ?>
</div>
</div>
</main>
+6 -6
View File
@@ -19,22 +19,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'add_note') {
$res = add_note_to_blocknote($blocknote_id, $_POST['title'] ?? '', $_POST['description'] ?? '', $user['username'], is_admin());
$res = add_note($blocknote_id, $_POST['title'] ?? '', $_POST['description'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'edit_note') {
$res = edit_note_in_blocknote($blocknote_id, $_POST['note_id'] ?? '', $_POST['title'] ?? '', $_POST['description'] ?? '', $user['username'], is_admin());
$res = edit_note($blocknote_id, $_POST['note_id'] ?? '', $_POST['title'] ?? '', $_POST['description'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'delete_note') {
$res = delete_note_from_blocknote($blocknote_id, $_POST['note_id'] ?? '', $user['username'], is_admin());
$res = delete_note($blocknote_id, $_POST['note_id'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'add_subnote') {
$res = add_subnote_to_note($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_title'] ?? '', $_POST['type'] ?? 'text', $_POST['content'] ?? '', $user['username'], is_admin());
$res = add_subnote($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_title'] ?? '', $_POST['type'] ?? 'text', $_POST['content'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'edit_subnote') {
$res = edit_subnote_in_note($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_id'] ?? '', $_POST['sub_title'] ?? '', $_POST['type'] ?? 'text', $_POST['content'] ?? '', $user['username'], is_admin());
$res = edit_subnote($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_id'] ?? '', $_POST['sub_title'] ?? '', $_POST['type'] ?? 'text', $_POST['content'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
} elseif ($action === 'delete_subnote') {
$res = delete_subnote_from_note($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_id'] ?? '', $user['username'], is_admin());
$res = delete_subnote($blocknote_id, $_POST['note_id'] ?? '', $_POST['sub_id'] ?? '', $user['username'], is_admin());
if ($res['success']) $msg_success = $res['message']; else $msg_error = $res['message'];
}