Parcourir la source

Fix missing links

svalavuo il y a 6 jours
Parent
commit
c241ea60dc
8 fichiers modifiés avec 100 ajouts et 14 suppressions
  1. 5 0
      admin/categories.php
  2. 6 0
      admin/index.php
  3. 5 0
      admin/publications.php
  4. 6 4
      admin/users.php
  5. 32 0
      includes/config.php
  6. 4 7
      includes/translation.php
  7. 3 3
      public/index.php
  8. 39 0
      test_language.php

+ 5 - 0
admin/categories.php

@@ -1,4 +1,9 @@
 <?php
+// Start session for language preference
+if (session_status() === PHP_SESSION_NONE) {
+    session_start();
+}
+
 require_once '../includes/config.php';
 require_once '../includes/database.php';
 require_once '../includes/auth.php';

+ 6 - 0
admin/index.php

@@ -1,4 +1,9 @@
 <?php
+// Start session for language preference
+if (session_status() === PHP_SESSION_NONE) {
+    session_start();
+}
+
 require_once '../includes/config.php';
 require_once '../includes/database.php';
 require_once '../includes/auth.php';
@@ -56,6 +61,7 @@ $recentPublications = $publication->getAll('all', 10);
                     <a href="index.php" class="nav-link active"><?php echo t('admin_nav_dashboard'); ?></a>
                     <a href="publications.php" class="nav-link"><?php echo t('admin_nav_publications'); ?></a>
                     <a href="categories.php" class="nav-link"><?php echo t('admin_nav_categories'); ?></a>
+                    <a href="users.php" class="nav-link"><?php echo t('admin_nav_users'); ?></a>
                     <?php if (LDAP_ENABLED): ?>
                         <a href="ldap-users.php" class="nav-link"><?php echo t('admin_nav_ldap_users'); ?></a>
                     <?php endif; ?>

+ 5 - 0
admin/publications.php

@@ -1,4 +1,9 @@
 <?php
+// Start session for language preference
+if (session_status() === PHP_SESSION_NONE) {
+    session_start();
+}
+
 require_once '../includes/config.php';
 require_once '../includes/database.php';
 require_once '../includes/auth.php';

+ 6 - 4
admin/users.php

@@ -1,12 +1,14 @@
 <?php
+// Start session for language preference
+if (session_status() === PHP_SESSION_NONE) {
+    session_start();
+}
+
 require_once '../includes/config.php';
 require_once '../includes/database.php';
 require_once '../includes/auth.php';
 require_once '../includes/translation.php';
 
-// Start session for language preference
-session_start();
-
 // Initialize translation system
 try {
     $translation = Translation::getInstance();
@@ -217,7 +219,7 @@ switch ($action) {
             <h1><a href="index.php"><?php echo SITE_TITLE; ?></a></h1>
             <nav class="admin-nav">
                 <a href="index.php"><?php echo t('nav_dashboard'); ?></a>
-                <a href="edit.php"><?php echo t('manage_publications'); ?></a>
+                <a href="edit.php"><?php echo t('create_publication'); ?></a>
                 <a href="publications.php"><?php echo t('manage_publications'); ?></a>
                 <a href="categories.php"><?php echo t('manage_categories'); ?></a>
                 <a href="users.php" class="active"><?php echo t('manage_users'); ?></a>

+ 32 - 0
includes/config.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * Site Configuration
+ */
+
+// Database settings
+define('DB_HOST', 'localhost');
+define('DB_NAME', 'website');
+define('DB_USER', 'root');
+define('DB_PASS', '');
+
+// Site settings
+define('SITE_TITLE', 'Publication System');
+define('DEFAULT_LANGUAGE', 'en');
+
+// LDAP settings
+define('LDAP_ENABLED', false);
+define('LDAP_HOST', 'localhost');
+define('LDAP_PORT', 389);
+define('LDAP_BASE_DN', 'dc=example,dc=com');
+define('LDAP_BIND_DN', 'cn=admin,dc=example,dc=com');
+define('LDAP_BIND_PASS', '');
+define('LDAP_USER_FILTER', '(objectClass=person)');
+
+// Security settings
+define('SESSION_LIFETIME', 3600); // 1 hour
+define('PASSWORD_MIN_LENGTH', 8);
+
+// Error reporting
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+?>

+ 4 - 7
includes/translation.php

@@ -34,20 +34,17 @@ class Translation {
         if (isset($_GET['lang']) && isset($this->supportedLanguages[$_GET['lang']])) {
             $this->currentLanguage = $_GET['lang'];
             $_SESSION['language'] = $this->currentLanguage;
-            return;
-        }
-        
-        // Redirect to same page without language parameter to apply new language
-        if (isset($_GET['lang']) && isset($this->supportedLanguages[$_GET['lang']])) {
-            // Remove language parameter from URL to prevent infinite redirect loops
+            
+            // Redirect to same page without language parameter to apply new language
             $currentUrl = $_SERVER['REQUEST_URI'];
             $urlWithoutLang = strtok($currentUrl, '?')[0];
             
             // Redirect to same page without language parameter
             if ($urlWithoutLang !== false) {
-                header('Location: ' . $urlWithoutLang . '?lang=' . $_GET['lang']);
+                header('Location: ' . $urlWithoutLang);
                 exit;
             }
+            return;
         }
         
         // Check browser language preference

+ 3 - 3
public/index.php

@@ -1,12 +1,12 @@
 <?php
+// Start session for language preference
+session_start();
+
 require_once '../includes/config.php';
 require_once '../includes/database.php';
 require_once '../includes/publication.php';
 require_once '../includes/translation.php';
 
-// Start session for language preference
-session_start();
-
 // Initialize translation system
 $translation = Translation::getInstance();
 

+ 39 - 0
test_language.php

@@ -0,0 +1,39 @@
+<?php
+// Start session
+session_start();
+
+require_once 'includes/config.php';
+require_once 'includes/translation.php';
+
+// Simulate different scenarios
+echo "=== Testing Language Switching ===\n\n";
+
+// Test 1: Default language (no session, no GET param)
+$_SESSION = array(); // Clear session
+$_GET = array(); // Clear GET params
+
+$translation = Translation::getInstance();
+echo "Test 1 - Default: " . $translation->getCurrentLanguage() . "\n";
+echo "Session language: " . ($_SESSION['language'] ?? 'not set') . "\n\n";
+
+// Test 2: Language parameter in URL
+$_GET['lang'] = 'fi';
+$translation = Translation::getInstance(); // Fresh instance
+echo "Test 2 - With GET lang=fi: " . $translation->getCurrentLanguage() . "\n";
+echo "Session language: " . ($_SESSION['language'] ?? 'not set') . "\n\n";
+
+// Test 3: Session persistence
+$_GET = array(); // Clear GET params
+$translation = Translation::getInstance(); // Fresh instance
+echo "Test 3 - Session persistence: " . $translation->getCurrentLanguage() . "\n";
+echo "Session language: " . ($_SESSION['language'] ?? 'not set') . "\n\n";
+
+// Test 4: Test translation
+echo "Test 4 - Translation test:\n";
+echo "English 'nav_home': " . $translation->translate('nav_home') . "\n";
+echo "Finnish 'nav_home': " . $translation->translate('nav_home') . "\n\n";
+
+// Test 5: Language switcher
+echo "Test 5 - Language switcher HTML:\n";
+echo $translation->getLanguageSwitcher('test.php') . "\n";
+?>