Liste Item Custom
objet(s) configuré(s) dans cette liste personnalisée.
Ajouter un bonus / malus
| Statistique | Signe | Valeur | Unité | Aperçu | Actions |
|---|---|---|---|---|---|
| Aucune statistique configurée pour cet objet. | |||||
|
|
|||||
'\\\\', '%' => '\\%', '_' => '\\_', ]); } function scitemcustom_search_available_items(PDO $db, int $ownerAuthId, string $query, ?int $limit = null): array { $query = trim($query); if ($query === '') { return []; } $escapedQuery = scitemcustom_escape_like($query); $exact = $escapedQuery; $prefix = $escapedQuery . '%'; $contains = '%' . $escapedQuery . '%'; $limitClause = ''; if ($limit !== null && $limit > 0) { $limitClause = ' LIMIT ' . (int) $limit; } $sql = "SELECT cl_scobjs_id, cl_scobjs_name, cl_scobjs_uuid, cl_scobjs_type, cl_scobjs_subtype FROM tbl_scobjs WHERE cl_scobjs_id NOT IN ( SELECT cl_scitemcustom_obj_id FROM tbl_scitemcustom WHERE cl_scitemcustom_owner_auth_id = :owner_auth_id ) AND ( cl_scobjs_name LIKE :contains_name OR cl_scobjs_type LIKE :contains_type OR cl_scobjs_subtype LIKE :contains_subtype OR cl_scobjs_uuid LIKE :contains_uuid ) ORDER BY CASE WHEN cl_scobjs_name = :exact_name THEN 0 WHEN cl_scobjs_name LIKE :prefix_name THEN 1 WHEN cl_scobjs_uuid = :exact_uuid THEN 2 WHEN cl_scobjs_uuid LIKE :prefix_uuid THEN 3 WHEN cl_scobjs_type LIKE :prefix_type THEN 4 WHEN cl_scobjs_subtype LIKE :prefix_subtype THEN 5 ELSE 6 END ASC, CHAR_LENGTH(cl_scobjs_name) ASC, cl_scobjs_name ASC, cl_scobjs_id ASC {$limitClause}"; $stmt = $db->prepare($sql); $stmt->execute([ 'owner_auth_id' => $ownerAuthId, 'contains_name' => $contains, 'contains_type' => $contains, 'contains_subtype' => $contains, 'contains_uuid' => $contains, 'exact_name' => $exact, 'prefix_name' => $prefix, 'exact_uuid' => $exact, 'prefix_uuid' => $prefix, 'prefix_type' => $prefix, 'prefix_subtype' => $prefix, ]); return $stmt->fetchAll() ?: []; } function scitemcustom_preview(string $sign, $value, string $unit): string { $prefix = $sign === '-' ? '-' : ($sign === '+' ? '+' : ''); return $prefix . scitemcustom_display_value($value) . ' ' . $unit; } function scitemcustom_current_owner_auth_id(PDO $db): int { $session_user = isset($_SESSION['user']) ? trim((string) $_SESSION['user']) : ''; if ($session_user === '') { return 0; } $stmt_owner = $db->prepare( 'SELECT cl_auth_id FROM tbl_auth WHERE cl_auth_user = :user LIMIT 1' ); $stmt_owner->execute(['user' => $session_user]); return (int) $stmt_owner->fetchColumn(); } function scitemcustom_redirect(?int $itemcustom_id = null): void { $location = 'scitemcustom.php'; if ($itemcustom_id !== null && $itemcustom_id > 0) { $location .= '#itemcustom-' . $itemcustom_id; } header('Location: ' . $location); exit; } $flash = auth_flash_get(); $flash_type = $flash['type'] ?? ''; $flash_message = $flash['message'] ?? ''; $db = db(); $csrf_token = auth_csrf_token(); $allowed_signs = ['+', '', '-']; $sign_labels = ['+' => '+', '' => 'Aucun', '-' => '-']; $current_owner_auth_id = scitemcustom_current_owner_auth_id($db); if ($current_owner_auth_id <= 0) { auth_flash_set('error', 'Utilisateur introuvable. Merci de vous reconnecter.'); header('Location: logout.php'); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $submitted_csrf = $_POST['csrf_token'] ?? ''; if (!auth_validate_csrf($submitted_csrf)) { auth_flash_set('error', 'Jeton CSRF invalide.'); scitemcustom_redirect(); } $action = $_POST['action'] ?? ''; if ($action === 'add_custom_item') { $obj_id = (int) ($_POST['obj_id'] ?? 0); $redirect_itemcustom_id = null; if ($obj_id <= 0) { auth_flash_set('error', 'Objet invalide.'); } else { try { $stmt_check = $db->prepare('SELECT cl_scobjs_id FROM tbl_scobjs WHERE cl_scobjs_id = :id'); $stmt_check->execute(['id' => $obj_id]); if (!$stmt_check->fetch()) { auth_flash_set('error', 'Objet introuvable.'); } else { $stmt_insert = $db->prepare( 'INSERT INTO tbl_scitemcustom (cl_scitemcustom_owner_auth_id, cl_scitemcustom_obj_id) VALUES (:owner_auth_id, :obj_id)' ); $stmt_insert->execute([ 'owner_auth_id' => $current_owner_auth_id, 'obj_id' => $obj_id, ]); $redirect_itemcustom_id = (int) $db->lastInsertId(); auth_flash_set('success', 'Objet ajouté dans Item Custom.'); } } catch (PDOException $e) { if ((string) $e->getCode() === '23000') { auth_flash_set('error', 'Cet objet est déjà présent dans Item Custom.'); } else { auth_flash_set('error', 'Erreur lors de l\'ajout : ' . $e->getMessage()); } } } scitemcustom_redirect($redirect_itemcustom_id); } if ($action === 'delete_custom_item') { $itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0); if ($itemcustom_id > 0) { try { $stmt_delete = $db->prepare( 'DELETE FROM tbl_scitemcustom WHERE cl_scitemcustom_id = :id AND cl_scitemcustom_owner_auth_id = :owner_auth_id' ); $stmt_delete->execute([ 'id' => $itemcustom_id, 'owner_auth_id' => $current_owner_auth_id, ]); if ($stmt_delete->rowCount() > 0) { auth_flash_set('success', 'Objet Item Custom supprimé.'); } else { auth_flash_set('error', 'Objet introuvable ou non autorisé.'); } } catch (PDOException $e) { auth_flash_set('error', 'Erreur lors de la suppression : ' . $e->getMessage()); } } scitemcustom_redirect(); } if ($action === 'add_custom_stat') { $itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0); $stat_id = (int) ($_POST['stat_id'] ?? 0); $sign = scitemcustom_normalize_sign($_POST['sign'] ?? '+'); $value = scitemcustom_normalize_value($_POST['value'] ?? ''); if ($itemcustom_id <= 0 || $stat_id <= 0 || $value === null) { auth_flash_set('error', 'Données de statistique invalides.'); } else { try { $stmt_check = $db->prepare( 'SELECT c.cl_scitemcustom_id, s.cl_scstatsitem_id FROM tbl_scitemcustom c JOIN tbl_scstatsitem s ON s.cl_scstatsitem_id = :stat_id WHERE c.cl_scitemcustom_id = :itemcustom_id AND c.cl_scitemcustom_owner_auth_id = :owner_auth_id' ); $stmt_check->execute([ 'itemcustom_id' => $itemcustom_id, 'stat_id' => $stat_id, 'owner_auth_id' => $current_owner_auth_id, ]); if (!$stmt_check->fetch()) { auth_flash_set('error', 'Objet ou statistique introuvable.'); } else { $stmt_insert = $db->prepare( 'INSERT INTO tbl_scitemcustomstat ( cl_scitemcustomstat_itemcustom_id, cl_scitemcustomstat_stat_id, cl_scitemcustomstat_sign, cl_scitemcustomstat_value ) VALUES (:itemcustom_id, :stat_id, :sign, :value)' ); $stmt_insert->execute([ 'itemcustom_id' => $itemcustom_id, 'stat_id' => $stat_id, 'sign' => $sign, 'value' => $value, ]); auth_flash_set('success', 'Statistique ajoutée à l\'objet.'); } } catch (PDOException $e) { if ((string) $e->getCode() === '23000') { auth_flash_set('error', 'Cette statistique est déjà configurée pour cet objet.'); } else { auth_flash_set('error', 'Erreur lors de l\'ajout : ' . $e->getMessage()); } } } scitemcustom_redirect($itemcustom_id); } if ($action === 'update_custom_stat') { $custom_stat_id = (int) ($_POST['custom_stat_id'] ?? 0); $itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0); $stat_id = (int) ($_POST['stat_id'] ?? 0); $sign = scitemcustom_normalize_sign($_POST['sign'] ?? '+'); $value = scitemcustom_normalize_value($_POST['value'] ?? ''); if ($custom_stat_id <= 0 || $stat_id <= 0 || $value === null) { auth_flash_set('error', 'Données de mise à jour invalides.'); } else { try { $stmt_update = $db->prepare( 'UPDATE tbl_scitemcustomstat cs JOIN tbl_scitemcustom c ON c.cl_scitemcustom_id = cs.cl_scitemcustomstat_itemcustom_id JOIN tbl_scstatsitem s ON s.cl_scstatsitem_id = :stat_id SET cs.cl_scitemcustomstat_stat_id = :stat_id, cs.cl_scitemcustomstat_sign = :sign, cs.cl_scitemcustomstat_value = :value WHERE cs.cl_scitemcustomstat_id = :id AND c.cl_scitemcustom_owner_auth_id = :owner_auth_id' ); $stmt_update->execute([ 'stat_id' => $stat_id, 'sign' => $sign, 'value' => $value, 'id' => $custom_stat_id, 'owner_auth_id' => $current_owner_auth_id, ]); if ($stmt_update->rowCount() > 0) { auth_flash_set('success', 'Statistique mise à jour.'); } else { auth_flash_set('error', 'Statistique introuvable ou non autorisée.'); } } catch (PDOException $e) { if ((string) $e->getCode() === '23000') { auth_flash_set('error', 'Cette statistique est déjà configurée pour cet objet.'); } else { auth_flash_set('error', 'Erreur lors de la mise à jour : ' . $e->getMessage()); } } } scitemcustom_redirect($itemcustom_id); } if ($action === 'delete_custom_stat') { $custom_stat_id = (int) ($_POST['custom_stat_id'] ?? 0); $itemcustom_id = (int) ($_POST['itemcustom_id'] ?? 0); if ($custom_stat_id > 0) { try { $stmt_delete = $db->prepare( 'DELETE cs FROM tbl_scitemcustomstat cs JOIN tbl_scitemcustom c ON c.cl_scitemcustom_id = cs.cl_scitemcustomstat_itemcustom_id WHERE cs.cl_scitemcustomstat_id = :id AND c.cl_scitemcustom_owner_auth_id = :owner_auth_id' ); $stmt_delete->execute([ 'id' => $custom_stat_id, 'owner_auth_id' => $current_owner_auth_id, ]); if ($stmt_delete->rowCount() > 0) { auth_flash_set('success', 'Statistique supprimée de l\'objet.'); } else { auth_flash_set('error', 'Statistique introuvable ou non autorisée.'); } } catch (PDOException $e) { auth_flash_set('error', 'Erreur lors de la suppression : ' . $e->getMessage()); } } scitemcustom_redirect($itemcustom_id); } } if ($_SERVER['REQUEST_METHOD'] === 'GET' && (string) ($_GET['ajax'] ?? '') === 'item_suggestions') { header('Content-Type: application/json; charset=UTF-8'); $query = trim((string) ($_GET['q'] ?? '')); $items = []; if (mb_strlen($query) >= 3) { $items = array_map(static function (array $row): array { return [ 'id' => (int) $row['cl_scobjs_id'], 'name' => (string) $row['cl_scobjs_name'], 'uuid' => (string) $row['cl_scobjs_uuid'], 'type' => (string) $row['cl_scobjs_type'], 'subtype' => (string) ($row['cl_scobjs_subtype'] ?? ''), ]; }, scitemcustom_search_available_items($db, $current_owner_auth_id, $query)); } echo json_encode(['items' => $items], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); exit; } $search = trim($_GET['search'] ?? ''); $search_results = $search !== '' ? scitemcustom_search_available_items($db, $current_owner_auth_id, $search, 15) : []; $stmt_stats_catalog = $db->query('SELECT * FROM tbl_scstatsitem ORDER BY cl_scstatsitem_name ASC, cl_scstatsitem_id ASC'); $stats_catalog = $stmt_stats_catalog->fetchAll(); $stats_by_id = []; foreach ($stats_catalog as $stat_catalog_row) { $stats_by_id[(int) $stat_catalog_row['cl_scstatsitem_id']] = $stat_catalog_row; } $sql_custom_items = "SELECT c.*, o.cl_scobjs_name, o.cl_scobjs_uuid, o.cl_scobjs_type, o.cl_scobjs_subtype, o.cl_scobjs_rarity FROM tbl_scitemcustom c JOIN tbl_scobjs o ON o.cl_scobjs_id = c.cl_scitemcustom_obj_id WHERE c.cl_scitemcustom_owner_auth_id = :owner_auth_id ORDER BY o.cl_scobjs_name ASC, c.cl_scitemcustom_id ASC"; $stmt_custom_items = $db->prepare($sql_custom_items); $stmt_custom_items->execute(['owner_auth_id' => $current_owner_auth_id]); $custom_items = $stmt_custom_items->fetchAll(); $stmt_custom_stats = $db->prepare( "SELECT cs.*, st.cl_scstatsitem_name, st.cl_scstatsitem_unit FROM tbl_scitemcustomstat cs JOIN tbl_scitemcustom c ON c.cl_scitemcustom_id = cs.cl_scitemcustomstat_itemcustom_id JOIN tbl_scstatsitem st ON st.cl_scstatsitem_id = cs.cl_scitemcustomstat_stat_id WHERE c.cl_scitemcustom_owner_auth_id = :owner_auth_id ORDER BY cs.cl_scitemcustomstat_itemcustom_id ASC, st.cl_scstatsitem_name ASC, cs.cl_scitemcustomstat_id ASC" ); $stmt_custom_stats->execute(['owner_auth_id' => $current_owner_auth_id]); $custom_stats_rows = $stmt_custom_stats->fetchAll(); $custom_stats_by_item = []; foreach ($custom_stats_rows as $custom_stat_row) { $item_key = (int) $custom_stat_row['cl_scitemcustomstat_itemcustom_id']; if (!isset($custom_stats_by_item[$item_key])) { $custom_stats_by_item[$item_key] = []; } $custom_stats_by_item[$item_key][] = $custom_stat_row; } $current_session_user = $_SESSION['user'] ?? ''; ?>
objet(s) configuré(s) dans cette liste personnalisée.
| Statistique | Signe | Valeur | Unité | Aperçu | Actions |
|---|---|---|---|---|---|
| Aucune statistique configurée pour cet objet. | |||||
|
|
|||||