public function renderDefault($event_id = null)
 {
     if ($event_id) {
         $this->template->filterName = $this->event->get($event_id)->name;
         $this->template->ticket = $this->ticket->where('event_id = ?', $event_id)->order('id DESC');
     } else {
         $this->template->filterName = '';
         $this->template->ticket = $this->ticket->order('id DESC')->limit(100);
     }
 }
 public function eventTicketFormSucceeded(Nette\Application\UI\Form $form, $values)
 {
     // Udalost
     $event = $this->event->get($values['event_id']);
     // Drive zamluvene vstupenky
     $duplicite = $this->ticket->where('event_id = ? AND email = ?', [$values['event_id'], $values['email']]);
     // Vycerpan limit
     if (count($duplicite) >= $event['max_ticket_per_email']) {
         $this->flashMessage('Limit na počet vstupenek pro Váš email byl již vyčerpán, použijte jiný email.', 'warning');
         $this->redirect('this');
     }
     // Ulozeni do databaze
     try {
         $ticket = $this->ticket->insert($values);
     } catch (\Exception $e) {
         $ticket = false;
     }
     // Notifikace na email a odeslání vstupenky
     if ($ticket) {
         $this->mailNotify('SOS - nova vstupenka', 'Uzivatel s emailem ' . $values['email'] . ' si zazadal o vstupenku na akci ' . $event->name . '.', $values);
         $this->sendTicket($ticket);
         $this->flashMessage('Byla Vám zaslána vstupenka.', 'success');
     } else {
         $this->flashMessage('Je nám líto, ale došlo k chybě. Pro vstupenku se obraťte se pořadatelku akce.', 'danger');
     }
     $this->redirect('this');
 }
    public function newsletterFormSucceeded(UI\Form $form, $values)
    {
        if (!$values['event_id']) {
            $values['event_id'] = null;
        }
        $this->saveFormValues($values);
        $contacts = array();
        if (!$values['event_id'] && $values['notTest']) {
            foreach ($this->registration as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } elseif ($values['notTest']) {
            foreach ($this->registration->where('event_id = ?', $values['event_id']) as $registration) {
                $contacts[] = $registration->email;
            }
            foreach ($this->ticket->where('event_id = ?', $values['event_id']) as $ticket) {
                $contacts[] = $ticket->email;
            }
            $contacts = array_unique($contacts);
        } else {
            $contacts = [0 => self::EMAIL_OPERATOR];
        }
        $mail = new Nette\Mail\Message();
        $mail->setFrom('Hudební S.O.S. <*****@*****.**>')->setSubject($values['subject'])->setHtmlBody('
				<html><head><title>' . $values['subject'] . '</title></head>
				<body>
				<div style="background-color: rgb(197, 230, 235);color: rgb(0, 117, 117);letter-spacing: 0.3px; margin: auto auto; padding:1em 1em">
				' . $values['text'] . '
				<br /><br />
				</div>
				<hr style="border:0;border-top: 1px solid #DDD;" />
				<center>
				<small>
				<font style="color:silver;font-family:\'Helvetica Neue\', sans-sherif">Pro odhlášení odpovězte na tento email slovy "Prosím odhlásit".</font>
				</small>
				</center>
				</body></html>');
        /** @var Nette\Http\FileUpload $attach */
        foreach ($values['files'] as $attach) {
            $mail->addAttachment($attach->getSanitizedName(), $attach->getContents());
        }
        $counter = 0;
        foreach ($contacts as $contact) {
            $counter++;
            $mail->addBcc($contact);
        }
        $mailer = new Nette\Mail\SendmailMailer();
        try {
            $mailer->send($mail);
            if (!$values['notTest']) {
                $this->flashMessage("Byl odeslán testovací email.", 'success');
            } else {
                $this->flashMessage("Bylo odesláno {$counter} emailů.", 'success');
            }
        } catch (\Exception $e) {
            $this->flashMessage('Při odesílání došlo k chybě. :: ' . $e->getMessage());
        }
        $this->redirect('this');
    }