protected function process()
 {
     $email = $_POST['mail_sender'];
     $res = null;
     $user = null;
     $domain = null;
     $MXHost = null;
     preg_match("/\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*/", $email, $res);
     $translator = $this->application->get('translator');
     if (!$res || $res[0] !== $email || empty($email)) {
         $this->contactStatus = $translator->translate('mail_invalide');
     } else {
         list($user, $domain) = explode('@', $email);
         if (!getmxrr($domain, $MXHost)) {
             $this->contactStatus = $translator->translate('mail_invalide');
         } else {
             $mail = new Mailer();
             $mail->addRecipient('*****@*****.**', '');
             $mail->addFrom($email, '');
             $mail->addSubject($_POST['mail_title'], '');
             $mail->html = "<table><tr><td>" . utf8_decode('Identité') . " :<br/>====================</td></tr>" . "<tr><td>{$_POST['mail_sender']}<br/></td></tr>" . "<tr><td>Message :<br/>====================</td></tr>" . "<tr><td>" . nl2br(htmlspecialchars(utf8_decode($_POST['mail_message']))) . "</td></tr></table>";
             if (!$mail->send()) {
                 $this->contactStatus = $mail->errorLog();
             }
         }
     }
 }
 public function zoneGeoAction()
 {
     if (($member = $this->getUser()) === null) {
         $this->redirect('Index/index');
     }
     if (!empty($_POST['country']) && isset($_POST['region']) && $_POST['region'] !== 0) {
         $db = $this->application->get('database_connection');
         $db->prepareStatement('UPDATE users SET country = :country, region = :region WHERE id = :id', ['country' => $_POST['country'], 'region' => $_POST['region'], 'id' => $member->getId()]);
         if ($_POST['region'] !== -1) {
             $logger = $this->application->get('logger');
             $logger->setWriter('db');
             // Ajout de l'utilisateur dans le groupe correspondant
             // ===================================================
             $echec_createGroup = false;
             $groupId = 0;
             $groupName = $db->prepareStatement('SELECT Name FROM regions WHERE Region_id = :region_id', ['region_id' => $_POST['region']])->fetch()['Name'];
             if ($db->prepareStatement('SELECT COUNT(*) AS count FROM groups WHERE name = :name', ['name' => $groupName])->fetch()['count'] === 0) {
                 $statement = $db->prepareStatement('INSERT INTO groups (type_id, description, name, contact_id) VALUES (:type_id, :description, :name, :contact_id)', ['type_id' => 1, 'description' => 'Groupe regional', 'name' => $groupName, 'contact_id' => 1]);
                 if ($statement->rowCount() === 0) {
                     $echec_createGroup = true;
                 } else {
                     // Journal de log
                     $logger->log("Création du groupe régional {$groupName} par l'utilisateur " . $member->getIdentity(), Log::ERR);
                     $groupId = $db->lastInsertId();
                 }
             } else {
                 $groupId = $db->query("SELECT id FROM groups WHERE name = '{$groupName}'")->fetch()['id'];
             }
             if (!$echec_createGroup) {
                 $statement = $db->prepareStatement('INSERT INTO citizen_groups (citizen_id, group_id) VALUES (:citizen_id, :group_id)', ['citizen_id' => $member->getId(), 'group_id' => $groupId]);
                 if ($statement->rowCount() === 1) {
                     // Journal de log
                     $logger->log("Ajout de l'utilisateur {$member->getIdentity()} dans le groupe {$groupName}", Log::ERR);
                 }
             }
         } else {
             // Si la region choisie est 'other' alors Brennan Waco reçoit un mail
             // ==================================================================
             $mail = new Mailer();
             $mail->addRecipient('*****@*****.**', '');
             $mail->addFrom('*****@*****.**', '');
             $mail->addSubject('regions inconnues', '');
             $mail->html = "<table><tr><td>ID User : {$member->getIdentity()} :<br/>====================</td></tr>" . "<tr><td>{$_POST['country']}<br/></td></tr>" . '<tr><td>Message :<br/>====================</td></tr></table>';
             $mail->send();
         }
         $this->redirect('Intranet/index');
     } else {
         $this->display(json_encode(['status' => 2, 'reponse' => $this->application->get('translator')->translate('fields_empty')]));
     }
 }
 public function validCodeForgetPasswordAction()
 {
     $translate = $this->application->get('translator');
     if (empty($_POST['code'])) {
         $err_msg = $translate->translate('fields_empty');
     } else {
         $db = $this->application->get('database_connection');
         if ($db->count('recovery', " WHERE code={$_POST['code']} AND login='******'memo_login']}'") === 0) {
             $err_msg = $translate->translate('no_result');
         } else {
             $email = $db->select("SELECT email FROM Utilisateurs WHERE login='******'memo_login']}'");
             if (count($email) === 0) {
                 $err_msg = $translate->translate('no_result');
             } else {
                 $new_pwd = $this->createPassword();
                 $mail = new Mailer();
                 $mail->addRecipient($email[0]['email'], '');
                 $mail->addFrom('*****@*****.**', '');
                 $mail->addSubject('8thwonderland - ' . $translate->translate('forget_pwd'), '');
                 $mail->html = $translate->translate('mail_newpwd') . $new_pwd;
                 if (!$mail->envoi()) {
                     $err_msg = $mail->error_log();
                 } else {
                     $db->query("UPDATE Utilisateurs SET password='******'sha512', $new_pwd) . "' WHERE login='******'memo_login']}'");
                     if ($db->affected_rows == 0) {
                         // log d'échec de mise à jour
                         $logger = $this->application->get('logger');
                         $logger->setWriter('db');
                         $logger->log("Echec de changement du mot de passe ({$_POST['memo_login']})", Log::ERR);
                     }
                 }
             }
         }
     }
     if (!empty($err_msg)) {
         return new Response('<div class="error" style="padding:3px"><table style="width:70%"><tr>' . '<td><img alt="error" src="' . ICO_PATH . '64x64/Error.png" style="width:24px;"/></td>' . '<td><span style="font-size: 13px;">' . $err_msg . '</span></td>' . '</tr></table></div>');
     }
     return new Response('<div class="info" style="padding:3px"><table style="width:70%"><tr>' . '<td><img alt="info" src="' . ICO_PATH . '64x64/Info.png" style="width:24px;"/></td>' . '<td><span style="font-size: 13px;">' . $translate->translate('reponse_newpwd') . '</span></td>' . '</tr></table></div>');
 }