public function contactAction() { try { if ($_POST) { $emailSent = false; if ($this->validateContactForm()) { $name = ArrayHelper::getSafeFromArray($_POST, "contactName", null); $firstName = ArrayHelper::getSafeFromArray($_POST, "contactFirstName", null); $email = ArrayHelper::getSafeFromArray($_POST, "email", null); $message = ArrayHelper::getSafeFromArray($_POST, "comments", null); $sendCopy = ArrayHelper::getSafeFromArray($_POST, "sendCopy", false); $subject = sprintf(__("Formulaire de contact : %s %s", "s1b"), $name, $firstName); $body = sprintf(__("Nom : %s <br/>Prénom: %s <br/>Email : %s <br/>Message: %s <br/>", "s1b"), $name, $firstName, $email, $message); $mailSvc = MailSvc::getNewInstance(null, Constants::CONTACT_EMAIL); $mailSvc->send(Constants::CONTACT_EMAIL . ", berliozd@gmail.com, rebiffe_olivier@yahoo.fr", $subject, $body); if ($sendCopy) { $subject = __("Formulaire de contact", "s1b"); $copyMessage = sprintf(__("Merci d'avoir contacté %s.", "s1b"), Constants::SITENAME) . "<br/>" . __("Nous nous efforçons de vous répondre au plus vite.", "s1b") . "<br/>" . sprintf(__("L'équipe %s", "s1b"), Constants::SITENAME) . "<br/><br/>" . $body; $mailSvc->send($email, $subject, $copyMessage); } $emailSent = true; } else { Flash::addItem(__("Le message n'a pas pu être envoyé.", "s1b")); } if ($emailSent) { Flash::addItem(__("Merci.", "s1b")); Flash::addItem(__("Votre e-mail a été envoyé. Vous recevrez une réponse au plus vite.", "s1b")); Flash::addItem(sprintf(__("L'equipe %s", "s1b"), Constants::SITENAME)); HTTPHelper::redirect(""); } } } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
/** * Send invitation to users */ public function inviteAction() { try { $globalContext = new \Sb\Context\Model\Context(); $user = $globalContext->getConnectedUser(); $continue = true; $emails = ArrayHelper::getSafeFromArray($_POST, 'Emails', null); $message = ArrayHelper::getSafeFromArray($_POST, 'Message', null); if (!$emails || !$message) { Flash::addItem(__("Vous devez renseigner tous les champs obligatoires.", "s1b")); $continue = false; } if ($continue) { $emailsListFromPost = explode(",", $emails); // Getting emails list if ($emailsListFromPost) { // Looping through all emails for validating all of them // At the end of the loop: // we will have an array of emails to be processed // and flag to process or not the sendings $emailsList = array(); foreach ($emailsListFromPost as $emailToInvite) { $addEmail = true; $emailToInvite = strtolower(trim($emailToInvite)); if ($emailToInvite != "") { // Testing if the email is valid if (!StringHelper::isValidEmail($emailToInvite)) { Flash::addItem(sprintf(__("%s n'est pas un email valide.", "s1b"), $emailToInvite)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } else { // Testing if the email does not match an existing user $userInDb = UserDao::getInstance()->getByEmail($emailToInvite); if ($userInDb && !$userInDb->getDeleted()) { $friendRequestUrl = HTTPHelper::Link(Urls::USER_FRIENDS_REQUEST, array("fid" => $userInDb->getId())); Flash::addItem(sprintf(__("Un utilisateur existe déjà avec l'email : %s. <a class=\"link\" href=\"%s\">Envoyer lui une demande d'ami</a>", "s1b"), $emailToInvite, $friendRequestUrl)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } else { // Testing if invitations have been sent to that guest (email) by the current user $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite); if ($invitations && count($invitations) > 0) { Flash::addItem(sprintf(__("Vous avez déjà envoyé une invitation à cet email : %s.", "s1b"), $emailToInvite)); // We will stop invitation sending $continue = false; // Current email not added to the array of emails to be processed $addEmail = false; } } } } if ($addEmail) { $emailsList[] = $emailToInvite; } } if ($continue) { // Looping through all emails for sending invitation $initialMessage = $message; foreach ($emailsList as $emailToInvite) { $emailToInvite = strtolower(trim($emailToInvite)); if ($emailToInvite != "") { $sendInvitation = true; // Testing again if invitations have been sent to that guest (email) by the current user $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite); if ($invitations && count($invitations) > 0) { $sendInvitation = false; } if ($sendInvitation) { // Getting existing guests matching email, and take first 1 $guest = null; $guests = GuestDao::getInstance()->getListByEmail($emailToInvite); if ($guests && count($guests) > 0) { $guest = $guests[0]; } $token = sha1(uniqid(rand())); // Send invite email $message = str_replace("\n", "<br/>", $initialMessage); $message .= "<br/><br/>"; $message .= sprintf(__("<a href=\"%s\">S'inscrire</a> ou <a href=\"%s\">Refuser</a>", "s1b"), HTTPHelper::Link(Urls::SUBSCRIBE), HTTPHelper::Link(Urls::REFUSE_INVITATION, array("Token" => $token, "Email" => $emailToInvite))); $message .= "<br/><br/>"; $message .= "<strong>" . sprintf(__("L'équipe %s", "s1b"), Constants::SITENAME) . "<strong/>"; MailSvc::getNewInstance($user->getEmail(), $user->getEmail())->send($emailToInvite, sprintf(__("Invitation à rejoindre %s", "s1b"), Constants::SITENAME), $message); // Create invitation $invitation = new Invitation(); $invitation->setSender($user); $invitation->setToken($token); $invitation->setLast_modification_date(new \DateTime()); if ($guest) { // Updating guest $guest->addInvitations($invitation); GuestDao::getInstance()->update($guest); } else { // Create guest $guest = new Guest(); $guest->setEmail($emailToInvite); $guest->setCreation_date(new \DateTime()); $guest->addInvitations($invitation); GuestDao::getInstance()->add($guest); } Flash::addItem(sprintf(__("Une invitation a été envoyée à %s.", "s1b"), $emailToInvite)); } } } HTTPHelper::redirectToHome(); } } } // If we arrive here : an error occured, then redirect to the invite form HTTPHelper::redirect(Urls::USER_FRIENDS_INVITE, array("emails" => $emails)); } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
public function warnBadDescriptionAction() { $globalContext = new \Sb\Context\Model\Context(); $bookId = $this->_getParam('bid'); if ($globalContext->getConnectedUser()) { if ($bookId) { $userId = $globalContext->getConnectedUser()->getId(); $mailSvc = MailSvc::getNewInstance(null, $globalContext->getConnectedUser()->getEmail()); $body = "Une description erronée a été signalée pour le livre {$bookId} par l'utilisateur {$userId}"; if ($mailSvc->send(Constants::WEBMASTER_EMAIL, "Signalisation de description erronée", $body)) { $this->view->message = __("L'administrateur du site a été averti. Nous vous remerçions pour votre aide", "s1b"); } else { $this->view->message = __("Le mail n'a pa pu être envoyé.", "s1b"); } } else { $this->view->message = __("Requête incorrecte.", "s1b"); } } else { $this->view->message = __("Vous devez être connecté pour effectuer cette action.", "s1b"); } }