<?php

namespace Ministra\Lib;

use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\f1346478e91df21aff77c1e1db9ef4c7;
use Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\bcb5276dcc10d28aee463111bf6dfaa1;
class Watchdog extends \Ministra\Lib\AjaxResponse implements \Ministra\Lib\StbApi\Watchdog
{
    public function __construct()
    {
        parent::__construct();
    }
    public function getEvents()
    {
        $just_started = isset($_REQUEST['init']) ? (int) $_REQUEST['init'] : 0;
        if (isset($_REQUEST['init']) && \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c::getSafe('log_mac_clones', false) && $just_started == 0 && \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\bcb5276dcc10d28aee463111bf6dfaa1::getInstance()->V041d80d62cca44e2567f80cd78f963cd('just_started') == 0) {
            $clone_ip = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\f1346478e91df21aff77c1e1db9ef4c7::O04df34b7f5a3340f060c3cc166414d74();
            if ($clone_ip) {
                \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\bcb5276dcc10d28aee463111bf6dfaa1::a1ee1f3ba73eab91d9b69d9ad109efe2($clone_ip);
            }
        }
        if ($this->stb->V041d80d62cca44e2567f80cd78f963cd('ip') != $this->stb->ip) {
            $user = \Ministra\Lib\User::getInstance($this->stb->id);
            $user->getInfoFromOSS();
        }
        $this->db->update('users', ['keep_alive' => 'NOW()', 'ip' => $this->stb->ip, 'now_playing_type' => (int) $_REQUEST['cur_play_type'], 'just_started' => $just_started, 'last_watchdog' => 'NOW()'], ['mac' => $this->stb->mac]);
        $events = \Ministra\Lib\Event::getAllNotEndedEvents($this->stb->id);
        $messages = \is_array($events) ? \count($events) : 0;
        $res['data'] = [];
        $res['data']['msgs'] = $messages;
        if ($messages > 0) {
            if ($events[0]['sended'] == 0) {
                \Ministra\Lib\Event::setSended($events[0]['id']);
                if ($events[0]['need_confirm'] == 0) {
                    \Ministra\Lib\Event::setEnded($events[0]['id']);
                }
            }
            if ($events[0]['id'] != @$_GET['data']['event_active_id']) {
                $res['data']['id'] = $events[0]['id'];
                $res['data']['event'] = $events[0]['event'];
                $res['data']['need_confirm'] = $events[0]['need_confirm'];
                $res['data']['msg'] = $events[0]['msg'];
                $res['data']['reboot_after_ok'] = $events[0]['reboot_after_ok'];
                $res['data']['auto_hide_timeout'] = $events[0]['auto_hide_timeout'];
                $res['data']['post_function'] = $events[0]['post_function'];
                $res['data']['param1'] = $events[0]['param1'];
                $res['data']['valid_until'] = \strtotime($events[0]['eventtime']);
                if (\Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c::getSafe('display_send_time_in_message', false)) {
                    $res['data']['send_time'] = $events[0]['addtime'];
                }
            }
        }
        $res['data']['additional_services_on'] = \Ministra\Lib\bd5c9022e9a9029209e5fd05775ea272\K131970f0a776522b1a53ba419cd5e32c::getSafe('enable_tariff_plans', false) ? '1' : $this->stb->additional_services_on;
        return $res;
    }
    public function confirmEvent()
    {
        \Ministra\Lib\Event::setConfirmed((int) $_REQUEST['event_active_id']);
        $res['data'] = 'ok';
        return $res;
    }
}
