Passed
Pull Request — master (#5000)
by Nils
06:29
created
sources/admin.queries.php 1 patch
Switch Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -2904,8 +2904,8 @@  discard block
 block discarded – undo
2904 2904
 // LIVE ACTIVITY ENDPOINT
2905 2905
 // ========================================
2906 2906
 
2907
-case 'get_live_activity':
2908
-    /**
2907
+    case 'get_live_activity':
2908
+        /**
2909 2909
      * Get recent activity (last 5 minutes, max 10 entries)
2910 2910
      * 
2911 2911
      * @return array [{
@@ -2919,26 +2919,26 @@  discard block
 block discarded – undo
2919 2919
      * }]
2920 2920
      */
2921 2921
     
2922
-    $timestamp5min = time() - 300; // 5 minutes ago
2922
+        $timestamp5min = time() - 300; // 5 minutes ago
2923 2923
     
2924
-    $activities = DB::query(
2925
-        'SELECT l.date, l.id_user, u.login, l.action, l.raison, l.id_item, i.label 
2924
+        $activities = DB::query(
2925
+            'SELECT l.date, l.id_user, u.login, l.action, l.raison, l.id_item, i.label 
2926 2926
         FROM ' . prefixTable('log_items') . ' AS l
2927 2927
         LEFT JOIN ' . prefixTable('users') . ' AS u ON l.id_user = u.id
2928 2928
         LEFT JOIN ' . prefixTable('items') . ' AS i ON l.id_item = i.id
2929 2929
         WHERE l.date > %i
2930 2930
         ORDER BY l.date DESC
2931 2931
         LIMIT 10',
2932
-        $timestamp5min
2933
-    );
2934
-    $activities = secureOutput($activities, ['login']);
2932
+            $timestamp5min
2933
+        );
2934
+        $activities = secureOutput($activities, ['login']);
2935 2935
     
2936
-    $activityList = array();
2936
+        $activityList = array();
2937 2937
     
2938
-    foreach ($activities as $activity) {
2939
-        // Translate action to readable text
2940
-        $actionText = '';
2941
-        switch ($activity['action']) {
2938
+        foreach ($activities as $activity) {
2939
+            // Translate action to readable text
2940
+            $actionText = '';
2941
+            switch ($activity['action']) {
2942 2942
             case 'at_shown':
2943 2943
                 $actionText = $lang->get('action_accessed');
2944 2944
                 break;
@@ -2962,7 +2962,7 @@  discard block
 block discarded – undo
2962 2962
                 break;
2963 2963
             default:
2964 2964
                 $actionText = $activity['action'];
2965
-        }
2965
+            }
2966 2966
         
2967 2967
         $activityList[] = array(
2968 2968
             'timestamp' => (int) $activity['date'],
@@ -2988,8 +2988,8 @@  discard block
 block discarded – undo
2988 2988
 // SYSTEM STATUS ENDPOINT
2989 2989
 // ========================================
2990 2990
 
2991
-case 'get_system_status':
2992
-    /**
2991
+    case 'get_system_status':
2992
+        /**
2993 2993
      * Get system status (tasks queue)
2994 2994
      * 
2995 2995
      * @return array {
@@ -2998,49 +2998,49 @@  discard block
 block discarded – undo
2998 2998
      * }
2999 2999
      */
3000 3000
         
3001
-    // Tasks queue count
3002
-    $tasksQueue = DB::queryFirstField(
3003
-        'SELECT COUNT(*) FROM ' . prefixTable('background_tasks') . ' 
3001
+        // Tasks queue count
3002
+        $tasksQueue = DB::queryFirstField(
3003
+            'SELECT COUNT(*) FROM ' . prefixTable('background_tasks') . ' 
3004 3004
         WHERE finished_at IS NULL OR finished_at = 0'
3005
-    );
3005
+        );
3006 3006
     
3007
-    // Last cron execution
3008
-    $lastCronLog = DB::queryFirstRow(
3009
-        'SELECT created_at FROM ' . prefixTable('background_tasks_logs') . ' 
3007
+        // Last cron execution
3008
+        $lastCronLog = DB::queryFirstRow(
3009
+            'SELECT created_at FROM ' . prefixTable('background_tasks_logs') . ' 
3010 3010
         ORDER BY created_at DESC 
3011 3011
         LIMIT 1'
3012
-    );
3012
+        );
3013 3013
     
3014
-    $lastCronText = $lang->get('never');
3015
-    if ($lastCronLog && isset($lastCronLog['created_at'])) {
3016
-        $timeDiff = time() - (int) $lastCronLog['created_at'];
3017
-        if ($timeDiff < 60) {
3018
-            $lastCronText = $timeDiff . 's ' . $lang->get('ago');
3019
-        } elseif ($timeDiff < 3600) {
3020
-            $lastCronText = floor($timeDiff / 60) . 'm ' . $lang->get('ago');
3021
-        } elseif ($timeDiff < 86400) {
3022
-            $lastCronText = floor($timeDiff / 3600) . 'h ' . $lang->get('ago');
3023
-        } else {
3024
-            $lastCronText = floor($timeDiff / 86400) . 'd ' . $lang->get('ago');
3014
+        $lastCronText = $lang->get('never');
3015
+        if ($lastCronLog && isset($lastCronLog['created_at'])) {
3016
+            $timeDiff = time() - (int) $lastCronLog['created_at'];
3017
+            if ($timeDiff < 60) {
3018
+                $lastCronText = $timeDiff . 's ' . $lang->get('ago');
3019
+            } elseif ($timeDiff < 3600) {
3020
+                $lastCronText = floor($timeDiff / 60) . 'm ' . $lang->get('ago');
3021
+            } elseif ($timeDiff < 86400) {
3022
+                $lastCronText = floor($timeDiff / 3600) . 'h ' . $lang->get('ago');
3023
+            } else {
3024
+                $lastCronText = floor($timeDiff / 86400) . 'd ' . $lang->get('ago');
3025
+            }
3025 3026
         }
3026
-    }
3027 3027
     
3028
-    echo prepareExchangedData(
3029
-        array(
3030
-            'error' => false,
3031
-            'tasks_queue' => (int) $tasksQueue,
3032
-            'last_cron' => $lastCronText,
3033
-        ),
3034
-        'encode'
3035
-    );
3036
-    break;
3028
+        echo prepareExchangedData(
3029
+            array(
3030
+                'error' => false,
3031
+                'tasks_queue' => (int) $tasksQueue,
3032
+                'last_cron' => $lastCronText,
3033
+            ),
3034
+            'encode'
3035
+        );
3036
+        break;
3037 3037
 
3038
-// ========================================
3039
-// SYSTEM HEALTH ENDPOINT
3040
-// ========================================
3038
+    // ========================================
3039
+    // SYSTEM HEALTH ENDPOINT
3040
+    // ========================================
3041 3041
 
3042
-case 'get_system_health':
3043
-    /**
3042
+    case 'get_system_health':
3043
+        /**
3044 3044
      * Get system health checks
3045 3045
      * 
3046 3046
      * @return array {
@@ -3052,97 +3052,97 @@  discard block
 block discarded – undo
3052 3052
      * }
3053 3053
      */
3054 3054
     
3055
-    // Encryption check
3056
-    $encryptionStatus = 'success';
3057
-    $encryptionText = $lang->get('health_status_ok');
3055
+        // Encryption check
3056
+        $encryptionStatus = 'success';
3057
+        $encryptionText = $lang->get('health_status_ok');
3058 3058
     
3059
-    // Check if secure file exists
3060
-    if (isset($SETTINGS['securepath']) && isset($SETTINGS['securefile']) && !file_exists($SETTINGS['securepath'] . DIRECTORY_SEPARATOR . $SETTINGS['securefile'])) {
3061
-        $encryptionStatus = 'danger';
3062
-        $encryptionText = $lang->get('health_secure_file_missing');
3063
-    }
3059
+        // Check if secure file exists
3060
+        if (isset($SETTINGS['securepath']) && isset($SETTINGS['securefile']) && !file_exists($SETTINGS['securepath'] . DIRECTORY_SEPARATOR . $SETTINGS['securefile'])) {
3061
+            $encryptionStatus = 'danger';
3062
+            $encryptionText = $lang->get('health_secure_file_missing');
3063
+        }
3064 3064
     
3065
-    // Active sessions count
3066
-    $sessionsCount = DB::queryFirstField(
3067
-        'SELECT COUNT(*) FROM ' . prefixTable('users') . ' 
3065
+        // Active sessions count
3066
+        $sessionsCount = DB::queryFirstField(
3067
+            'SELECT COUNT(*) FROM ' . prefixTable('users') . ' 
3068 3068
         WHERE session_end > %i',
3069
-        time()
3070
-    );
3069
+            time()
3070
+        );
3071 3071
     
3072
-    // Is cron installed
3073
-    DB::query(
3074
-        'SELECT valeur
3072
+        // Is cron installed
3073
+        DB::query(
3074
+            'SELECT valeur
3075 3075
         FROM ' . prefixTable('misc') . '
3076 3076
         WHERE type = %s AND intitule = %s and valeur >= %d',
3077
-        'admin',
3078
-        'last_cron_exec',
3079
-        time() - 600 // max 10 minutes
3080
-    );
3077
+            'admin',
3078
+            'last_cron_exec',
3079
+            time() - 600 // max 10 minutes
3080
+        );
3081 3081
 
3082
-    if (DB::count() === 0) {
3083
-        $cronStatus = 'danger';
3084
-        $cronText = $lang->get('error');
3085
-    } else {
3086
-        // Cron check (last execution should be < 2 minutes ago)
3087
-        $lastCron = DB::queryFirstField(
3088
-            'SELECT created_at FROM ' . prefixTable('background_tasks_logs') . ' 
3082
+        if (DB::count() === 0) {
3083
+            $cronStatus = 'danger';
3084
+            $cronText = $lang->get('error');
3085
+        } else {
3086
+            // Cron check (last execution should be < 2 minutes ago)
3087
+            $lastCron = DB::queryFirstField(
3088
+                'SELECT created_at FROM ' . prefixTable('background_tasks_logs') . ' 
3089 3089
             ORDER BY created_at DESC 
3090 3090
             LIMIT 1'
3091
-        );
3091
+            );
3092 3092
         
3093
-        $cronStatus = 'success';
3094
-        $cronText = $lang->get('health_status_ok');
3093
+            $cronStatus = 'success';
3094
+            $cronText = $lang->get('health_status_ok');
3095 3095
         
3096
-        if (!$lastCron || (time() - (int) $lastCron) > 120) {
3097
-            $cronStatus = 'warning';
3098
-            $cronText = $lang->get('health_cron_delayed');
3096
+            if (!$lastCron || (time() - (int) $lastCron) > 120) {
3097
+                $cronStatus = 'warning';
3098
+                $cronText = $lang->get('health_cron_delayed');
3099
+            }
3099 3100
         }
3100
-    }
3101 3101
     
3102
-    // Unknown files count
3103
-    $unknownFilesData = DB::queryFirstField(
3104
-        'SELECT valeur FROM ' . prefixTable('misc') . ' 
3102
+        // Unknown files count
3103
+        $unknownFilesData = DB::queryFirstField(
3104
+            'SELECT valeur FROM ' . prefixTable('misc') . ' 
3105 3105
         WHERE type = %s AND intitule = %s',
3106
-        'admin',
3107
-        'unknown_files'
3108
-    );
3106
+            'admin',
3107
+            'unknown_files'
3108
+        );
3109 3109
     
3110
-    $unknownFilesCount = 0;
3111
-    if ($unknownFilesData) {
3112
-        $unknownFiles = json_decode($unknownFilesData, true);
3113
-        if (is_array($unknownFiles)) {
3114
-            $unknownFilesCount = count($unknownFiles);
3110
+        $unknownFilesCount = 0;
3111
+        if ($unknownFilesData) {
3112
+            $unknownFiles = json_decode($unknownFilesData, true);
3113
+            if (is_array($unknownFiles)) {
3114
+                $unknownFilesCount = count($unknownFiles);
3115
+            }
3115 3116
         }
3116
-    }
3117 3117
     
3118
-    echo prepareExchangedData(
3119
-        array(
3120
-            'error' => false,
3121
-            'encryption' => array(
3122
-                'status' => $encryptionStatus,
3123
-                'text' => $encryptionText,
3124
-            ),
3125
-            'sessions' => array(
3126
-                'count' => (int) $sessionsCount,
3127
-            ),
3128
-            'cron' => array(
3129
-                'status' => $cronStatus,
3130
-                'text' => $cronText,
3131
-            ),
3132
-            'unknown_files' => array(
3133
-                'count' => $unknownFilesCount,
3118
+        echo prepareExchangedData(
3119
+            array(
3120
+                'error' => false,
3121
+                'encryption' => array(
3122
+                    'status' => $encryptionStatus,
3123
+                    'text' => $encryptionText,
3124
+                ),
3125
+                'sessions' => array(
3126
+                    'count' => (int) $sessionsCount,
3127
+                ),
3128
+                'cron' => array(
3129
+                    'status' => $cronStatus,
3130
+                    'text' => $cronText,
3131
+                ),
3132
+                'unknown_files' => array(
3133
+                    'count' => $unknownFilesCount,
3134
+                ),
3134 3135
             ),
3135
-        ),
3136
-        'encode'
3137
-    );
3138
-    break;
3136
+            'encode'
3137
+        );
3138
+        break;
3139 3139
 
3140
-// ========================================
3141
-// QUICK ACTIONS - CLEAN OLD LOGS
3142
-// ========================================
3140
+    // ========================================
3141
+    // QUICK ACTIONS - CLEAN OLD LOGS
3142
+    // ========================================
3143 3143
 
3144
-case 'clean_old_logs':
3145
-    /**
3144
+    case 'clean_old_logs':
3145
+        /**
3146 3146
      * Clean logs older than 90 days
3147 3147
      * 
3148 3148
      * @return array {
@@ -3152,54 +3152,54 @@  discard block
 block discarded – undo
3152 3152
      * }
3153 3153
      */
3154 3154
     
3155
-    $threshold = time() - (90 * 86400); // 90 days ago
3155
+        $threshold = time() - (90 * 86400); // 90 days ago
3156 3156
     
3157
-    // Delete old log_items entries
3158
-    DB::delete(
3159
-        prefixTable('log_items'),
3160
-        'date < %i',
3161
-        $threshold
3162
-    );
3157
+        // Delete old log_items entries
3158
+        DB::delete(
3159
+            prefixTable('log_items'),
3160
+            'date < %i',
3161
+            $threshold
3162
+        );
3163 3163
     
3164
-    $deletedItems = DB::affectedRows();
3164
+        $deletedItems = DB::affectedRows();
3165 3165
     
3166
-    // Delete old log_system entries
3167
-    DB::delete(
3168
-        prefixTable('log_system'),
3169
-        'date < %i',
3170
-        $threshold
3171
-    );
3166
+        // Delete old log_system entries
3167
+        DB::delete(
3168
+            prefixTable('log_system'),
3169
+            'date < %i',
3170
+            $threshold
3171
+        );
3172 3172
     
3173
-    $deletedSystem = DB::affectedRows();
3173
+        $deletedSystem = DB::affectedRows();
3174 3174
     
3175
-    $totalDeleted = $deletedItems + $deletedSystem;
3175
+        $totalDeleted = $deletedItems + $deletedSystem;
3176 3176
     
3177
-    // Log the action
3178
-    logEvents(
3179
-        $SETTINGS,
3180
-        'admin_action',
3181
-        'clean_old_logs',
3182
-        (string) $session->get('user-id'),
3183
-        $session->get('user-login'),
3184
-        'Cleaned ' . $totalDeleted . ' old log entries'
3185
-    );
3177
+        // Log the action
3178
+        logEvents(
3179
+            $SETTINGS,
3180
+            'admin_action',
3181
+            'clean_old_logs',
3182
+            (string) $session->get('user-id'),
3183
+            $session->get('user-login'),
3184
+            'Cleaned ' . $totalDeleted . ' old log entries'
3185
+        );
3186 3186
     
3187
-    echo prepareExchangedData(
3188
-        array(
3189
-            'error' => false,
3190
-            'message' => $lang->get('admin_logs_cleaned_success'),
3191
-            'deleted_count' => $totalDeleted,
3192
-        ),
3193
-        'encode'
3194
-    );
3195
-    break;
3187
+        echo prepareExchangedData(
3188
+            array(
3189
+                'error' => false,
3190
+                'message' => $lang->get('admin_logs_cleaned_success'),
3191
+                'deleted_count' => $totalDeleted,
3192
+            ),
3193
+            'encode'
3194
+        );
3195
+        break;
3196 3196
 
3197
-// ========================================
3198
-// QUICK ACTIONS - TEST ENCRYPTION (KEPT FOR COMPATIBILITY)
3199
-// ========================================
3197
+    // ========================================
3198
+    // QUICK ACTIONS - TEST ENCRYPTION (KEPT FOR COMPATIBILITY)
3199
+    // ========================================
3200 3200
 
3201
-case 'test_encryption':
3202
-    /**
3201
+    case 'test_encryption':
3202
+        /**
3203 3203
      * Test encryption system integrity
3204 3204
      * 
3205 3205
      * @return array {
@@ -3208,117 +3208,117 @@  discard block
 block discarded – undo
3208 3208
      * }
3209 3209
      */
3210 3210
     
3211
-    try {
3212
-        // Test string
3213
-        $testString = 'TeamPass Encryption Test ' . time();
3211
+        try {
3212
+            // Test string
3213
+            $testString = 'TeamPass Encryption Test ' . time();
3214 3214
         
3215
-        // Get encryption key
3216
-        $key = file_get_contents($SETTINGS['securepath'] . DIRECTORY_SEPARATOR . $SETTINGS['securefile']);
3215
+            // Get encryption key
3216
+            $key = file_get_contents($SETTINGS['securepath'] . DIRECTORY_SEPARATOR . $SETTINGS['securefile']);
3217 3217
         
3218
-        if ($key === false) {
3219
-            throw new Exception($lang->get('admin_encryption_key_not_found'));
3220
-        }
3218
+            if ($key === false) {
3219
+                throw new Exception($lang->get('admin_encryption_key_not_found'));
3220
+            }
3221 3221
         
3222
-        // Use Defuse encryption (TeamPass's current encryption method)
3223
-        require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/EnvironmentIsBrokenException.php';
3224
-        require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/BadFormatException.php';
3225
-        require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/WrongKeyOrModifiedCiphertextException.php';
3226
-        require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Crypto.php';
3227
-        require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Key.php';
3222
+            // Use Defuse encryption (TeamPass's current encryption method)
3223
+            require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/EnvironmentIsBrokenException.php';
3224
+            require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/BadFormatException.php';
3225
+            require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Exception/WrongKeyOrModifiedCiphertextException.php';
3226
+            require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Crypto.php';
3227
+            require_once $SETTINGS['cpassman_dir'] . '/vendor/defuse/php-encryption/src/Key.php';
3228 3228
         
3229
-        $encryptionKey = \Defuse\Crypto\Key::loadFromAsciiSafeString($key);
3229
+            $encryptionKey = \Defuse\Crypto\Key::loadFromAsciiSafeString($key);
3230 3230
         
3231
-        // Encrypt test string
3232
-        $encrypted = \Defuse\Crypto\Crypto::encrypt($testString, $encryptionKey);
3231
+            // Encrypt test string
3232
+            $encrypted = \Defuse\Crypto\Crypto::encrypt($testString, $encryptionKey);
3233 3233
         
3234
-        // Decrypt test string
3235
-        $decrypted = \Defuse\Crypto\Crypto::decrypt($encrypted, $encryptionKey);
3234
+            // Decrypt test string
3235
+            $decrypted = \Defuse\Crypto\Crypto::decrypt($encrypted, $encryptionKey);
3236 3236
         
3237
-        // Verify
3238
-        if ($decrypted !== $testString) {
3239
-            throw new Exception($lang->get('admin_encryption_test_failed'));
3240
-        }
3237
+            // Verify
3238
+            if ($decrypted !== $testString) {
3239
+                throw new Exception($lang->get('admin_encryption_test_failed'));
3240
+            }
3241 3241
         
3242
-        // Log the test
3243
-        logEvents(
3244
-            $SETTINGS,
3245
-            'admin_action',
3246
-            'test_encryption',
3247
-            (string) $session->get('user-id'),
3248
-            $session->get('user-login'),
3249
-            'Encryption test successful'
3250
-        );
3242
+            // Log the test
3243
+            logEvents(
3244
+                $SETTINGS,
3245
+                'admin_action',
3246
+                'test_encryption',
3247
+                (string) $session->get('user-id'),
3248
+                $session->get('user-login'),
3249
+                'Encryption test successful'
3250
+            );
3251 3251
         
3252
-        echo prepareExchangedData(
3253
-            array(
3254
-                'error' => false,
3255
-                'message' => $lang->get('admin_encryption_test_success'),
3256
-            ),
3257
-            'encode'
3258
-        );
3252
+            echo prepareExchangedData(
3253
+                array(
3254
+                    'error' => false,
3255
+                    'message' => $lang->get('admin_encryption_test_success'),
3256
+                ),
3257
+                'encode'
3258
+            );
3259 3259
         
3260
-    } catch (Exception $e) {
3261
-        echo prepareExchangedData(
3262
-            array(
3263
-                'error' => true,
3264
-                'message' => $e->getMessage(),
3265
-            ),
3266
-            'encode'
3267
-        );
3268
-    }
3269
-    break;
3260
+        } catch (Exception $e) {
3261
+            echo prepareExchangedData(
3262
+                array(
3263
+                    'error' => true,
3264
+                    'message' => $e->getMessage(),
3265
+                ),
3266
+                'encode'
3267
+            );
3268
+        }
3269
+        break;
3270 3270
 
3271
-// ========================================
3272
-// QUICK ACTIONS - EXPORT STATISTICS
3273
-// ========================================
3271
+    // ========================================
3272
+    // QUICK ACTIONS - EXPORT STATISTICS
3273
+    // ========================================
3274 3274
 
3275
-case 'export_statistics':
3276
-    /**
3275
+    case 'export_statistics':
3276
+        /**
3277 3277
      * Export statistics as CSV file
3278 3278
      * 
3279 3279
      * @return void (file download)
3280 3280
      */
3281 3281
     
3282
-    // Set headers for CSV download
3283
-    header('Content-Type: text/csv; charset=utf-8');
3284
-    header('Content-Disposition: attachment; filename="teampass_statistics_' . date('Y-m-d_H-i-s') . '.csv"');
3282
+        // Set headers for CSV download
3283
+        header('Content-Type: text/csv; charset=utf-8');
3284
+        header('Content-Disposition: attachment; filename="teampass_statistics_' . date('Y-m-d_H-i-s') . '.csv"');
3285 3285
     
3286
-    // Create output stream
3287
-    $output = fopen('php://output', 'w');
3286
+        // Create output stream
3287
+        $output = fopen('php://output', 'w');
3288 3288
     
3289
-    // Write CSV headers
3290
-    fputcsv($output, array(
3291
-        $lang->get('admin_export_metric'),
3292
-        $lang->get('admin_export_value'),
3293
-    ));
3289
+        // Write CSV headers
3290
+        fputcsv($output, array(
3291
+            $lang->get('admin_export_metric'),
3292
+            $lang->get('admin_export_value'),
3293
+        ));
3294 3294
     
3295
-    // Gather statistics
3296
-    $stats = array(
3297
-        $lang->get('active_users') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('users') . ' WHERE disabled = 0'),
3298
-        $lang->get('total_items') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('items') . ' WHERE inactif = 0'),
3299
-        $lang->get('total_folders') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('nested_tree')),
3300
-        $lang->get('logs_24h') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('log_items') . ' WHERE date > ' . (time() - 86400)),
3301
-    );
3295
+        // Gather statistics
3296
+        $stats = array(
3297
+            $lang->get('active_users') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('users') . ' WHERE disabled = 0'),
3298
+            $lang->get('total_items') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('items') . ' WHERE inactif = 0'),
3299
+            $lang->get('total_folders') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('nested_tree')),
3300
+            $lang->get('logs_24h') => DB::queryFirstField('SELECT COUNT(*) FROM ' . prefixTable('log_items') . ' WHERE date > ' . (time() - 86400)),
3301
+        );
3302 3302
     
3303
-    // Write statistics
3304
-    foreach ($stats as $metric => $value) {
3305
-        fputcsv($output, array($metric, $value));
3306
-    }
3303
+        // Write statistics
3304
+        foreach ($stats as $metric => $value) {
3305
+            fputcsv($output, array($metric, $value));
3306
+        }
3307 3307
     
3308
-    fclose($output);
3308
+        fclose($output);
3309 3309
     
3310
-    // Log the export
3311
-    logEvents(
3312
-        $SETTINGS,
3313
-        'admin_action',
3314
-        'export_statistics',
3315
-        (string) $session->get('user-id'),
3316
-        $session->get('user-login'),
3317
-        'Statistics exported'
3318
-    );
3310
+        // Log the export
3311
+        logEvents(
3312
+            $SETTINGS,
3313
+            'admin_action',
3314
+            'export_statistics',
3315
+            (string) $session->get('user-id'),
3316
+            $session->get('user-login'),
3317
+            'Statistics exported'
3318
+        );
3319 3319
     
3320
-    exit;
3321
-    break;
3320
+        exit;
3321
+        break;
3322 3322
     
3323 3323
 }
3324 3324
 
Please login to merge, or discard this patch.