<?php
$GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"] = (@$GLOBALS["__65da1b1ec2d6653e8a0ab7848e536" . "215"] ?: array()) + array("_c4d674abe9291be143b224c41195" . "8fcf" => base64_decode("b3duZXI" . "="), "_919910d74305" . "18f92c30b3fd2" . "9c9c851" => base64_decode("VVBEQVRFIG5ld3MgU0VUIG5ld3NfY2" . "hhbm5lbF9pZD1pbnQ6bW92ZV9uZXdz" . "IFdIRVJFIG5ld3NfY2hhbm5lbF9pZD" . "1pbnQ6aWQ="), "_bb8d3ec87162b4f5e2" . "07989fe91db9e2" => base64_decode("RmFpbGVkIHRvIHNhdmUgb" . "mV3cyBjaGFuZWw="), "_3c8b14b38504cea04e67c" . "6a2c53ec412" => base64_decode("bmV3c19jaG" . "FubmVsLmlk"), "_0877a0b" . "48cf424a" . "0de57a45" . "3ce95e30" . "c" => base64_decode("aW50OnV" . "zZXJfaW" . "Q="), "_dafab08d4" . "06ac3a09e8" . "ae01fbabe1" . "92b" => base64_decode("U0VMRUNUIG5ld3NfY2hhbm5lbC4qIEZST00gbmV3c19jaGFubmVsLCBw" . "ZXJtaXNzaW9ucyBXSEVSRSA="), "_df4259c0e" . "9f8944bd3d" . "978b193db0" . "c9c" => base64_decode("Y2hhbm5lbF9uY" . "W1l"), "_4ade992c" . "2c8354f78" . "241af44a5" . "2ad365" => base64_decode("REVMRVRFIEZST00gbmV3c19jaGFubmVsX3VzZXJzCgkJCQlXSEVSRSB1c2VyX2lkIGVxOmludDp1c2VyX2lkCgkJCQlBTkQgbmV3c19jaGFubmVs" . "X2lkIGVxOmludDpjaGFubmVsX2lk"), "i" . "d" => base64_decode("aWQ" . "="), "na" . "me" => base64_decode("bm" . "Ft" . "ZQ" . "=="), "_fbff46fdb" . "5963c3edfa" . "7c97a30072" . "270" => base64_decode("SU5TRVJUIElOVE8gbmV3c19jaGFubmVsX3V" . "zZXJzICh1c2VyX2lkLCBuZXdzX2NoYW5uZW" . "xfaWQpIFNFTEVDVCBpZCwgaW50OmNoX2lkI" . "EZST00gdXNlcnMgV0hFUkUgaWQ8PjE="), "_e9c0f7641e" . "53e0d5b5a2b" . "802d970b6ec" => base64_decode("REVMRVRFIEZST00gbmV3c19jaGFubmVsX3VzZXJzIFdIRVJFIG5ld3NfY2hhbm5lbF9pZCA9IGludDpuZXdzX2" . "NoYW5uZWxfaWQ="), "_4e259f7b99bbc380aa93bb08a23" . "d9fba" => base64_decode("YXJyYXlfcmVwbGFjZ" . "Q=="), "_b19ec89cbd" . "20f9479de5a" . "aa873be4127" => base64_decode("U0VMRUNUICoKCQkJCUZST00gbmV3c19jaGFubmVsX3VzZXJzCgkJCQlXSEVSRSB1c2VyX2lkI" . "GVxOmludDp1c2VyX2lkCgkJCQlBTkQgbmV3c19jaGFubmVsX2lkIGVxOmludDpjaGFubmVsX2" . "lk"), "_97dea5086bb7551c9aa" . "b10f37e124446" => base64_decode("aXNfZGV" . "mYXVsdA" . "=="), "_616bb42f5ea676c1e195fecc7e" . "788df2" => base64_decode("anMtd" . "W5wdW" . "JsaXN" . "o"), "_a591754a8ddcdbda9c80f1db4d" . "911e14" => base64_decode("aXNfb" . "nVsbA" . "=="), "_a7b10c1c75d5251faf18ace1fe37" . "f1a2" => base64_decode("Tm8gbmV3cyBjaGFubm" . "VsIGV4aXN0cyB3aXRo" . "IElEICM="), "templat" . "e" => base64_decode("dGVt" . "cGxh" . "dGU="), "_1713a73314bb1fa00b3cafa93a6" . "ea316" => base64_decode("REVMRVRFIEZST00gbmV3c" . "19jaGFubmVsX3VzZXJzIF" . "dIRVJFIG5ld3NfY2hhbm5" . "lbF9pZD1pbnQ6aWQ="), "_6aaca16e2d21" . "14fffa657b692" . "2e1e712" => base64_decode("aWQuc2VsZWN0" . "ZWQ="), "_11fd26e3588c9a903762012c2c13c" . "162" => base64_decode("aWQ" . "uK2" . "NsY" . "XNz"), "_0769bd64a29d4d0e7a779b77935" . "bf081" => base64_decode("aWQudmFsdWU" . "="), "_b761cc86be02c" . "5003784df4c528" . "a6fa3" => base64_decode("U0VMRUNUIHVzZXJfaWQKCQkJCUZST00gbmV3" . "c19jaGFubmVsX3VzZXJzCgkJCQlXSEVSRSBu" . "ZXdzX2NoYW5uZWxfaWQgZXE6aW50OmNoYW5u" . "ZWxfaWQ="), "_e92cf27b906d8aa7" . "650a6f932443ddf5" => base64_decode("IE9SREVSIEJZIG5ld3NfY2hhbm5l" . "bC5jaGFubmVsX25hbWU="), "_125f1c1" . "6ec22c0a" . "03009aed" . "89fdec5f" . "1" => base64_decode("aW50Om5ld3NfY2hhbm5lbF" . "9pZA=="), "_035eb232f3a4bb1b89abf" . "f269267a597" => base64_decode("U0VMRUNUIGlkIEZST00gbmV3cyBXSEVSRSBoZWFkbGluZT0xIEFORCBuZXdzX2NoYW5uZWxfaWQ" . "9aW50Omlk"), "_4d707fab93bebb00bbe69" . "e8159697c90" => base64_decode(""), "_06a5174" . "4c9cb63a" . "51d6b8b2" . "ec456dd1" . "2" => base64_decode("bmV3c19jaG" . "FubmVs"), "_85ec0a2a3bac9d12e85b6723b875c1f" . "5" => base64_decode("TmV3cyBja" . "GFubmVsIE" . "lEIGlzIG5" . "vdCBzZXQ="), "_9b68bdcd85c0ad0fd" . "e0aefc8d9b3dfba" => base64_decode("bmV3c19jaGFubmVsX" . "3VzZXJz"), "_7490e4e1021f71d" . "6f407abac7f27dc3" . "5" => base64_decode("aWQuYm9ke" . "Q=="));
use Claromentis\Core\Services;
use Claromentis\Core\DAL;
class NewsChannel extends ActiveRecord
{
    
    
    
    
    const DEFAULT_CHANNEL_ID = 1;
    public $id;
    public $name;
    public $is_default;
    public $template;
    public $owner;
    
    
    
    
    protected $permissions;
    public function InitDbMapping(ObjectsStorage $storage)
    {
        $storage->MapDbTable($this, $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_06a51744c9cb63a51" . "d6b8b2ec456dd12"], $GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["i" . "d"]);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["i" . "d"], ObjectsStorage::T_INT);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_df4259c0e9f8944bd3d978" . "b193db0c9c"], ObjectsStorage::T_STRING, 255);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_97dea5086bb75" . "51c9aab10f37e1" . "24446"], ObjectsStorage::T_INT);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["temp" . "late"], ObjectsStorage::T_CLOB);
        $storage->MapDbColumn($this, $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_c4d674abe9291be" . "143b224c411958fc" . "f"], ObjectsStorage::T_INT);
        $storage->SetCacheMode($this, ClaCache::C_SHARED);
    }
    public function GetProperty($_ce76a91ef2b7be07d7d04e74d4da9b6a)
    {
        $_a42c86642011ef739b88ee80672c387d = $this->GetStorage()->GetDbColumns($this);
        if (isset($_a42c86642011ef739b88ee80672c387d[$_ce76a91ef2b7be07d7d04e74d4da9b6a])) {
            
            
            if ($_ce76a91ef2b7be07d7d04e74d4da9b6a == $GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_df4259c0e9f" . "8944bd3d978b" . "193db0c9c"]) {
                $_ce76a91ef2b7be07d7d04e74d4da9b6a = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["na" . "me"];
            }
            return $this->{$_ce76a91ef2b7be07d7d04e74d4da9b6a};
        }
        return null;
    }
    
    
    
    
    
    
    public function __construct($id = null)
    {
        $this->name = $GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_4d707fab93bebb00" . "bbe69e8159697c90"];
        $this->is_default = false;
        $this->owner = 0;
        if (!$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_a591754a8ddcdbda9c8" . "0f1db4d911e14"]($id)) {
            $this->Load($id);
        }
    }
    
    
    
    
    
    
    
