V1.0.1
This commit is contained in:
parent
e464a95e35
commit
2145a0438c
@ -9,6 +9,14 @@ function scitemcustom_column_exists(PDO $db, string $table, string $column): boo
|
||||
return (bool) $stmt->fetch();
|
||||
}
|
||||
|
||||
function scitemcustom_column_definition(PDO $db, string $table, string $column): ?array
|
||||
{
|
||||
$stmt = $db->query("SHOW COLUMNS FROM `{$table}` LIKE " . $db->quote($column));
|
||||
$column_definition = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
return $column_definition ?: null;
|
||||
}
|
||||
|
||||
function scitemcustom_index_exists(PDO $db, string $table, string $index): bool
|
||||
{
|
||||
$stmt = $db->query("SHOW INDEX FROM `{$table}` WHERE Key_name = " . $db->quote($index));
|
||||
@ -105,7 +113,7 @@ function scitemcustom_bootstrap(): void
|
||||
cl_scitemcustomstat_id INT(11) NOT NULL AUTO_INCREMENT,
|
||||
cl_scitemcustomstat_itemcustom_id INT(11) NOT NULL,
|
||||
cl_scitemcustomstat_stat_id INT(11) NOT NULL,
|
||||
cl_scitemcustomstat_sign ENUM('+', '-') NOT NULL DEFAULT '+',
|
||||
cl_scitemcustomstat_sign ENUM('+', '', '-') NOT NULL DEFAULT '+',
|
||||
cl_scitemcustomstat_value DECIMAL(10,2) NOT NULL DEFAULT 0.00,
|
||||
cl_scitemcustomstat_created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (cl_scitemcustomstat_id),
|
||||
@ -123,5 +131,13 @@ function scitemcustom_bootstrap(): void
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"
|
||||
);
|
||||
|
||||
$sign_column = scitemcustom_column_definition($db, 'tbl_scitemcustomstat', 'cl_scitemcustomstat_sign');
|
||||
if ($sign_column && ($sign_column['Type'] ?? '') !== "enum('+','','-')") {
|
||||
$db->exec(
|
||||
"ALTER TABLE tbl_scitemcustomstat
|
||||
MODIFY COLUMN cl_scitemcustomstat_sign ENUM('+', '', '-') NOT NULL DEFAULT '+'"
|
||||
);
|
||||
}
|
||||
|
||||
$scitemcustom_bootstrap_done = true;
|
||||
}
|
||||
|
||||
@ -16,7 +16,15 @@ if (!auth_is_admin()) {
|
||||
|
||||
function scitemcustom_normalize_sign(?string $sign): string
|
||||
{
|
||||
return $sign === '-' ? '-' : '+';
|
||||
if ($sign === '-') {
|
||||
return '-';
|
||||
}
|
||||
|
||||
if ($sign === '+') {
|
||||
return '+';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function scitemcustom_normalize_value(?string $value): ?string
|
||||
@ -43,7 +51,9 @@ function scitemcustom_display_value($value): string
|
||||
|
||||
function scitemcustom_preview(string $sign, $value, string $unit): string
|
||||
{
|
||||
return ($sign === '-' ? '-' : '+') . scitemcustom_display_value($value) . $unit;
|
||||
$prefix = $sign === '-' ? '-' : ($sign === '+' ? '+' : '');
|
||||
|
||||
return $prefix . scitemcustom_display_value($value) . $unit;
|
||||
}
|
||||
|
||||
function scitemcustom_current_owner_auth_id(PDO $db): int
|
||||
@ -70,7 +80,8 @@ $flash_message = $flash['message'] ?? '';
|
||||
|
||||
$db = db();
|
||||
$csrf_token = auth_csrf_token();
|
||||
$allowed_signs = ['+', '-'];
|
||||
$allowed_signs = ['+', '', '-'];
|
||||
$sign_labels = ['+' => '+', '' => 'Aucun', '-' => '-'];
|
||||
$current_owner_auth_id = scitemcustom_current_owner_auth_id($db);
|
||||
|
||||
if ($current_owner_auth_id <= 0) {
|
||||
@ -871,8 +882,11 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
<div class="form-group" style="margin-bottom:0;">
|
||||
<label>Signe</label>
|
||||
<select name="sign" class="form-control">
|
||||
<option value="+" selected>+</option>
|
||||
<option value="-">-</option>
|
||||
<?php foreach ($allowed_signs as $sign_option): ?>
|
||||
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === '+' ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@ -923,7 +937,7 @@ $current_session_user = $_SESSION['user'] ?? '';
|
||||
<select name="sign" class="form-control">
|
||||
<?php foreach ($allowed_signs as $sign_option): ?>
|
||||
<option value="<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $sign_option === $item_stat['cl_scitemcustomstat_sign'] ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($sign_option, ENT_QUOTES, 'UTF-8'); ?>
|
||||
<?php echo htmlspecialchars($sign_labels[$sign_option], ENT_QUOTES, 'UTF-8'); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
@ -19,7 +19,7 @@ $flash_message = $flash['message'] ?? '';
|
||||
$db = db();
|
||||
$csrf_token = auth_csrf_token();
|
||||
|
||||
$allowed_units = ['%', '°C', 'RPM'];
|
||||
$allowed_units = ['%', '°C', 'RPM', 'Q', 'SCU'];
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user