/** * Action called for unsubscription to press reviews */ public function unsubscribeAction() { try { $email = $this->getParam("email", null); if (!$email) { Flash::addItem(__("Requête invalide", "s1b")); } else { $email = trim($email); /* @var $pressReviewsSubscriber PressReviewsSubscriber */ $pressReviewsSubscriber = PressReviewsSubscriberDao::getInstance()->getByEmail($email); if ($pressReviewsSubscriber) { // Mark the press review subscriber as deleted $pressReviewsSubscriber->setIs_deleted(true); PressReviewsSubscriberDao::getInstance()->update($pressReviewsSubscriber); Flash::addItem(__("Votre désinscription a bien été pris en compte.", "s1b")); } else { Flash::addItem(__("Il n'y a pas d'abonné correspondant à l'email fourni.", "s1b")); } } HTTPHelper::redirectToHome(); } 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 editAction() { try { $globalContext = new \Sb\Context\Model\Context(); if ($globalContext->getIsShowingFriendLibrary()) { Flash::addItem(__("You cannot edit a lending from a friend's library")); HTTPHelper::redirectToHome(); } $userBookId = $_GET['ubid']; $userBook = UserBookDao::getInstance()->get($userBookId); if ($userBook) { // Check user is user book owner if ($globalContext->getConnectedUser()->getId() != $userBook->getUser()->getId()) { Flash::addItem(__("Le livre que vous souhaitez éditer ne correspond pas à l'utilisateur connecté.", "share1book")); HTTPHelper::redirectToLibrary(); } $book = $userBook->getBook(); $bookView = new BookView($book, false, false, false); $this->view->book = $bookView->get(); $lendingView = new LendingView($userBook, $globalContext->getConnectedUser()->getId()); $this->view->bookForm = $lendingView->get(); $buttonsBar = new ButtonsBar(false); $this->view->buttonsBar = $buttonsBar->get(); } else { Flash::addItem("Le livre que vous souhaitez éditer n'existe pas."); HTTPHelper::redirectToLibrary(); } } 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"); } }
/** * Check if a user is connected in session and otherwise set a flash message, persist request url in session and redirect to homepage */ public function checkUserIsConnected() { if (!$this->getIsConnected()) { $_SESSION[\Sb\Entity\SessionKeys::RETURN_URL_AFTER_LOGIN] = $_SERVER["REQUEST_URI"]; Flash::addItem(__("Vous devez être connecté pour accéder à cette page.", "s1b")); HTTPHelper::redirectToHome(); } }
/** * 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"); } }
private function redirectToHome() { Flash::addItem(__("Vos critères de recherche ne nous ont pas permis de trouver de livre.", "s1b")); HTTPHelper::redirectToHome(); }
public function refuseInvitationAction() { try { if (!empty($_GET)) { $email = $_GET['Email']; $token = $_GET['Token']; $invitation = InvitationDao::getInstance()->getByEmailAndToken($email, $token); if ($invitation) { $invitation->setIs_accepted(false); $invitation->setIs_validated(true); $invitation->setLast_modification_date(new \DateTime()); InvitationDao::getInstance()->update($invitation); Flash::addItem(sprintf(__("L'invitation à rejoindre %s a été refusée.", "s1b"), Constants::SITENAME)); } else { //Invitation unknown Flash::addItem(__("Une erreur est survenue lors du refus de l'invitation", "s1b")); } } HTTPHelper::redirectToHome(); } 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 borrowFromFriendsAction() { try { $globalContext = new \Sb\Context\Model\Context(); $bookIdInIQS = ArrayHelper::getSafeFromArray($_GET, "bid", null); if ($bookIdInIQS) { $book = BookDao::getInstance()->get($bookIdInIQS); } else { // Get Book to add from cache $book = ZendFileCache::getInstance()->load(Constants::BOOK_TO_ADD_PREFIX . session_id()); } if ($book) { $userBookInDb = UserBookDao::getInstance()->getByBookIdAndUserId($globalContext->getConnectedUser()->getId(), $book->getId()); if ($userBookInDb && !$userBookInDb->getIs_deleted()) { Flash::addItem(__("Vous avez déjà ce livre dans votre bibliothèque.", "s1b")); HTTPHelper::redirectToLibrary(); } else { // Checking if a friend has this book in his library $userBookDao = UserBookDao::getInstance(); $user = $globalContext->getConnectedUser(); $friends = $user->getAcceptedFriends(); if ($friends) { $userBooks = $userBookDao->getBookInFriendsUserBook($book->getId(), $globalContext->getConnectedUser()->getId()); if ($userBooks) { $this->view->friendUserBooks = array_filter($userBooks, array(&$this, "IsBorrowable")); } } $bookView = new \Sb\View\Book($book, false, false, true, null, null, null, false); $this->view->book = $bookView->get(); } } else { HTTPHelper::redirectToHome(); } } 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"); } }