public function event_scheduler_list_json()
 {
     if ($this->isAjax) {
         if ($no_auth = $this->checkAuth()) {
             return $no_auth;
         }
     }
     $response = array('data' => array(), 'recordsTotal' => 0, 'recordsFiltered' => 0);
     $error = $this->setLocalization("Error");
     $param = !empty($this->data) ? $this->data : array();
     $query_param = $this->prepareDataTableParams($param, array('operations', '_', 'next_run', 'event_trans'));
     if (!isset($query_param['where'])) {
         $query_param['where'] = array();
     }
     $filter = $this->getEventsFilters();
     $query_param['where'] = array_merge($query_param['where'], $filter);
     $filds_for_select = $this->getScheduleEventsFields();
     if (!empty($query_param['select'])) {
         $this->cleanQueryParams($query_param, array_keys($filds_for_select), $filds_for_select);
     } else {
         $query_param['select'] = $filds_for_select;
     }
     if (!array_key_exists('event', $query_param['select'])) {
         $query_param['select']['event'] = $filds_for_select['event'];
     }
     if (!array_key_exists('last_run', $query_param['select'])) {
         $query_param['select']['last_run'] = $filds_for_select['last_run'];
     }
     if (array_key_exists('id', $this->postData)) {
         $query_param['where'] = array('S_E.id' => $this->postData['id']);
         $response['action'] = 'fillModalForm';
     }
     $response['recordsTotal'] = $this->db->getTotalRowsScheduleEvents();
     $response["recordsFiltered"] = $this->db->getTotalRowsScheduleEvents($query_param['where'], $query_param['like']);
     $cronTab = new \CronExpression('* * * * *', new Cron\FieldFactory());
     foreach ($cronTab->getMessageParts() as $key => $val) {
         $cronTab->setMessageParts($key, $this->setLocalization($val));
     }
     $deferred = $this->setLocalization('deferred');
     $unlimited = $this->setLocalization('unlimited');
     $not_run = $this->setLocalization('do not yet running');
     $all_event = array_merge($this->formEvent, $this->hiddenEvent);
     $all_event = array_combine($this->getFieldFromArray($all_event, 'id'), $this->getFieldFromArray($all_event, 'title'));
     $all_recipients = array('to_all' => $this->setLocalization('All'), 'by_group' => $this->setLocalization('Group'), 'to_single' => $this->setLocalization('One'), 'by_filter' => $this->setLocalization('Filter'));
     $response['data'] = array_map(function ($row) use($cronTab, $deferred, $all_event, $all_recipients, $unlimited, $not_run) {
         $cronTab->setCurrentTime($row['last_run']);
         $row['event_trans'] = $all_event[$row['event']];
         $row['post_function'] = array_key_exists($row['post_function'], $all_event) ? $all_event[$row['post_function']] : $row['post_function'];
         $row['date_begin'] = (int) strtotime($row['date_begin']);
         if ($row['date_begin'] < 0) {
             $row['date_begin'] = 0;
         }
         $row['date_end'] = (int) strtotime($row['date_end']);
         if ($row['date_end'] <= 0) {
             $row['date_end'] = $unlimited;
         }
         $row['last_run'] = (int) strtotime($row['last_run']);
         if ($row['last_run'] <= 0) {
             $row['last_run'] = $not_run;
         }
         $row['cron_str'] = $row['schedule'];
         $cronTab->setExpression($row['schedule'])->setMessage();
         if (!empty($row['schedule']) && (int) $row['periodic']) {
             $row['next_run'] = $cronTab->getNextRunDate()->getTimestamp();
             $row['schedule'] = implode(' ', $cronTab->getMessage());
         } else {
             $row['date_end'] = $row['next_run'] = $row['state'] ? $cronTab->getNextRunDate()->getTimestamp() : $deferred;
             $row['schedule'] = $cronTab->getMessageParts('once');
         }
         $recipient = json_decode($row['recipient'], TRUE);
         list($row['recipient'], $recipient) = each($recipient);
         $row['user_list_type'] = $row['recipient'];
         $row['recipient'] = $all_recipients[$row['recipient']];
         if (!empty($recipient) && is_array($recipient)) {
             $row = array_merge($row, (array) $recipient);
         }
         return $row;
     }, $this->db->getScheduleEvents($query_param));
     $response["draw"] = !empty($this->data['draw']) ? $this->data['draw'] : 1;
     $error = '';
     if ($this->isAjax) {
         if (!empty($response['data']) && !empty($this->postData['id'])) {
             $response['data'][0] = array_merge($response['data'][0], array_map(function ($row) {
                 return is_numeric($row) ? str_pad((string) $row, 2, '0', STR_PAD_LEFT) : $row;
             }, \CronForm::getInstance()->setExpression($response['data'][0]['cron_str'])->getFormData()));
             if (array_key_exists('interval', $response['data'][0])) {
                 $response['data'][0]['interval'] = str_replace('0', 'repeating_interval_', $response['data'][0]['interval']);
             }
             $response['data'][0]['type'] = "schedule_type_" . ((int) $response['data'][0]['periodic'] + 1);
         }
         $response = $this->generateAjaxResponse($response);
         return new Response(json_encode($response), empty($error) ? 200 : 500);
     } else {
         return $response;
     }
 }
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)) {
                $row = array_merge($row, $param);