Exemple #1
0
function getNameReceivers($idsReceivers)
{
    $strReceivers = "";
    $receivers = explode(",", $idsReceivers);
    foreach ($receivers as $idReceiver) {
        $receiver = UtilisateurDAO::selectUtilisateurParId($idReceiver);
        $strReceivers .= $receiver->getIdentifiant() . ", ";
    }
    return $strReceivers;
}
/**
 * Retourne les noms des destinataires du message de chat
 * 
 * @param string $idsReceivers
 * @return string
 */
function getNameReceivers($idsReceivers)
{
    $strReceivers = "";
    try {
        $receivers = explode(",", $idsReceivers);
        if (count($receivers) == 1 && $receivers[0] == 0) {
            $strReceivers = "TOUS";
        } else {
            foreach ($receivers as $key => $idReceiver) {
                $receiver = UtilisateurDAO::selectById($idReceiver);
                $strReceivers .= $receiver->username;
                $strReceivers .= iif(count($receivers) - 1 != $key, ", ", "");
            }
        }
    } catch (Exception $exc) {
        $strReceivers = "???";
    }
    return $strReceivers;
}
$fullData = false;
$username = trim($_POST["identifiant"]);
$password = trim($_POST["motdepasse"]);
$email = trim($_POST["email"]);
$nameMainPlanet = trim($_POST["PM"]);
$id_language = (int) $_POST['Lang'];
if (isset($username) && respectsLengthWord($username, ">=", 3) && isset($password) && respectsLengthWord($password, ">=", 3) && isset($email) && respectsLengthWord($email, ">=", 3) && isset($nameMainPlanet) && respectsLengthWord($nameMainPlanet, ">=", 3) && isset($id_language)) {
    $fullData = true;
}
//Toutes les informations sont complètes...
if ($fullData) {
    if (!UtilisateurDAO::userExistByUsernameAndEmail($username, $email)) {
        //Création planète
        $p = new Planet();
        $p->assignValueDefault();
        //Création utilisateur
        $u = new User();
        $u->id_language = $id_language;
        $u->username = $username;
        $u->hash_password = encodePassword($password);
        $u->email = $email;
        UtilisateurDAO::add($u);
        $message = $lang['sign_finish'] . "" . $username . "" . $lang['return_mail'];
        MessageSIWE::showAjaxMessage($message, $lang['title_sign'] . $lang['title_game'], null, MessageSIWE::MESSAGE_SUCCESS);
    } else {
        MessageSIWE::showAjaxMessage($lang['error_isset_user'], $lang['title_sign'], null, MessageSIWE::MESSAGE_ERROR);
    }
} else {
    MessageSIWE::showAjaxMessage($lang['error_champs_empty'], $lang['title_sign'] . $lang['title_game'], null, MessageSIWE::MESSAGE_ERROR);
}
<?php

$users = UtilisateurDAO::selectAll();
$available_users = array();
foreach ($users as $i => $user) {
    $available_users[$i]["id"] = $user->id_user;
    $available_users[$i]["value"] = $user->username;
}
echo json_encode($available_users);
die;
<?php

ob_start();
$fullData = false;
$username = trim($_POST["identifiant"]);
$password = $_POST["motdepasse"];
if (isset($username) && respectsLengthWord($username, ">=", 3) && isset($password) && respectsLengthWord($password, ">=", 3)) {
    $fullData = true;
}
//Toutes les informations sont complètes...
if ($fullData) {
    $user = UtilisateurDAO::getUserByLogins($username, encodePassword($password));
    //Si les données sont exactes, on va alors tenté la redirection
    if (isset($user) && $user->id_user > 0) {
        $_SESSION = array();
        $_SESSION["id"] = $user->id_user;
        echo "<script>window.location = '" . $_SERVER['HTTP_REFERER'] . "';</script>";
        exit;
    } else {
        MessageSIWE::showAjaxMessage($lang['error_write_conn'], $lang['title_conn'] . $lang['title_game'], null, MessageSIWE::MESSAGE_ERROR);
    }
} else {
    MessageSIWE::showAjaxMessage($lang['error_champs_empty'], $lang['title_conn'] . $lang['title_game'], null, MessageSIWE::MESSAGE_ERROR);
}
ob_end_flush();
Exemple #6
0
 $langues = LangueDAO::selectAll();
 foreach ($langues as $langue) {
     $tabLangue[$langue->code] = $langue->id_language;
 }
 //Traduction
 $translations = TranslationDAO::selectAll();
 foreach ($translations as $translation) {
     if ($translation->id_language == $tabLangue[$_SESSION['language']]) {
         $lang[$translation->name] = utf8_encode($translation->value);
     }
 }
 $parse = $lang;
 try {
     //-------------------------------------------------------------------------------
     if (isset($_SESSION["id"])) {
         $user = UtilisateurDAO::selectById(intval($_SESSION["id"]));
         //$planet = PlaneteDAO::selectPlaneteParId(...);
         //Language
         $langage = LangueDAO::selectById($user->id_language);
         //Est dans le jeu (pour le menu)
         $isInGame = true;
     } else {
         //Language
         $langage = LangueDAO::selectById($tabLangue[$_SESSION['language']]);
         //Est dans le jeu (pour le menu)
         $isInGame = false;
     }
     //Gestion des menus
     require_once NAME_DIRECTORY_CONTROLLERS . DIRECTORY_SEPARATOR . 'menu.php';
     $listMenus = MenuDAO::selectAppropriateMenu($isInGame);
     $parse['navbar_menus'] = getMenu($listMenus);
<?php

$message = trim(utf8_decode($_POST["message"]));
$is_connected = $_POST["is_connected"];
$str_recipients = $_POST["id_recipients"];
$id_user = (int) $_SESSION['id'];
//Formater les destinataires en cas de tentative d'injection
$formatted_recipients = "";
$id_recipients = explode(",", $str_recipients);
if (count($id_recipients) > 0) {
    $temp_array = array();
    foreach ($id_recipients as $id_recipient) {
        $id_recipient = (int) $id_recipient;
        if ($id_recipient > 0 && UtilisateurDAO::selectById($id_recipient)) {
            $temp_array[] = $id_recipient;
        }
    }
    $formatted_recipients = implode(",", $temp_array);
} else {
    $formatted_recipients = "0";
}
$chat = new Chat();
$chat->time_msg = (new DateTime("now", new DateTimeZone(DATETIME_ZONE)))->getTimestamp();
if (strlen($message) > 0) {
    if ($is_connected) {
        $chat->id_recipients = $formatted_recipients;
        $chat->id_sender = $id_user;
        $chat->msg = $message;
    } else {
        $chat->id_recipients = $id_user;
        $chat->id_sender = 0;