public static function generatePage(&$tpl, &$session, &$account, &$perso) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante $errorUrl = '?popup=1&m=Action_Perso_Depouiller'; if (!isset($_POST['persoid'])) { return fctErrorMSG('Vous devez sélectionner une personne à fouiller.', $errorUrl); } if (!isset($_POST['msg']) || empty($_POST['msg'])) { return fctErrorMSG('Vous devez entrer un message expliquant l\'action. (ex.: veuillez lever les bras.)', $errorUrl); } //Valider que le personnage à fouiller est bel et bien dans le lieu actuel $i = 0; $found = false; while ($tmp = $perso->getLieu()->getPerso($perso, $i++)) { if ($tmp->getId() == $_POST['persoid']) { $found = true; break; } } if (!$found) { return fctErrorMSG('Le personnage que vous avez sélectionné ne se situe pas dans le même lieu que vous.', $errorUrl); } //Tout est OK, créer et envoyer la demande de Fouille //Si une ancienne demande existait, la supprimer, de facon à la renouveller $query = 'DELETE FROM ' . DB_PREFIX . 'perso_fouille' . ' WHERE fromid = ' . (int) $perso->getId() . ' AND toid = ' . (int) $_POST['persoid'] . ' LIMIT 1;'; $db->queryPlus($query, __FILE__, __LINE__); //Créer la demande $query = 'INSERT INTO ' . DB_PREFIX . 'perso_fouille' . ' (`fromid`, `toid`, `expiration`, `reponse`)' . ' VALUES' . ' (:fromId, :toId, UNIX_TIMESTAMP(), 0);'; $prep = $db->prepare($query); $prep->bindValue(':fromId', $perso->getId(), PDO::PARAM_INT); $prep->bindValue(':toId', $_POST['persoid'], PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Soumettre le message confirmant la demande $msg = fctScriptProtect($_POST['msg']); Member_He::add($perso->getId(), (int) $_POST['persoid'], 'fouille', $msg . "\n[HJ: Acceptez-vous de vous laisser fouiller? [<a href=\"?m=Action_Perso_FouillerGo&id=" . (int) $perso->getId() . "&choix=1\">Oui</a>/<a href=\"?m=Action_Perso_FouillerGo&id=" . (int) $perso->getId() . "&choix=0\">Non</a>]]", HE_AUCUN, HE_TOUS, false); Member_He::add($perso->getId(), (int) $_POST['persoid'], 'fouille', $msg . "\n[HJ: En attente de la réponse du joueur ...]", HE_TOUS, HE_AUCUN, false); //Rafraichir le HE return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/herefresh.htm', __FILE__, __LINE__); }
public static function generatePage(&$tpl, &$session, &$account, &$perso) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante $errorUrl = '?popup=1&m=ContactMj'; if (!isset($_POST['type']) || !isset($_POST['titre']) || !isset($_POST['msg'])) { return fctErrorMSG('Données requises manquantes.', $errorUrl); } if (empty($_POST['titre'])) { return fctErrorMSG('Vous devez remplir tout les champs (1).', $errorUrl); } if (empty($_POST['msg'])) { return fctErrorMSG('Vous devez remplir tout les champs (2).', $errorUrl); } $query = 'SELECT COUNT(*)' . ' FROM ' . DB_PREFIX . 'ppa' . ' WHERE persoid=:persoId' . ' AND statut="ouvert";'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arr = $prep->fetch(); if ($arr[0] >= PPA_MAX) { return fctErrorMSG('Vous avez atteind votre maximum de ticket ouvert.', $errorUrl); } $query = 'INSERT INTO ' . DB_PREFIX . 'ppa' . ' (`persoid`, `type`, `date`, `mjid`, `titre`, `msg`, `lieu`, `pa`, `paMax`, `pv`, `pvMax`)' . ' VALUES' . ' (:persoId, :type, UNIX_TIMESTAMP(), 0, :titre, :msg, :lieu, :pa, :paMax, :pv, :pvMax);'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->bindValue(':type', $_POST['type'], PDO::PARAM_STR); $prep->bindValue(':titre', fctScriptProtect($_POST['titre']), PDO::PARAM_STR); $prep->bindValue(':msg', fctScriptProtect($_POST['msg']), PDO::PARAM_STR); $prep->bindValue(':lieu', $perso->getLieu()->getNomTech(), PDO::PARAM_STR); $prep->bindValue(':pa', $perso->getPa(), PDO::PARAM_STR); $prep->bindValue(':paMax', $perso->getPaMax(), PDO::PARAM_STR); $prep->bindValue(':pv', $perso->getPv(), PDO::PARAM_STR); $prep->bindValue(':pvMax', $perso->getPvMax(), PDO::PARAM_STR); $prep->executePlus($db, __FILE__, __LINE__); //Copier le message dans les HE Member_He::add($perso->getId(), 'MJ', 'ppa', $_POST['msg']); //Retourner le template complété/rempli $tpl->set('PAGE', '?popup=1&m=ContactMj'); return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/action_redirect.htm', __FILE__, __LINE__); }
/** Ajoute un message dans un ou des HE. * * Exemple d'utilisation - Ajouter un message Système au personnage #801: * <code> * $he::add('System', 801, 'remise', 'Remise de PA effectué.'); * </code> * <br> * Exemple d'utilisation - Envoyer un message du personnage #801 à 3 personnages: * <code> * $arrToPerso = array{545, 656, 701}; * Member_He::add(801, $arrToPerso, 'msg', 'Salut les gars !'); * </code> * <br> * Exemple d'utilisation - Envoyer un message du personnage joué à tous les personnages du lieu actuel: * <code> * while( $arrPerso = $perso->getLieu()->getPerso($perso, $i++)) * $arrIdPerso = $arrPerso->getId() * * Member_He::add($perso->getId(), $arrIdPerso , 'msg', 'Salut à tlm !'); * </code> * <br> * <br> * <br>Valeurs possibles pour $fromshow et $toshow: * - HE_AUCUN : Ne pas afficher le message aux gens de cette liste. * - HE_TOUS : Afficher le message aux gens de cette liste. * - HE_UNIQUEMENT_MOI : Afficher le message aux gens de cette liste, mais ne pas leurs afficher la liste, excepté eux-même. * * @param int $from Id ou nom du ou des envoyeur(s) du message. Peut être un int ou un tableau d'int * @param int $to Id ou nom du ou des récepteur(s) du message. Peut être un int ou un tableau d'int * @param string $type Type du message (techniquement utile pour la suppression des déplacement ou le tri par type de message) * @param string $msg Message * @param bool $fromshow Afficher le message à l'/les envoyeur(s) (par défaut à HE_TOUS) * @param bool $toshow Afficher le message à l'/les récepteur(s) (par défaut à HE_TOUS) * @param bool $msgProtect Protège le message en supprimant les balises HTML(par défaut à true) * @return int Retourne l'ID du message ajouté */ public static function add($from = null, $to = null, $type = '', $msg = '', $fromshow = HE_TOUS, $toshow = HE_TOUS, $msgProtect = true) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante if (!is_numeric($fromshow)) { throw new Exception('Valeur du paramètre fromshow non-numérique. Corrigez l\'appel à Member_He::add'); return false; } if (!is_numeric($toshow)) { throw new Exception('Valeur du paramètre toshow non-numérique. Corrigez l\'appel à Member_He::add'); return false; } //Préparer les requêtes FromTo //############################################################## $query = 'INSERT INTO `' . DB_PREFIX . 'he_fromto`' . ' (`msgid`, `fromto`, `persoid`, `lieuid`, `masque`, `show`, `id_description`, `name_complement`)' . ' VALUES' . ' (:msgId, :fromTo, :persoId, :lieuId, :masque, :show, :idDescription, :nameComplement);'; $prepAddFromTo = $db->prepare($query); //############################################################## //NULL = Message systeme (0) if ($from === NULL) { $from = array(0); } if ($to === NULL) { $to = array(0); } //Si les paramètres ne sont pas un tableau, les placer dans un tableau if (!is_array($from)) { $from = array($from); } if (!is_array($to)) { $to = array($to); } //Valider si on essaie d'envoyer un message à au moins 1 joueur (un ID) $fromCheck = is_array($from) && count($from) > 0 && is_numeric($from[0]); $toCheck = is_array($to) && count($to) > 0 && is_numeric($to[0]); if (!$fromCheck && !$toCheck) { throw new Exception('Aucune correspondance tangible au message. Ajoutez un From ou un To. Corrigez l\'appel à Member_He::add'); return false; } //### Créer le message if ($msgProtect) { $msg = fctScriptProtect($msg); } try { $db->beginTransaction(); $query = 'INSERT INTO `' . DB_PREFIX . 'he`' . ' (`date`, `type`, `msg`)' . ' VALUES (' . ' UNIX_TIMESTAMP(),' . ' :type,' . ' :msg' . ' );'; $prep = $db->prepare($query); $prep->bindValue(':type', $type, PDO::PARAM_STR); $prep->bindValue(':msg', $msg, PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; $msgId = $db->lastInsertId(); //Récupérer l'ID du message inséré. //Créer les lien FROMTO (Insérer "from") self::addFromTo($msgId, 'from', $from, $fromshow, $type, $prepAddFromTo); //Créer les lien FROMTO (Insérer "to") self::addFromTo($msgId, 'to', $to, $toshow, $type, $prepAddFromTo); //Sauvegarder les modifications $db->commit(); return $msgId; } catch (exception $e) { $db->rollback(); throw $e; return false; } }
public static function generatePage(&$tpl, &$session, &$account) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante //$errorUrl = défini plus bas if (!isset($_GET['id'])) { return fctErrorMSG('Données requises manquantes. (cheat)'); } //Trouver les informations sur le perso / Valider s'il est authorisé à être modifié $query = 'SELECT id' . ' FROM ' . DB_PREFIX . 'perso' . ' WHERE id=:id' . ' AND userid=:userId' . ' AND inscription_valide IN ("0", "mod")' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':id', $_GET['id'], PDO::PARAM_INT); $prep->bindValue(':userId', $account->getId(), PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $arr = $prep->fetch(); $prep->closeCursor(); $prep = NULL; if ($arr === false) { return fctErrorMSG('Ce personnage n\'existe pas, ne vous appartiend pas, ou n\'est pas en phase de refus. (cheat)'); } $persoId = $arr[0]; $errorUrl = '?m=ModPerso&id=' . $persoId; //Si les magicQuote sont activer, les retirer. fctStripMagicQuote($_POST); //Validation du NOM if (!isset($_POST['nom']) || empty($_POST['nom'])) { return fctErrorMSG('Nom de personnage manquant.', $errorUrl, $_POST, false); } if (strlen($_POST['nom']) > 25 || strlen($_POST['nom']) < 4) { return fctErrorMSG('Le nom du personnage à une taille invalide.', $errorUrl, $_POST, false); } preg_match('/^[-\' çéèôêîA-Za-z]+$/', $_POST['nom'], $matches); if (count($matches) == 0) { return fctErrorMSG('Le nom du personnage comporte des caractères invalide (' . $_POST['nom'] . ').', $errorUrl, $_POST, false); } $query = 'SELECT id' . ' FROM ' . DB_PREFIX . 'perso' . ' WHERE nom=:nom' . ' AND id!=:id' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':nom', $_POST['nom'], PDO::PARAM_STR); $prep->bindValue(':id', $_GET['id'], PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $arr = $prep->fetch(); $prep->closeCursor(); $prep = NULL; if ($arr !== false) { return fctErrorMSG('Ce nom est déjà utilisé par un autre personnage que le vôtre.', $errorUrl, $_POST, false); } //Validation de l'ETHNIE if (!isset($_POST['ethnie']) || empty($_POST['ethnie'])) { return fctErrorMSG('Ethnie du personnage manquant.', $errorUrl, $_POST, false); } //Validation de l'AGE if (!isset($_POST['age']) || empty($_POST['age'])) { return fctErrorMSG('Âge du personnage manquant.', $errorUrl, $_POST, false); } preg_match('/^[0-9]{1,2}$/', $_POST['age'], $matches); if (count($matches) == 0) { return fctErrorMSG('L\'âge du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation du POIDS if (!isset($_POST['poids']) || empty($_POST['poids'])) { return fctErrorMSG('Poids du personnage manquant.', $errorUrl, $_POST, false); } preg_match('/^[0-9]{1,3}$/', $_POST['poids'], $matches); if (count($matches) == 0) { return fctErrorMSG('Le poids du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation de la TAILLE if (!isset($_POST['taillem']) || empty($_POST['taillem'])) { return fctErrorMSG('Taille du personnage manquante (1).', $errorUrl, $_POST, false); } if (!isset($_POST['taillecm']) || empty($_POST['taillecm'])) { return fctErrorMSG('Taille du personnage manquante (2).', $errorUrl, $_POST, false); } $taille = $_POST['taillem'] . 'm' . $_POST['taillecm']; preg_match('/^[12][m][0-9][05]$/', $taille, $matches); if (count($matches) == 0) { return fctErrorMSG('La taille du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation des YEUX if (!isset($_POST['yeux']) || empty($_POST['yeux'])) { return fctErrorMSG('Description des yeux du personnage manquante.', $errorUrl, $_POST, false); } if (strlen($_POST['yeux']) > 100) { return fctErrorMSG('mod - Description des yeux du personnage à une taille invalide (' . strlen($_POST['yeux']) . ').', $errorUrl, $_POST, false); } //Validation des CHEVEUX if (!isset($_POST['cheveux']) || empty($_POST['cheveux'])) { return fctErrorMSG('mod - Description des cheveux du personnage manquante.', $errorUrl, $_POST, false); } if (strlen($_POST['cheveux']) > 100) { return fctErrorMSG('Description des cheveux du personnage à une taille invalide (' . strlen($_POST['cheveux']) . ').', $errorUrl, $_POST, false); } //Effectuer la liste de toutes les statistiques $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'stat;'; $prep = $db->prepare($query); $prep->execute($db, __FILE__, __LINE__); $arrStat = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; //Validation des STATS $totalStat = 0; foreach ($arrStat as $stat) { $fieldName = 'stat_' . $stat['id']; if (!isset($_POST[$fieldName]) || !is_numeric($_POST[$fieldName]) || $_POST[$fieldName] < -75 || $_POST[$fieldName] > 75) { return fctErrorMSG('Données sur les statistiques invalides.', $errorUrl, $_POST, false); } $totalStat += $_POST[$fieldName]; } if ($totalStat != 0) { return fctErrorMSG('Les statistiques doivent avoir une somme de zéro.', $errorUrl, $_POST, false); } //Effectuer la liste de toutes les compétences $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'competence' . ' WHERE inscription="1";'; $prep = $db->prepare($query); $prep->execute($db, __FILE__, __LINE__); $arrComp = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; //Validation des COMPS $totalComp = 0; foreach ($arrComp as $comp) { $fieldName = 'comp_' . $comp['id']; if (!isset($_POST[$fieldName]) || !is_numeric($_POST[$fieldName]) || $_POST[$fieldName] < 0 || $_POST[$fieldName] > INSCRIPTION_MAX_COMP) { return fctErrorMSG('Données sur les compétences invalides.', $errorUrl, $_POST, false); } $totalComp += $_POST[$fieldName]; } if ($totalComp != INSCRIPTION_NBR_COMP) { return fctErrorMSG('Les compétences doivent avoir une somme de ' . INSCRIPTION_NBR_COMP . '.', $errorUrl, $_POST, false); } //Validation SIGNES if (!isset($_POST['arrCaract'])) { return fctErrorMSG('Sélection des signes du personnage manquante.', $errorUrl, $_POST, false); } if (count($_POST['arrCaract']) < 5) { return fctErrorMSG('Données sur les signes invalides.', $errorUrl, $_POST, false); } //Validation Background + Description if (!isset($_POST['description']) || empty($_POST['description'])) { return fctErrorMSG('Description du personnage manquante.', $errorUrl, $_POST, false); } if (!isset($_POST['background']) || empty($_POST['background'])) { return fctErrorMSG('Historique du personnage manquante.', $errorUrl, $_POST, false); } // FIN DES VALIDATION, EFFECTUER LA MISE A JOUR. //Modifier le personnage $query = 'UPDATE ' . DB_PREFIX . 'perso' . ' SET' . ' `nom` = :nom,' . ' `sexe` = :sexe,' . ' `age` = :age,' . ' `taille` = :taille,' . ' `yeux` = :yeux,' . ' `ethnie` = :ethnie,' . ' `cheveux` = :cheveux,' . ' `poids` = :poids,' . ' `lng1_lvl` = :lng1_lvl,' . ' `lng2` = :lng2,' . ' `lng2_lvl` = :lng2_lvl,' . ' `description` = :description,' . ' `background` = :background,' . ' `inscription_valide`= :saveType' . ' WHERE id=:persoId' . ' LIMIT 1;'; $prep = $db->prepare($query); $saveType = $_POST['SaveType'] == 'go' ? '0' : 'mod'; $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':nom', $_POST['nom'], PDO::PARAM_STR); $prep->bindValue(':sexe', $_POST['sexe'], PDO::PARAM_STR); $prep->bindValue(':age', $_POST['age'], PDO::PARAM_INT); $prep->bindValue(':taille', $taille, PDO::PARAM_STR); $prep->bindValue(':yeux', $_POST['yeux'], PDO::PARAM_STR); $prep->bindValue(':ethnie', $_POST['ethnie'], PDO::PARAM_STR); $prep->bindValue(':cheveux', $_POST['cheveux'], PDO::PARAM_STR); $prep->bindValue(':poids', $_POST['poids'], PDO::PARAM_INT); $prep->bindValue(':lng1_lvl', $_POST['lng1_lvl'], PDO::PARAM_STR); $prep->bindValue(':lng2', $_POST['lng2'], PDO::PARAM_STR); $prep->bindValue(':lng2_lvl', $_POST['lng2_lvl'], PDO::PARAM_STR); $prep->bindValue(':description', $_POST['description'], PDO::PARAM_STR); $prep->bindValue(':background', $_POST['background'], PDO::PARAM_STR); $prep->bindValue(':saveType', $saveType, PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Effacer les informations sur les statistiques $query = 'DELETE FROM ' . DB_PREFIX . 'perso_stat' . ' WHERE persoid=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Insérer les stats $query = 'INSERT INTO ' . DB_PREFIX . 'perso_stat' . ' (`persoid`, `statid`, `xp`)' . ' VALUES' . ' (:persoId, :statId, :xp);'; $prep = $db->prepare($query); foreach ($arrStat as $stat) { $statXp = $_POST['stat_' . $stat['id']]; $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':statId', $stat['id'], PDO::PARAM_INT); $prep->bindValue(':xp', $statXp, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); } $prep->closeCursor(); $prep = NULL; //Effacer les informations sur les compétences $query = 'DELETE FROM ' . DB_PREFIX . 'perso_competence' . ' WHERE persoid=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Insérer les compétences $query = 'INSERT INTO ' . DB_PREFIX . 'perso_competence' . ' (`persoid`, `compid`, `xp`)' . ' VALUES' . ' (:persoId, :compId, :xp);'; $prep = $db->prepare($query); foreach ($arrComp as $comp) { $fn = 'comp_' . $comp['id']; if (isset($_POST[$fn]) && is_numeric($_POST[$fn]) && $_POST[$fn] > 0) { $compXp = Member_Perso::convCompLevelToXp($_POST[$fn]); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':compId', $comp['id'], PDO::PARAM_INT); $prep->bindValue(':xp', $compXp, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); } } $prep->closeCursor(); $prep = NULL; //Effacer les informations sur les anciennes caractéristiques $query = 'DELETE FROM ' . DB_PREFIX . 'perso_caract' . ' WHERE persoid=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Ajouter les informations sur les caractéristiques $query = 'INSERT INTO ' . DB_PREFIX . 'perso_caract' . ' ( `persoid` , `caractid` , `desc` )' . ' VALUES' . ' (:persoId, :caractId, :desc);'; $prep = $db->prepare($query); foreach ($_POST['arrCaract'] as $caract) { $desc = fctScriptProtect($_POST['caractDesc_' . $caract]); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':caractId', $caract, PDO::PARAM_INT); $prep->bindValue(':desc', $desc, PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); } $prep->closeCursor(); $prep = NULL; //Retourner le template complété/rempli $tpl->set('PAGE', 'News'); //return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/redirect.htm',__FILE__,__LINE__); }
public static function generatePage(&$tpl, &$session, &$account, &$perso) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { return fctErrorMSG('Données requises manquantes.'); } //Ajouter un message au PPA if (isset($_POST['form_action']) && ($_POST['form_action'] == 'reply' || $_POST['form_action'] == 'del' && !empty($_POST['msg']))) { $query = 'INSERT INTO ' . DB_PREFIX . 'ppa_reponses' . ' (`sujetid`, `mjid`, `date`, `msg`)' . ' VALUES' . ' (:sujetId, 0, UNIX_TIMESTAMP(), :msg);'; $prep = $db->prepare($query); $prep->bindValue(':sujetId', $_GET['id'], PDO::PARAM_INT); $prep->bindValue(':msg', fctScriptProtect($_POST['msg']), PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); //Copier le message dans les HE Member_He::add($perso->getId(), 'MJ', 'ppa', $_POST['msg']); } //Fermer le PPA if (isset($_POST['form_action']) && $_POST['form_action'] == 'del') { $query = 'UPDATE ' . DB_PREFIX . 'ppa' . ' SET statut="ferme"' . ' WHERE id=:sujetId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':sujetId', $_GET['id'], PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $tpl->set('PAGE', '?popup=1&m=ContactMj'); return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/action_redirect.htm', __FILE__, __LINE__); } //Trouver les PPA demandé $query = 'SELECT m.id, m.msg, m.`date`, m.statut, mj.nom as mjnom' . ' FROM ' . DB_PREFIX . 'ppa as m' . ' LEFT JOIN ' . DB_PREFIX . 'mj as mj ON (mj.id = m.mjid) ' . ' WHERE m.id=:sujetId' . ' AND persoid=:persoId' . ' LIMIT 1'; $prep = $db->prepare($query); $prep->bindValue(':sujetId', $_GET['id'], PDO::PARAM_INT); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $arr = $prep->fetch(); if ($arr === false) { return fctErrorMSG('Ppa innexistant.'); } $PPA = array(); $i = 0; //Afficher le message de base (Le PPA) $PPA[$i] = $arr; $PPA[$i]['msg'] = BBCodes(stripslashes($PPA[$i]['msg'])); $PPA[$i]['date'] = fctToGameTime($arr['date']); $PPA[$i]['de'] = $perso->getNom(); $i++; //Afficher les réponses $query = 'SELECT p.*, mj.nom as mjnom' . ' FROM ' . DB_PREFIX . 'ppa_reponses as p' . ' LEFT JOIN ' . DB_PREFIX . 'mj as mj ON (mj.id = p.mjid)' . ' WHERE p.sujetid=:sujetId' . ' ORDER BY p.`date` ASC;'; $prep = $db->prepare($query); $prep->bindValue(':sujetId', $_GET['id'], PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $arrM = $prep->fetchAll(); if (count($arrM) != 0) { foreach ($arrM as $arr) { $PPA[$i] = $arr; $PPA[$i]['msg'] = BBCodes(stripslashes($PPA[$i]['msg'])); $PPA[$i]['date'] = fctToGameTime($arr['date']); if (empty($arr['mjnom'])) { $PPA[$i]['de'] = $perso->getNom(); } else { $PPA[$i]['de'] = stripslashes($arr['mjnom']); } $i++; } } $tpl->set('PPA', $PPA); return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/contactMjMod.htm', __FILE__, __LINE__); }
public static function generatePage(&$tpl, &$session, &$account) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante $errorUrl = '?m=CreerPerso2'; //Si les magicQuote sont activer, les retirer. fctStripMagicQuote($_POST); //Déterminer la quantité de perso que ce compte à l'autorisation de créer $query = 'SELECT auth_creation_perso' . ' FROM ' . DB_PREFIX . 'account' . ' WHERE id=:id' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':id', $account->getId(), PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $arr = $prep->fetch(); $prep->closeCursor(); $prep = NULL; if ($arr['auth_creation_perso'] == 0) { return fctErrorMSG('Vous n\'avez pas l\'autorisation de créer un personnage. (cheat)', '?m=News', null, false); } //Validation du NOM if (!isset($_POST['nom']) || empty($_POST['nom'])) { return fctErrorMSG('Nom de personnage manquant.', $errorUrl, $_POST, false); } if (strlen($_POST['nom']) > 25 || strlen($_POST['nom']) < 4) { return fctErrorMSG('Le nom du personnage à une taille invalide.', $errorUrl, $_POST, false); } preg_match('/^[-\' çéèôêîA-Za-z]+$/', $_POST['nom'], $matches); if (count($matches) == 0) { return fctErrorMSG('Le nom du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } $query = 'SELECT id' . ' FROM ' . DB_PREFIX . 'perso' . ' WHERE nom=:nom' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':nom', $_POST['nom'], PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); $arr = $prep->fetch(); $prep->closeCursor(); $prep = NULL; if ($arr !== false) { return fctErrorMSG('Ce nom est déjà utilisé.', $errorUrl, $_POST, false); } //Validation de l'ETHNIE if (!isset($_POST['ethnie']) || empty($_POST['ethnie'])) { return fctErrorMSG('Ethnie du personnage manquant.', $errorUrl, $_POST, false); } //Validation de l'AGE if (!isset($_POST['age']) || empty($_POST['age'])) { return fctErrorMSG('Âge du personnage manquant.', $errorUrl, $_POST, false); } preg_match('/^[0-9]{1,2}$/', $_POST['age'], $matches); if (count($matches) == 0) { return fctErrorMSG('L\'âge du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation du POIDS if (!isset($_POST['poids']) || empty($_POST['poids'])) { return fctErrorMSG('Poids du personnage manquant.', $errorUrl, $_POST, false); } preg_match('/^[0-9]{1,3}$/', $_POST['poids'], $matches); if (count($matches) == 0) { return fctErrorMSG('Le poids du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation de la TAILLE if (!isset($_POST['taillem']) || empty($_POST['taillem'])) { return fctErrorMSG('Taille du personnage manquante (1).', $errorUrl, $_POST, false); } if (!isset($_POST['taillecm']) || empty($_POST['taillecm'])) { return fctErrorMSG('Taille du personnage manquante (2).', $errorUrl, $_POST, false); } $taille = $_POST['taillem'] . 'm' . $_POST['taillecm']; preg_match('/^[12][m][0-9][05]$/', $taille, $matches); if (count($matches) == 0) { return fctErrorMSG('La taille du personnage comporte des caractères invalide.', $errorUrl, $_POST, false); } //Validation des YEUX if (!isset($_POST['yeux']) || empty($_POST['yeux'])) { return fctErrorMSG('Description des yeux du personnage manquante.', $errorUrl, $_POST, false); } if (strlen($_POST['yeux']) > 100) { return fctErrorMSG('add - Description des yeux du personnage à une taille invalide (' . strlen($_POST['yeux']) . ').', $errorUrl, $_POST, false); } //Validation des CHEVEUX if (!isset($_POST['cheveux']) || empty($_POST['cheveux'])) { return fctErrorMSG('Description des cheveux du personnage manquante.', $errorUrl, $_POST, false); } if (strlen($_POST['cheveux']) > 100) { return fctErrorMSG('add - Description des cheveux du personnage à une taille invalide (' . strlen($_POST['cheveux']) . ').', $errorUrl, $_POST, false); } //Effectuer la liste de toutes les statistiques $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'stat;'; $prep = $db->prepare($query); $prep->execute($db, __FILE__, __LINE__); $arrStat = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; //Validation des STATS $totalStat = 0; foreach ($arrStat as &$stat) { $fieldName = 'stat_' . $stat['id']; if (!isset($_POST[$fieldName]) || !is_numeric($_POST[$fieldName]) || $_POST[$fieldName] < -75 || $_POST[$fieldName] > 75) { return fctErrorMSG('Données sur les stats invalides.', $errorUrl, $_POST, false); } $totalStat += $_POST[$fieldName]; } if ($totalStat != 0) { return fctErrorMSG('Les statistiques doivent avoir une somme de zéro.', $errorUrl, $_POST, false); } //Effectuer la liste de toutes les compétences $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'competence' . ' WHERE inscription="1";'; $prep = $db->prepare($query); $prep->execute($db, __FILE__, __LINE__); $arrComp = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; //Validation des COMPS $totalComp = 0; foreach ($arrComp as &$comp) { $fieldName = 'comp_' . $comp['id']; if (!isset($_POST[$fieldName]) || !is_numeric($_POST[$fieldName]) || $_POST[$fieldName] < 0 || $_POST[$fieldName] > INSCRIPTION_MAX_COMP) { return fctErrorMSG('Données sur les compétences invalides.', $errorUrl, $_POST, false); } $totalComp += $_POST[$fieldName]; } if ($totalComp != INSCRIPTION_NBR_COMP) { return fctErrorMSG('Les compétences doivent avoir une somme de ' . INSCRIPTION_NBR_COMP . '.', $errorUrl, $_POST, false); } //Validation SIGNES if (!isset($_POST['arrCaract'])) { return fctErrorMSG('Sélection des caractéristiques du personnage manquante.', $errorUrl, $_POST, false); } if (count($_POST['arrCaract']) < 5) { return fctErrorMSG('Vous n\'avez sélectionné que ' . count($_POST['arrCaract']) . ' caractéristique(s).', $errorUrl, $_POST, false); } //Validation Background + Description if (!isset($_POST['description']) || empty($_POST['description'])) { return fctErrorMSG('Description du personnage manquante.', $errorUrl, $_POST, false); } if (!isset($_POST['background']) || empty($_POST['background'])) { return fctErrorMSG('Historique du personnage manquante.', $errorUrl, $_POST, false); } //Protéger tout les champs de premier niveau foreach ($_POST as &$elem) { if (!is_array($elem)) { $elem = fctScriptProtect($elem); } } //Créer le personnage if (isset($_POST['go'])) { $Pstatus = '0'; } if (isset($_POST['save'])) { $Pstatus = 'mod'; } try { $db->beginTransaction(); $query = 'INSERT INTO ' . DB_PREFIX . 'perso' . ' (' . ' `userId`, `nom`, `sexe`, `age`, `taille`, `yeux`,' . ' `ethnie`, `cheveux`, `poids`,' . ' `lng1`, `lng1_lvl`, `lng2`, `lng2_lvl`,' . ' `lieu`, `description`, `background`, `inscription_valide`' . ' )' . ' VALUES' . ' (' . ' :userId, :nom, :sexe, :age, :taille, :yeux,' . ' :ethnie, :cheveux, :poids,' . ' "en", :lng1_lvl, :lng2, :lng2_lvl,' . ' :lieu, :description, :background, :saveType' . ' );'; $prep = $db->prepare($query); $saveType = $_POST['SaveType'] == 'go' ? '0' : 'mod'; $prep->bindValue(':userId', $account->getId(), PDO::PARAM_INT); $prep->bindValue(':nom', $_POST['nom'], PDO::PARAM_STR); $prep->bindValue(':sexe', $_POST['sexe'], PDO::PARAM_STR); $prep->bindValue(':age', $_POST['age'], PDO::PARAM_INT); $prep->bindValue(':taille', $taille, PDO::PARAM_STR); $prep->bindValue(':yeux', $_POST['yeux'], PDO::PARAM_STR); $prep->bindValue(':ethnie', $_POST['ethnie'], PDO::PARAM_STR); $prep->bindValue(':cheveux', $_POST['cheveux'], PDO::PARAM_STR); $prep->bindValue(':poids', $_POST['poids'], PDO::PARAM_STR); $prep->bindValue(':lng1_lvl', $_POST['lng1_lvl'], PDO::PARAM_STR); $prep->bindValue(':lng2', $_POST['lng2'], PDO::PARAM_STR); $prep->bindValue(':lng2_lvl', $_POST['lng2_lvl'], PDO::PARAM_STR); $prep->bindValue(':lieu', INNACTIVITE_VOLUNTARY_LOCATION, PDO::PARAM_STR); $prep->bindValue(':description', $_POST['description'], PDO::PARAM_STR); $prep->bindValue(':background', $_POST['background'], PDO::PARAM_STR); $prep->bindValue(':saveType', $saveType, PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; $persoId = $db->lastInsertId(); //Insérer les stats $query = 'INSERT INTO ' . DB_PREFIX . 'perso_stat' . ' (`persoid`, `statid`, `xp`)' . ' VALUES' . ' (:persoId, :statId, :xp);'; $prep = $db->prepare($query); foreach ($arrStat as &$stat) { $statXp = $_POST['stat_' . $stat['id']]; $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':statId', $stat['id'], PDO::PARAM_INT); $prep->bindValue(':xp', $statXp, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); } $prep->closeCursor(); $prep = NULL; //Insérer les compétences $query = 'INSERT INTO ' . DB_PREFIX . 'perso_competence' . ' (`persoid`, `compid`, `xp`)' . ' VALUES' . ' (:persoId, :compId, :xp);'; $prep = $db->prepare($query); foreach ($arrComp as &$comp) { $fn = 'comp_' . $comp['id']; if (isset($_POST[$fn]) && is_numeric($_POST[$fn]) && $_POST[$fn] > 0) { $compXp = Member_Perso::convCompLevelToXp($_POST[$fn]); $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':compId', $comp['id'], PDO::PARAM_INT); $prep->bindValue(':xp', $compXp, PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); } } $prep->closeCursor(); $prep = NULL; //Ajouter les informations sur les Signes $query = 'INSERT INTO ' . DB_PREFIX . 'perso_caract' . ' (`persoid`, `caractid`, `desc`)' . ' VALUES' . ' (:persoId, :caractId, :desc);'; $prep = $db->prepare($query); foreach ($_POST['arrCaract'] as &$caract) { $desc = $_POST['caractDesc_' . $caract]; $prep->bindValue(':persoId', $persoId, PDO::PARAM_INT); $prep->bindValue(':caractId', $caract, PDO::PARAM_INT); $prep->bindValue(':desc', $desc, PDO::PARAM_STR); $prep->execute($db, __FILE__, __LINE__); } $prep->closeCursor(); $prep = NULL; //Baisser le nombre de création de perso de 1 $query = 'UPDATE ' . DB_PREFIX . 'account' . ' SET auth_creation_perso=auth_creation_perso-1' . ' WHERE id=:userId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':userId', $account->getId(), PDO::PARAM_INT); $prep->execute($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Sauvegarder la liste des personnages du compte $perso_list = array(); $perso_list = $session->getVar('persoList'); $perso_list[] = array('id' => $persoId, 'nom' => $_POST['nom']); $session->setVar('persoList', $perso_list); $db->commit(); } catch (exception $e) { $db->rollback(); var_dump($e); throw $e; } //Retourner le template complété/rempli $tpl->set('PAGE', 'News'); return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/redirect.htm', __FILE__, __LINE__); }
public static function generatePage(&$tpl, &$session, &$account, &$perso) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante $errorUrl = '?popup=1&m=Action_Item_Menotter'; if (!isset($_POST['inv_id'])) { return fctErrorMSG('Vous devez sélectionner un item permettant le menottage.', $errorUrl); } if (!isset($_POST['toPersoId'])) { return fctErrorMSG('Vous devez sélectionner une personne à menotter.', $errorUrl); } if (!isset($_POST['msg']) || empty($_POST['msg'])) { return fctErrorMSG('Vous devez entrer un message expliquant l\'action. (ex.: lecture des droits)', $errorUrl); } //Lister tous les items en inventaire $i = 0; $arrInv = array(); while ($item = $perso->getInventaire($i++)) { $arrInv[] = $item->getDbId(); } $queryIn = implode(',', $arrInv); //Valider que l'item appartient au perso ET qu'il sert a menotter $query = 'SELECT item_dbid' . ' FROM ' . DB_PREFIX . 'item_menu' . ' WHERE item_dbid IN (' . $queryIn . ')' . ' AND url="Menotter";'; $prep = $db->prepare($query); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; $found = false; foreach ($arrAll as &$arr) { $i = 0; while ($item = $perso->getInventaire($i++)) { //Liste de tout les items du perso if ($item->getInvId() == $_POST['inv_id'] && $item->getDbId() == $arr['item_dbid'] && !$item->isEquip()) { //S'il y a correspondance, ajouter l'item à la liste à afficher $found = true; break 2; } } } if (!$found) { return fctErrorMSG('Vous devez utiliser un item en votre possession permettant le menottage.', $errorUrl); } //Valider que le personnage à menotter est bel et bien dans le lieu actuel $i = 0; $found = false; $persoDansLeLieuActuel = array(); while ($tmp = $perso->getLieu()->getPerso($perso, $i++)) { if ($tmp->getId() == $_POST['toPersoId']) { $found = true; break; } } if (!$found) { return fctErrorMSG('Le personnage que vous avez sélectionné ne se situe pas dans le même lieu que vous.', $errorUrl); } //Tout est OK, créer et envoyer la demande de Menottage $menId = $_POST['inv_id']; //Si une ancienne demande existait, la supprimer, de facon à la renouveller $query = 'DELETE FROM ' . DB_PREFIX . 'perso_menotte' . ' WHERE inv_id =:itemId' . ' AND to_id=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':itemId', $menId, PDO::PARAM_INT); $prep->bindValue(':persoId', $_POST['toPersoId'], PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Créer la demande $query = 'INSERT INTO ' . DB_PREFIX . 'perso_menotte' . ' (inv_id, to_id, expiration)' . ' VALUES' . ' (:itemId, :persoId, UNIX_TIMESTAMP());'; $prep = $db->prepare($query); $prep->bindValue(':itemId', $menId, PDO::PARAM_INT); $prep->bindValue(':persoId', $_POST['toPersoId'], PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Soumettre le message confirmant la demande $msg = fctScriptProtect($_POST['msg']); Member_He::add($perso->getId(), (int) $_POST['toPersoId'], 'menotte', $msg . "\n[HJ: Acceptez-vous de vous laisser attacher ou menotter? [<a href=\"?m=Action_Item_MenotterGo&id={$menId}&choix=1\">Oui</a>/<a href=\"?m=Action_Item_MenotterGo&id={$menId}&choix=0\">Non</a>]]", HE_AUCUN, HE_TOUS, false); Member_He::add($perso->getId(), (int) $_POST['toPersoId'], 'menotte', $msg . "\n[HJ: En attente de la réponse du joueur ...]", HE_TOUS, HE_AUCUN, false); //Rafraichir le HE return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Member/herefresh.htm', __FILE__, __LINE__); }
public static function generatePage(&$tpl, &$session, &$account, &$mj) { $dbMgr = DbManager::getInstance(); //Instancier le gestionnaire $db = $dbMgr->getConn('game'); //Demander la connexion existante if (isset($_POST['save'])) { //Fetcher toutes les informations concernant le perso $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'perso' . ' WHERE id=:persoId' . ' LIMIT 1;'; $prepP = $db->prepare($query); $prepP->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prepP->executePlus($db, __FILE__, __LINE__); $arr = $prepP->fetch(); $perso = new Member_Perso($arr); //Vérifier tout ce qui a changé $msg = array(); if ($perso->getUserId() != $_POST['userId']) { $msg[] = 'UserId: ' . $_POST['userId']; } if ($perso->getNom() != $_POST['nom']) { $msg[] = 'Nom: ' . $_POST['nom']; } if ($perso->getSexe() != $_POST['sexe']) { $msg[] = 'Sexe: ' . $_POST['sexe']; } if ($perso->getAge() != $_POST['age']) { $msg[] = 'Age: ' . $_POST['age']; } if ($perso->getTaille() != $_POST['taille']) { $msg[] = 'Taille: ' . $_POST['taille']; } if ($perso->getEthnie() != $_POST['ethnie']) { $msg[] = 'Ethnie: ' . $_POST['ethnie']; } if ($perso->getYeux() != $_POST['yeux']) { $msg[] = 'Yeux: ' . $_POST['yeux']; } if ($perso->getCheveux() != $_POST['cheveux']) { $msg[] = 'Cheveux: ' . $_POST['cheveux']; } if ($perso->getType() != $_POST['playertype']) { $msg[] = 'Type: ' . $_POST['playertype']; } if ($perso->getPrMax() != $_POST['prmax']) { $msg[] = 'Pr Max: ' . $_POST['prmax']; } if ($perso->getPa() != $_POST['pa']) { $msg[] = 'Pa: ' . $_POST['pa']; } if ($perso->getPaMax() != $_POST['pamax']) { $msg[] = 'Pa Max: ' . $_POST['pamax']; } if ($perso->getPv() != $_POST['pv']) { $msg[] = 'Pv: ' . $_POST['pv']; } if ($perso->getPvMax() != $_POST['pvmax']) { $msg[] = 'Pv Max: ' . $_POST['pvmax']; } if ($perso->getPn() != $_POST['pn']) { $msg[] = 'Pn: ' . $_POST['pn']; } if ($perso->getCash() != $_POST['cash']) { $msg[] = 'Argent: ' . $_POST['cash']; } try { if ($perso->getLieu()->getNomTech() != $_POST['lieu']) { $msg[] = 'Lieu: ' . $_POST['lieu']; } } catch (Exception $e) { if (!isset($_POST['lieu'])) { $msg[] = 'Lieu: non-sélectionné'; } else { $msg[] = 'Lieu: ' . $_POST['lieu']; } } if ($perso->getCurrentAction() != $_POST['current_action']) { $msg[] = "Action Courrante: \n" . $_POST['current_action']; } if ($perso->getDescription() != $_POST['description']) { $msg[] = "Description: \n" . $_POST['description']; } if ($perso->getBackground() != $_POST['background']) { $msg[] = "Background: \n" . $_POST['background']; } if ($perso->getNoteMj() != $_POST['note_mj']) { $msg[] = "Note MJ: \n" . $_POST['note_mj']; } if ($perso->isBloque() != $_POST['actif']) { $msg[] = 'Actif: ' . $_POST['actif']; } if ($perso->getVisaPerm() != $_POST['visavert']) { $msg[] = 'VisaVert: ' . $_POST['visavert']; } if ($perso->getPv() > 0 && $_POST['pv'] < 0) { $perso->logMort($mj->getNom(), 'Modifier Perso'); } $menotte = $_POST['menotte'] == false ? NULL : $_POST['menotteId']; if ($perso->getMenotte() != $menotte) { $msg[] = 'Menotté : ' . ($menotte ? 'oui (' . $menotte . ').' : 'non.'); //Gestion des menottes //Si menotté : //Vérifier si l'item a bien la capacité menottage //Vérifier si l'item n'est pas déjà utilisé //Equiper l'item //Si passage de monotté à menotté avec autre item => déséquiper ancien item //Si passage de menotté à non menotté => déséquiper l'item if ($menotte) { try { $newMenotte = Member_ItemFactory::createFromInvId($menotte); } catch (Exception $e) { return fctErrorMSG($e->getMessage()); } $query = 'SELECT *' . ' FROM ' . DB_PREFIX . 'item_menu' . ' WHERE item_dbid = :dbid' . ' AND url="Menotter" LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':dbid', $newMenotte->getDbId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; if (count($arrAll) == 0) { return fctErrorMSG('L\'item choisi pour menotter n\'a pas la capacité menotter.'); } if ($newMenotte->isEquip()) { return fctErrorMSG('L\'item choisi pour menotter est déjà utilisé.'); } //Équiper l'item $query = 'UPDATE ' . DB_PREFIX . 'item_inv' . ' SET inv_equip="1"' . ' WHERE inv_id=:itemId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':itemId', $newMenotte->getInvId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; if ($perso->getMenotte()) { $query = 'UPDATE ' . DB_PREFIX . 'item_inv' . ' SET inv_equip="0"' . ' WHERE inv_id=:itemId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':itemId', $perso->getMenotte(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; } } else { $query = 'UPDATE ' . DB_PREFIX . 'item_inv' . ' SET inv_equip="0"' . ' WHERE inv_id=:itemId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':itemId', $perso->getMenotte(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; } } //modification $query = 'UPDATE ' . DB_PREFIX . 'perso' . ' SET' . ' userId=:userId,' . ' nom=:nom,' . ' sexe=:sexe,' . ' age=:age,' . ' taille=:taille,' . ' ethnie=:ethnie,' . ' yeux=:yeux,' . ' cheveux=:cheveux,' . ' playertype=:playerType,' . ' prmax=:prMax,' . ' pa=:pa,' . ' pamax=:paMax,' . ' pv=:pv,' . ' pvmax=:pvMax,' . ' pn=:pn,' . ' cash=:cash,' . ' lieu=:lieu,' . ' current_action=:currentAction,' . ' description=:description,' . ' background=:background,' . ' note_mj=:noteMj,' . ' bloque=:bloque,' . ' visa_perm=:visaPerm,' . ' menotte = :menotte' . ' WHERE id=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prep->bindValue(':userId', $_POST['userId'], PDO::PARAM_INT); $prep->bindValue(':nom', $_POST['nom'], PDO::PARAM_STR); $prep->bindValue(':sexe', $_POST['sexe'], PDO::PARAM_STR); $prep->bindValue(':age', $_POST['age'], PDO::PARAM_INT); $prep->bindValue(':taille', $_POST['taille'], PDO::PARAM_STR); $prep->bindValue(':ethnie', $_POST['ethnie'], PDO::PARAM_STR); $prep->bindValue(':yeux', $_POST['yeux'], PDO::PARAM_STR); $prep->bindValue(':cheveux', $_POST['cheveux'], PDO::PARAM_STR); $prep->bindValue(':playerType', $_POST['playertype'], PDO::PARAM_STR); $prep->bindValue(':prMax', $_POST['prmax'], PDO::PARAM_INT); $prep->bindValue(':pa', $_POST['pa'], PDO::PARAM_INT); $prep->bindValue(':paMax', $_POST['pamax'], PDO::PARAM_INT); $prep->bindValue(':pv', $_POST['pv'], PDO::PARAM_INT); $prep->bindValue(':pvMax', $_POST['pvmax'], PDO::PARAM_INT); $prep->bindValue(':pn', $_POST['pn'], PDO::PARAM_INT); $prep->bindValue(':cash', $_POST['cash'], PDO::PARAM_INT); $prep->bindValue(':lieu', isset($_POST['lieu']) ? $_POST['lieu'] : LIEU_DEPART, PDO::PARAM_STR); $prep->bindValue(':currentAction', $_POST['current_action'], PDO::PARAM_STR); $prep->bindValue(':description', $_POST['description'], PDO::PARAM_STR); $prep->bindValue(':background', $_POST['background'], PDO::PARAM_STR); $prep->bindValue(':noteMj', $_POST['note_mj'], PDO::PARAM_STR); $prep->bindValue(':bloque', $_POST['actif'], PDO::PARAM_STR); $prep->bindValue(':visaPerm', $_POST['visavert'], PDO::PARAM_STR); $prep->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prep->bindValue(':menotte', $menotte, PDO::PARAM_STR); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; //Fetcher toutes les informations concernant le perso $prepP->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prepP->executePlus($db, __FILE__, __LINE__); $arr = $prepP->fetch(); $perso = new Member_Perso($arr); //Sauvegarder les stats $query = 'INSERT INTO ' . DB_PREFIX . 'perso_stat' . ' (persoid, statid, xp)' . ' VALUES' . ' (:persoId, :statId, :xp);'; $prepIns = $db->prepare($query); $query = 'UPDATE ' . DB_PREFIX . 'perso_stat' . ' SET xp=:xp' . ' WHERE persoid=:persoId' . ' AND statid=:statId' . ' LIMIT 1;'; $prepUpd = $db->prepare($query); foreach ($perso->getStat() as $id) { $statCode = $perso->getStatCode($id); $fieldName = 'stat_' . $statCode; if (isset($_POST[$fieldName]) && is_numeric($_POST[$fieldName]) && $perso->getStatRawXp($id) != $_POST[$fieldName]) { //Construire le message d'information $statDiff = (int) $_POST[$fieldName] - $perso->getStatRawXp($id); if ($statDiff > 0) { $statDiff = '+' . $statDiff; } $msg[] = 'Stat ' . strtoupper($statCode) . ': ' . $statDiff; if ($perso->getStatRawXp($id) === NULL) { $prepIns->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prepIns->bindValue(':statId', $id, PDO::PARAM_INT); $prepIns->bindValue(':xp', $_POST[$fieldName], PDO::PARAM_INT); $prepIns->executePlus($db, __FILE__, __LINE__); } else { $prepUpd->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prepUpd->bindValue(':statId', $id, PDO::PARAM_INT); $prepUpd->bindValue(':xp', $_POST[$fieldName], PDO::PARAM_INT); $prepUpd->executePlus($db, __FILE__, __LINE__); } } } $prepIns->closeCursor(); $prepIns = NULL; $prepUpd->closeCursor(); $prepUpd = NULL; //Sauvegarder les comps $query = 'INSERT INTO ' . DB_PREFIX . 'perso_competence' . ' (`persoid`, `compid`, `xp`)' . 'VALUES' . '(:persoId, :compId, :xp);'; $prepIns = $db->prepare($query); $query = 'UPDATE ' . DB_PREFIX . 'perso_competence' . ' SET xp=:xp' . ' WHERE persoid=:persoId' . ' AND compid=:compId' . ' LIMIT 1;'; $prepUpd = $db->prepare($query); $query = 'DELETE FROM ' . DB_PREFIX . 'perso_competence' . ' WHERE persoid=:persoId' . ' AND compid=:compId' . ' LIMIT 1;'; $prepDel = $db->prepare($query); foreach ($perso->getComp() as $id) { $compCode = $perso->getCompCode($id); $fieldName = 'comp_' . $compCode; //La comp doit être définie if (isset($_POST[$fieldName]) && !empty($_POST[$fieldName]) && is_numeric($_POST[$fieldName]) && $perso->getCompXp($id) != $_POST[$fieldName]) { //Construire le message d'information $compDiff = (int) $_POST[$fieldName] - $perso->getCompXp($id); if ($compDiff > 0) { $compDiff = '+' . $compDiff; } $msg[] = 'Comp ' . strtoupper($compCode) . ': ' . $compDiff; //Créer la comp if ($perso->getCompXp($id) === NULL) { $prepIns->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prepIns->bindValue(':compId', $id, PDO::PARAM_INT); $prepIns->bindValue(':xp', $_POST[$fieldName], PDO::PARAM_INT); $prepIns->executePlus($db, __FILE__, __LINE__); } else { $prepUpd->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prepUpd->bindValue(':compId', $id, PDO::PARAM_INT); $prepUpd->bindValue(':xp', $_POST[$fieldName], PDO::PARAM_INT); $prepUpd->executePlus($db, __FILE__, __LINE__); } } //La compétence doit être effacée if (isset($_POST[$fieldName]) && empty($_POST[$fieldName]) && $perso->getCompXp($id) !== NULL) { $prepDel->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prepDel->bindValue(':compId', $id, PDO::PARAM_INT); $prepDel->executePlus($db, __FILE__, __LINE__); //Construire le message d'information $msg[] = 'Comp ' . strtoupper($compCode) . ': 0'; } } $prepIns->closeCursor(); $prepIns = NULL; $prepUpd->closeCursor(); $prepUpd = NULL; $prepDel->closeCursor(); $prepDel = NULL; //Modifier / Supprimer une caract $query = 'SELECT p.*, c.nom' . ' FROM ' . DB_PREFIX . 'perso_caract as p' . ' LEFT JOIN ' . DB_PREFIX . 'caract as c' . ' ON (c.id = p.caractid)' . ' WHERE p.`persoid`=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $_GET['id']); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; $query = 'UPDATE ' . DB_PREFIX . 'perso_caract' . ' SET `desc`=:description' . ' WHERE `id`=:id;'; $prepUpd = $db->prepare($query); $query = 'DELETE FROM ' . DB_PREFIX . 'perso_caract' . ' WHERE `id`=:id' . ' LIMIT 1;'; $prepDel = $db->prepare($query); foreach ($arrAll as &$row) { //Supprimer ? if (isset($_POST['del_caract_' . $row['id']])) { $prepDel->bindValue(':id', $row['id'], PDO::PARAM_INT); $prepDel->executePlus($db, __FILE__, __LINE__); $msg[] = 'Suppression de la caract ' . stripslashes($row['nom']); } else { $newDesc = fctScriptProtect($_POST['caract_' . $row['id']]); if (stripslashes($row['desc']) != $newDesc) { //Modifier $prepUpd->bindValue(':description', $newDesc, PDO::PARAM_STR); $prepUpd->bindValue(':id', $row['id'], PDO::PARAM_INT); $prepUpd->executePlus($db, __FILE__, __LINE__); $msg[] = 'Modification de la caract ' . stripslashes($row['nom']) . ":\n" . $newDesc; } } } $prepUpd->closeCursor(); $prepUpd = NULL; $prepDel->closeCursor(); $prepDel = NULL; //Ajouter une caract if ($_POST['add_caract'] != 0) { $query = 'INSERT INTO ' . DB_PREFIX . 'perso_caract' . ' (`caractid`,`persoid`)' . ' VALUES' . ' (:caractId, :persoId);'; $prep = $db->prepare($query); $prep->bindValue(':caractId', $_POST['add_caract'], PDO::PARAM_INT); $prep->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $prep->closeCursor(); $prep = NULL; $msg[] = 'Ajout de la caract #' . $_POST['add_caract'] . ":\n"; } //Recharger la liste des perso du compte actuel (compte du MJ) $query = 'SELECT id, nom FROM ' . DB_PREFIX . 'perso WHERE userId=:userId;'; $prep = $db->prepare($query); $prep->bindValue(':userId', $session->getVar('userId'), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; $session->setVar('persoList', $arrAll); //Afficher les messages et logger dans le HE MJ if (count($msg) > 0) { $msg = implode(",\n", $msg); $tpl->set('MODIFICATIONS', nl2br($msg)); $mj->addHe("Modification du personnage: \n" . $msg, $perso->getNom(), 'perso'); } $prepP->closeCursor(); $prepP = NULL; } // End save //Fetcher toutes les informations concernant le perso $query = 'SELECT p.*, a.user as user' . ' FROM ' . DB_PREFIX . 'perso as p' . ' LEFT JOIN ' . DB_PREFIX . 'account as a' . ' ON (a.id=p.userId)' . ' WHERE p.id=:persoId' . ' LIMIT 1;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $_GET['id'], PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arr = $prep->fetch(); $prep->closeCursor(); $prep = NULL; if ($arr === false) { return fctErrorMSG('Ce personnage n\'existe pas.'); } try { $perso = new Member_Perso($arr); } catch (Exception $e) { return fctErrorMSG($e->getMessage()); } try { $tpl->set('PERSO_LIEU', $perso->getLieu()->getNomTech()); } catch (Exception $e) { $tpl->set('PERSO_LIEU', 'LIEU CORROMPU'); } $tpl->set('PERSO', $perso); $tpl->set('ACCOUNT_USER', $arr['user']); $tpl->set('BACKGROUND', stripslashes($arr['background'])); $tpl->set('NOTE_MJ', stripslashes($arr['note_mj'])); //Trouver les drogues consommées $query = 'SELECT inv_id' . ' FROM ' . DB_PREFIX . 'item_inv' . ' WHERE inv_equip="1"' . ' AND inv_dbid="2"' . ' AND inv_persoid=:persoId' . ' ;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; $drogues = array(); foreach ($arrAll as &$arr) { $drogues[] = '<a href="?mj=Item_Inv_Mod&id=' . (int) $arr['inv_id'] . '&rpage=Perso_Mod&rid=' . (int) $perso->getId() . '">' . (int) $arr['inv_id'] . '</a>'; } if (count($drogues) > 0) { $tpl->set('DROGUES', implode(', ', $drogues)); } //Trouver les caractéristiques du perso $query = 'SELECT p.*, c.nom, t.nom as cat' . ' FROM ' . DB_PREFIX . 'perso_caract as p' . ' LEFT JOIN ' . DB_PREFIX . 'caract as c ON (c.id = p.caractid)' . ' LEFT JOIN ' . DB_PREFIX . 'caract as t ON (t.id = c.catid)' . ' WHERE p.persoid=:persoId;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; foreach ($arrAll as &$arr) { $arr['cat'] = stripslashes($arr['cat']); $arr['nom'] = stripslashes($arr['nom']); $arr['desc'] = stripslashes($arr['desc']); } $tpl->set('CARACT', $arrAll); //Trouver toutes les caractéristiques $query = 'SELECT c.*, t.nom as cat' . ' FROM ' . DB_PREFIX . 'caract as c' . ' LEFT JOIN ' . DB_PREFIX . 'caract as t ON (t.id = c.catid)' . ' WHERE c.catid!=0' . ' ORDER BY t.nom, c.nom;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; foreach ($arrAll as &$arr) { $arr['cat'] = stripslashes($arr['cat']); $arr['nom'] = stripslashes($arr['nom']); } $tpl->set('ALLCARACT', $arrAll); //trouver les modificateurs des compétences: $query = 'SELECT c.*, p.xp, s.statid, s.stat_multi' . ' FROM ' . DB_PREFIX . 'competence as c' . ' LEFT JOIN ' . DB_PREFIX . 'perso_competence as p ON (p.compid = c.id AND p.persoid=:persoId)' . ' LEFT JOIN ' . DB_PREFIX . 'competence_stat as s ON (s.compid = c.id)' . ' ORDER BY c.id;'; $prep = $db->prepare($query); $prep->bindValue(':persoId', $perso->getId(), PDO::PARAM_INT); $prep->executePlus($db, __FILE__, __LINE__); $arrAll = $prep->fetchAll(); $prep->closeCursor(); $prep = NULL; $arrComp = array(); foreach ($arrAll as &$arr) { if ($arr['statid'] === NULL) { $arrComp[$arr['id']] = NULL; } else { $arrComp[$arr['id']][$arr['statid']] = $arr['stat_multi']; } } foreach ($arrComp as &$arr) { if ($arr === NULL) { $arr['txt'] = ''; } else { $txtBuilder = array(); foreach ($arr as $statId => $multi) { $txtBuilder[] = strtoupper($perso->getStatCode($statId)) . 'x' . $multi; } $arr['txt'] = implode(' + ', $txtBuilder); } } $tpl->set('COMP_MOD_TXT', $arrComp); return $tpl->fetch($account->getSkinRemotePhysicalPath() . 'html/Mj/Perso/Mod.htm'); }