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); } } $search = trim($_GET['search'] ?? ''); $search_results = []; if ($search !== '') { $stmt_search = $db->prepare( "SELECT * FROM tbl_scobjs WHERE (cl_scobjs_name LIKE :search OR cl_scobjs_type LIKE :search OR cl_scobjs_subtype LIKE :search OR cl_scobjs_uuid LIKE :search) AND cl_scobjs_id NOT IN ( SELECT cl_scitemcustom_obj_id FROM tbl_scitemcustom WHERE cl_scitemcustom_owner_auth_id = :owner_auth_id ) ORDER BY cl_scobjs_name ASC LIMIT 15" ); $stmt_search->execute([ 'search' => '%' . $search . '%', 'owner_auth_id' => $current_owner_auth_id, ]); $search_results = $stmt_search->fetchAll(); } $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'] ?? ''; ?> OBJETS PERSONNALISES | R.E.A.C.T. Admin

OBJETS PERSONNALISES

Associer des objets à autant de bonus / malus de stats que nécessaire

Liste Item Custom

objet(s) configuré(s) dans cette liste personnalisée.

Aucun objet Item Custom enregistré pour le moment.
Affichage : /
Tape quelques lettres pour retrouver rapidement un objet déjà présent dans ta liste Item Custom.
Aucun objet Item Custom ne correspond à cette recherche.
/
UUID:
stat 1 ? 's' : ''; ?>