public function add_event()
 {
     if (!$this->isAjax || $this->method != 'POST' || empty($this->postData['user_list_type']) || empty($this->postData['event'])) {
         $this->app->abort(404, $this->setLocalization('Page not found'));
     }
     if ($no_auth = $this->checkAuth()) {
         return $no_auth;
     }
     $data = array();
     $data['action'] = 'addEvent';
     $data['msg'] = $this->setlocalization('Added') . ' ' . $this->setlocalization('for') . ' ';
     $error = $this->setlocalization('Error. Event has not been added.');
     $_SERVER['TARGET'] = 'ADM';
     $event = new \AdminPanelEvents($this->postData);
     $event->setTtl($this->postData['ttl']);
     if (!empty($this->postData['add_post_function']) && !empty($this->postData['post_function']) && !empty($this->postData['param1'])) {
         $event->setPostFunctionParam($this->postData['post_function'], $this->postData['param1']);
     }
     $get_list_func_name = 'get_userlist_' . str_replace('to_', '', $this->postData['user_list_type']);
     $set_event_func_name = 'set_event_' . str_replace('to_', '', $this->postData['event']);
     if ($event->{$get_list_func_name}()->cleanAndSetUsers()->{$set_event_func_name}()) {
         $data['msg'] .= count($event->getUserList()) . ' ' . $this->setlocalization('users');
         $error = '';
     }
     $response = $this->generateAjaxResponse($data, $error);
     return new Response(json_encode($response), empty($error) ? 200 : 500);
 }
<?php

require_once __DIR__ . '/../../admin/vendor/autoload.php';
define('PROJECT_PATH', realpath(dirname(__FILE__) . '/../'));
require_once PROJECT_PATH . '/../storage/config.php';
$run_start_time = time();
$five_minute_interval = $run_start_time - $run_start_time % 300 + 300;
echo strftime('%Y-%m-%d %H:%M:%S', $five_minute_interval), PHP_EOL;
$_SERVER['TARGET'] = 'ADM';
$schedule_events = Mysql::getInstance()->from("`schedule_events`")->where(array('state' => 1, 'date_begin<=' => 'now()'))->where(array('date_end>last_run and date_end>' => 'now()', 'date_end' => 0), 'OR ')->get()->all();
$update_data = array();
$event = new \AdminPanelEvents();
$cronTab = new \CronExpression('* * * * *', new Cron\FieldFactory());
$cronTab->setCurrentTime('now');
foreach ($schedule_events as $row) {
    if (!empty($row['schedule'])) {
        $cronTab->setExpression($row['schedule']);
        $next_run_interval = $five_minute_interval - $cronTab->getNextRunDate()->getTimestamp();
        if ($next_run_interval < 0 || $next_run_interval > 300) {
            continue;
        }
        $event->setTtl((int) $row['ttl']);
        if (!empty($row['post_function']) && !empty($row['param1'])) {
            $event->setPostFunctionParam($row['post_function'], $row['param1']);
        } else {
            $event->setPostFunctionParam('', '');
        }
        if ($add_params = json_decode($row['recipient'], TRUE)) {
            list($user_list_type, $param) = each($add_params);
            $row['user_list_type'] = $user_list_type;
            if (is_array($param)) {