Example #1
0
/**
 * Send a notification to the poll admin to notify him about an update.
 *
 * @param stdClass $poll The poll
 * @param MailService $mailService The mail service
 * @param int $type cf: Constants on the top of this page
 */
function sendUpdateNotification($poll, $mailService, $type)
{
    if (!isset($_SESSION['mail_sent'])) {
        $_SESSION['mail_sent'] = [];
    }
    if ($poll->receiveNewVotes) {
        $subject = '[' . NOMAPPLICATION . '] ' . __f('Mail', 'Notification of poll: %s', $poll->title);
        $message = '';
        switch ($type) {
            case UPDATE_POLL:
                $message = __f('Mail', 'Someone just change your poll available at the following link %s.', Utils::getUrlSondage($poll->admin_id, true)) . "\n\n";
                break;
            case DELETED_POLL:
                $message = __f('Mail', 'Someone just delete your poll %s.', Utils::htmlEscape($poll->title)) . "\n\n";
                break;
        }
        $messageTypeKey = $type . '-' . $poll->id;
        $mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey);
    }
}
     // Insert poll in database
     $ids = $pollService->createPoll($_SESSION['form']);
     $poll_id = $ids[0];
     $admin_poll_id = $ids[1];
     // Send confirmation by mail if enabled
     if ($config['use_smtp'] === true) {
         $message = __('Mail', "This is the message you have to send to the people you want to poll. \nNow, you have to send this message to everyone you want to poll.");
         $message .= '<br/><br/>';
         $message .= Utils::htmlEscape($_SESSION['form']->admin_name) . ' ' . __('Mail', 'hast just created a poll called') . ' : "' . Utils::htmlEscape($_SESSION['form']->title) . '".<br/>';
         $message .= __('Mail', 'Thanks for filling the poll at the link above') . ' :<br/><br/><a href="%1$s">%1$s</a>';
         $message_admin = __('Mail', "This message should NOT be sent to the polled people. It is private for the poll's creator.\n\nYou can now modify it at the link above");
         $message_admin .= ' :<br/><br/><a href="%1$s">%1$s</a>';
         $message = sprintf($message, Utils::getUrlSondage($poll_id));
         $message_admin = sprintf($message_admin, Utils::getUrlSondage($admin_poll_id, true));
         if ($mailService->isValidEmail($_SESSION['form']->admin_mail)) {
             $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'Author\'s message') . '] ' . __('Generic', 'Poll') . ': ' . Utils::htmlEscape($_SESSION['form']->title), $message_admin);
             $mailService->send($_SESSION['form']->admin_mail, '[' . NOMAPPLICATION . '][' . __('Mail', 'For sending to the polled users') . '] ' . __('Generic', 'Poll') . ': ' . Utils::htmlEscape($_SESSION['form']->title), $message);
         }
     }
     // Clean Form data in $_SESSION
     unset($_SESSION['form']);
     // Delete old polls
     $purgeService->purgeOldPolls();
     // Redirect to poll administration
     header('Location:' . Utils::getUrlSondage($admin_poll_id, true));
     exit;
 } else {
     if (isset($_POST['fin_sondage_autre'])) {
         Utils::print_header(__('Step 3', 'Removal date and confirmation (3 on 3)'));
         bandeau_titre(__('Step 3', 'Removal date and confirmation (3 on 3)'));
         // Store choices in $_SESSION
Example #3
0
use Framadate\Services\LogService;
use Framadate\Services\MailService;
use Framadate\Services\PollService;
include_once __DIR__ . '/app/inc/init.php';
/* SERVICES */
/* -------- */
$logService = new LogService();
$pollService = new PollService($connect, $logService);
$mailService = new MailService($config['use_smtp']);
/* PAGE */
/* ---- */
$message = null;
if (!empty($_POST['mail'])) {
    $mail = filter_input(INPUT_POST, 'mail', FILTER_VALIDATE_EMAIL);
    if ($mail) {
        $polls = $pollService->findAllByAdminMail($mail);
        if (count($polls) > 0) {
            $smarty->assign('polls', $polls);
            $body = $smarty->fetch('mail/find_polls.tpl');
            $mailService->send($mail, __('Homepage', 'Where are my polls'), $body, 'SEND_POLLS');
            $message = new Message('success', __('FindPolls', 'Polls sent'));
        } else {
            $message = new Message('warning', __('Error', 'No polls found'));
        }
    } else {
        $message = new Message('danger', __('Error', 'Something is wrong with the format'));
    }
}
$smarty->assign('title', __('Homepage', 'Where are my polls'));
$smarty->assign('message', $message);
$smarty->display('find_polls.tpl');