<?php

$main_class = 'usersUnsubscribe';

class usersUnsubscribe extends Frame
{
    use DatabaseCommunication;

    protected $template = 'board/usersUnsubscribe.tpl';

    public function handle()
    {
        $emails = getVal('emails');

        $emails = array_filter(preg_split('/[\s;,]/i', mb_strtolower($emails)));

        if ($emails) {
            $count = sqlQueryBuilder()->update('users')
                ->set('get_news', '"N"')
                ->set('date_updated', 'NOW()')
                ->set('date_unsubscribe', 'NOW()')
                ->where(Query\Operator::inStringArray($emails, 'email'))
                ->execute();

            $this->returnOK("Odhlášeno {$count} uživatelů");
        }
    }
}