    public function Load($id = null)
    {
        if ($GLOBALS["__65da1b1ec2d6653e" . "8a0ab7848e536215"]["_a591754a8ddcdbda9c80f1db4d911" . "e14"]($id)) {
            $id = $this->id;
        } else {
            $this->id = $id;
        }
        if (!$id) {
            return $this->SetErrMsg($GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_85ec0a2a3bac" . "9d12e85b6723b" . "875c1f5"]);
        }
        if (parent::Load($id) === false) {
            return $this->SetErrMsg($GLOBALS["__65da1b1ec2d6" . "653e8a0ab7848e" . "536215"]["_a7b10c1c75" . "d5251faf18a" . "ce1fe37f1a2"] . $id);
        }
        return true;
    }
    
    
    
    
    
    
    public function LoadFromArray($_343a395319323dd7609bcbc465b4d034)
    {
        $this->id = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53621" . "5"]["i" . "d"]];
        $this->name = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_df4259c0e9f8" . "944bd3d978b19" . "3db0c9c"]];
        $this->is_default = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_97dea5086bb7551c9aab10f37" . "e124446"]] ? true : false;
        $this->template = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["templa" . "te"]];
        $this->owner = $_343a395319323dd7609bcbc465b4d034[$GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_c4d674abe9291b" . "e143b224c411958" . "fcf"]];
    }
    
    
    
    
    
    
    
    
    public function Save()
    {
        
        
        $this->is_default = $this->is_default ? 1 : 0;
        $_e72d9ec0d7be4b2da009d8a18fa662a9 = $this->GetStorage()->Save($this);
        if (!$_e72d9ec0d7be4b2da009d8a18fa662a9) {
            return $this->SetErrMsg($GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_bb8d3ec8" . "7162b4f5e" . "207989fe9" . "1db9e2"]);
        }
        $this->id = $_e72d9ec0d7be4b2da009d8a18fa662a9;
        return $_e72d9ec0d7be4b2da009d8a18fa662a9;
    }
    
    
    
    
    
    
    public function GetDisplayName()
    {
        return $this->name;
    }
    
    
    
    
    public function GetPermissions()
    {
        if (!$this->permissions instanceof Permissions) {
            $this->permissions = new Permissions(PERM_CLASS_NEWS_CHANNEL, $this->id);
            $this->permissions->Load();
        }
        return $this->permissions;
    }
    
    
    
    
    
    
    public function UserHasPermission($_1ac701da0834eb6c188cf3ef004a1aca)
    {
        return $this->GetPermissions()->UserHasPermission($_1ac701da0834eb6c188cf3ef004a1aca);
    }
    
    
    
    
    
    
    public function UserCanApprove()
    {
        return $this->UserHasPermission(PERM_APPROVE) || $this->UserHasPermission(PERM_EDIT_APPROVE);
    }
    
    
    
    
    
    
    public function Delete($_8973800324bb90d37ffd58aa1c2b1e02 = null)
    {
        $db = Services::I()->GetDb();
        $channel_id = $this->id;
        if (!$_8973800324bb90d37ffd58aa1c2b1e02) {
            $_1f24efd4735b7a11b391147435e7d35d = $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_035eb232f3a4bb1b89abff269267a59" . "7"], $channel_id);
            while ($row = $_1f24efd4735b7a11b391147435e7d35d->fetchRow()) {
                $item = new NewsItem();
                $item->Load($row[0]);
                $item->Delete();
            }
        } else {
            $db->query($GLOBALS["__65da1b1ec2d66" . "53e8a0ab7848e53" . "6215"]["_919910d7430518f92c" . "30b3fd29c9c851"], $_8973800324bb90d37ffd58aa1c2b1e02, $channel_id);
        }
        $db->query($GLOBALS["__65da1b1ec2d6653e8a0a" . "b7848e536215"]["_e9c0f764" . "1e53e0d5b" . "5a2b802d9" . "70b6ec"], $channel_id);
        $this->GetStorage()->Delete($this);
    }
    
    
    
    
    
    public function SubscribeAll()
    {
        $db = Services::I()->GetDb();
        $db->query($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_1713a73314bb1fa00b3cafa93a6ea" . "316"], $this->id);
        $db->query($GLOBALS["__65da1b1ec2d6653e8a" . "0ab7848e536215"]["_fbff46fdb5963c3edfa7c97a" . "30072270"], $this->id);
    }
    
    
    
    
    public function Subscribe()
    {
        if ($this->IsSubscribed() == false) {
            $db = Services::I()->GetDb();
            $db->DisableTokenCheck();
            $_7f5aa4e96d4b415a86ed72ebff677cbe = new DAL\QueryInsert($GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_9b68bdcd85c0ad0fde0aefc" . "8d9b3dfba"], [$GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_0877a0b48" . "cf424a0de5" . "7a453ce95e" . "30c"] => AuthUser::I()->GetId(), $GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_125f1c16ec22c0a030" . "09aed89fdec5f1"] => $this->id]);
            $db->query($_7f5aa4e96d4b415a86ed72ebff677cbe);
            $db->EnableTokenCheck();
        }
    }
    
    
    
    
    public function Unsubscribe()
    {
        if ($this->IsSubscribed() == true) {
            $db = Services::I()->GetDb();
            $db->DisableTokenCheck();
            $_1f24efd4735b7a11b391147435e7d35d = $db->query($GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_4ade992c2c8354f78241" . "af44a52ad365"], AuthUser::I()->GetId(), $this->id);
            $db->EnableTokenCheck();
        }
    }
    
    
    
    
    public function IsSubscribed()
    {
        $_1f24efd4735b7a11b391147435e7d35d = Services::I()->GetDb()->query($GLOBALS["__65da1b1ec2d6653e8a0" . "ab7848e536215"]["_b19ec89cbd20f9479d" . "e5aaa873be4127"], AuthUser::I()->GetId(), $this->id);
        return $_1f24efd4735b7a11b391147435e7d35d->hasData();
    }
    
    
    
    
    public function GetSubscribers()
    {
        $_1f24efd4735b7a11b391147435e7d35d = Services::I()->GetDb()->query($GLOBALS["__65da1b1ec2d6653e8a0ab7848e5362" . "15"]["_b761cc86be02c5003784" . "df4c528a6fa3"], $this->id);
        return $_1f24efd4735b7a11b391147435e7d35d->fetchAllValues();
    }
    
    
    
    
    
    
    
    
    public static function ShowChannelsSelect($selected = null, $is_admin = true)
    {
        $channels = static::GetList($is_admin ? 0 : PERM_EDIT);
        $_f274035cf280fb57c0c9ef54d849a83d = array();
        $_a4e45bcaa40df1b0ba8f156afaca4a06 = false;
        foreach ($channels as $channel) {
            $_189840d11056515e52402d1412a0b6e4 = array();
            $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2d6653e8a0ab7848e53" . "6215"]["_0769bd64a29d4d0e7a779b7793" . "5bf081"]] = $channel->id;
            $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"]["_7490e4e1021f71d" . "6f407abac7f27dc3" . "5"]] = $channel->GetDisplayName();
            if (!$is_admin && !$channel->UserCanApprove()) {
                $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_11fd26e358" . "8c9a9037620" . "12c2c13c162"]] = $GLOBALS["__65da1b1" . "ec2d6653e" . "8a0ab7848" . "e536215"]["_616bb42f5ea676c1e195fecc7e788d" . "f2"];
            }
            if (!$_a4e45bcaa40df1b0ba8f156afaca4a06) {
                $_e29a0f53fc0db0fa791e9966536e61e5 = $GLOBALS["__65da1b1e" . "c2d6653e8a" . "0ab7848e53" . "6215"]["_a591754a8ddcdbda9c80f1" . "db4d911e14"]($selected) && $channel->id == self::DEFAULT_CHANNEL_ID;
            }
            $_9295971fa2fc22cd84228ccc7b4e17c0 = $channel->id === $selected;
            $_a4e45bcaa40df1b0ba8f156afaca4a06 = $_189840d11056515e52402d1412a0b6e4[$GLOBALS["__65da1b1ec2d" . "6653e8a0ab784" . "8e536215"]["_6aaca16e2d2" . "114fffa657b6" . "922e1e712"]] = $_e29a0f53fc0db0fa791e9966536e61e5 || $_9295971fa2fc22cd84228ccc7b4e17c0;
            $_f274035cf280fb57c0c9ef54d849a83d[] = $_189840d11056515e52402d1412a0b6e4;
        }
        return $_f274035cf280fb57c0c9ef54d849a83d;
    }
    
    
    
    
    
    
    
    public static function GetList($perms)
    {
        $_f274035cf280fb57c0c9ef54d849a83d = [];
        $_63ea8031ac60963aed4f8f066366fc71 = null;
        $db = Services::I()->GetDb();
        $_189840d11056515e52402d1412a0b6e4 = $db->query($GLOBALS["__65da1b1ec" . "2d6653e8a0a" . "b7848e53621" . "5"]["_dafab08d406ac3a09e8ae01fbab" . "e192b"] . Permissions::SQLCheck(PERM_CLASS_NEWS_CHANNEL, $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_3c8b14b385" . "04cea04e67c" . "6a2c53ec412"], $perms) . $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_e92cf27b9" . "06d8aa7650" . "a6f932443d" . "df5"]);
        while ($_343a395319323dd7609bcbc465b4d034 = $_189840d11056515e52402d1412a0b6e4->fetchArray()) {
            $channel = new NewsChannel();
            $channel->LoadFromArray($_343a395319323dd7609bcbc465b4d034);
            if ($channel->id == self::DEFAULT_CHANNEL_ID) {
                $_63ea8031ac60963aed4f8f066366fc71 = $channel;
            } else {
                $_f274035cf280fb57c0c9ef54d849a83d[$channel->id] = $channel;
            }
        }
        
        
        if ($_63ea8031ac60963aed4f8f066366fc71) {
            $_f274035cf280fb57c0c9ef54d849a83d = $GLOBALS["__65da1b1ec2d665" . "3e8a0ab7848e5362" . "15"]["_4e259f7b99bbc380aa93bb" . "08a23d9fba"]($_f274035cf280fb57c0c9ef54d849a83d, [self::DEFAULT_CHANNEL_ID => $_63ea8031ac60963aed4f8f066366fc71]);
        }
        return $_f274035cf280fb57c0c9ef54d849a83d;
    }
    
    
    
    
    
    
    public static function GetAll()
    {
        return static::GetList(0);
    }
}