Issues (2089)

public/main/admin/filler.php (2 issues)

Labels
Severity
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Index of the admin tools.
6
 */
7
8
use Chamilo\CoreBundle\Enums\ActionIcon;
9
use Chamilo\CoreBundle\Enums\ObjectIcon;
10
11
// resetting the course id
12
$cidReset = true;
13
14
// including some necessary chamilo files
15
require_once __DIR__.'/../inc/global.inc.php';
16
17
// setting the section (for the tabs)
18
$this_section = SECTION_PLATFORM_ADMIN;
19
20
// Access restrictions
21
api_protect_admin_script(true);
22
23
$nameTools = get_lang('Administration');
24
25
// setting breadcrumbs
26
$interbreadcrumb[] = ['url' => 'index.php', 'name' => $nameTools];
27
28
// setting the name of the tool
29
$nameTools = get_lang('Data filler');
30
31
$output = [];
32
if (!empty($_GET['fill'])) {
33
    switch ($_GET['fill']) {
34
        case 'users':
35
            require __DIR__.'/../../../tests/datafiller/fill_users.php';
36
            $output = fill_users();
0 ignored issues
show
The function fill_users was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
            $output = /** @scrutinizer ignore-call */ fill_users();
Loading history...
37
            break;
38
        case 'courses':
39
            require __DIR__.'/../../../tests/datafiller/fill_courses.php';
40
            $output = fill_courses();
0 ignored issues
show
The function fill_courses was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            $output = /** @scrutinizer ignore-call */ fill_courses();
Loading history...
41
            break;
42
        default:
43
            break;
44
    }
45
}
46
47
// Displaying the header
48
Display::display_header($nameTools);
49
?>
50
    <div class="w-full max-w-none px-6 py-6">
51
52
        <?php if (!empty($output)) : ?>
53
            <?php
54
            $reportTitle = $output[0]['title'] ?? get_lang('Report');
55
            ?>
56
57
            <div class="mb-4 rounded-xl border border-info/30 bg-info/10 px-4 py-3">
58
                <p class="font-medium text-gray-90"><?php echo htmlspecialchars($reportTitle); ?></p>
59
            </div>
60
61
            <div class="overflow-hidden rounded-2xl border border-gray-25 bg-white shadow-sm">
62
                <?php foreach ($output as $i => $line) :
63
                    if ($i === 0) { continue; }
64
                    $title      = $line['line-init'] ?? '';
65
                    $statusText = (string)($line['line-info'] ?? '');
66
                    $statusCode = $line['status'] ?? null;
67
68
                    if ($statusCode === null) {
69
                        $isOk  = preg_match('/(Ajout|Added|Añadid|Agregad|OK|Success)/i', $statusText);
70
                        $isErr = preg_match('/(Non|Not|Error|Erreur|No|Failed|Existe|already)/i', $statusText);
71
                        $statusCode = $isOk ? 'ok' : ($isErr ? 'error' : 'exists');
72
                    }
73
                    switch ($statusCode) {
74
                        case 'ok':
75
                            $badge = 'bg-success/10 text-success border-success/30';
76
                            $dot   = 'bg-success';
77
                            break;
78
                        case 'error':
79
                            $badge = 'bg-danger/10 text-danger border-danger/30';
80
                            $dot   = 'bg-danger';
81
                            break;
82
                        case 'exists':
83
                        default:
84
                            $badge = 'bg-warning/10 text-warning border-warning/30';
85
                            $dot   = 'bg-warning';
86
                            break;
87
                    }
88
                    ?>
89
                    <div class="flex items-center justify-between border-b border-gray-25 px-4 py-3 last:border-b-0">
90
                        <div class="flex min-w-0 items-start gap-3">
91
                            <span class="mt-1 inline-flex h-2.5 w-2.5 flex-none rounded-full <?php echo $dot; ?>"></span>
92
                            <span class="truncate font-medium text-gray-90"><?php echo htmlspecialchars($title); ?></span>
93
                        </div>
94
                        <span class="ml-4 inline-flex items-center rounded-full border px-3 py-1 text-sm <?php echo $badge; ?>">
95
            <?php echo htmlspecialchars($statusText); ?>
96
        </span>
97
                    </div>
98
                <?php endforeach; ?>
99
100
            </div>
101
        <?php endif; ?>
102
103
        <section class="mt-8 rounded-2xl border border-gray-25 bg-white p-6 shadow-sm">
104
            <div class="mb-4 flex items-center gap-3">
105
                <div class="flex h-10 w-10 items-center justify-center rounded-full bg-support-2">
106
                    <?php echo Display::getMdiIcon(ActionIcon::FILL, 'h-6 w-6 text-info', null, ICON_SIZE_SMALL, get_lang('Data filler')); ?>
107
                </div>
108
                <div>
109
                    <h4 class="text-lg font-semibold text-gray-90"><?php echo get_lang('Data filler'); ?></h4>
110
                    <p class="mt-1 text-sm text-gray-50">
111
                        <?php echo get_lang('This section is only visible on installations from source code, not in packaged versions of the platform. It will allow you to quickly populate your platform with test data. Use with care (data is really inserted) and only on development or testing installations.'); ?>
112
                    </p>
113
                </div>
114
            </div>
115
116
            <div class="grid gap-4 sm:grid-cols-2">
117
                <a href="filler.php?fill=users"
118
                   class="group flex items-center justify-between rounded-xl border border-gray-25 bg-white p-4 hover:bg-gray-10">
119
                    <div class="flex items-center gap-3">
120
                        <?php
121
                        echo Display::getMdiIcon(
122
                            ObjectIcon::USER,
123
                            'h-5 w-5 text-primary',
124
                            null,
125
                            ICON_SIZE_SMALL,
126
                            get_lang('Fill users')
127
                        );
128
                        ?>
129
                        <span class="font-medium text-gray-90"><?php echo get_lang('Fill users'); ?></span>
130
                    </div>
131
                    <span class="rounded-md bg-primary/10 px-2 py-1 text-xs font-medium text-primary">
132
          <?php echo get_lang('Run'); ?>
133
        </span>
134
                </a>
135
136
                <a href="filler.php?fill=courses"
137
                   class="group flex items-center justify-between rounded-xl border border-gray-25 bg-white p-4 hover:bg-gray-10">
138
                    <div class="flex items-center gap-3">
139
                        <?php
140
                        echo Display::getMdiIcon(
141
                            ObjectIcon::COURSE,
142
                            'h-5 w-5 text-secondary',
143
                            null,
144
                            ICON_SIZE_SMALL,
145
                            get_lang('Fill courses')
146
                        );
147
                        ?>
148
                        <span class="font-medium text-gray-90"><?php echo get_lang('Fill courses'); ?></span>
149
                    </div>
150
                    <span class="rounded-md bg-secondary/10 px-2 py-1 text-xs font-medium text-secondary">
151
          <?php echo get_lang('Run'); ?>
152
        </span>
153
                </a>
154
            </div>
155
        </section>
156
    </div>
157
158
<?php
159
Display::display_footer();
160