commit ebe1f5bd00e90b740abf6f654be43deef92a01d3 Author: sadmin Date: Tue Jan 13 12:36:57 2026 +0300 sync diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..bd7405a --- /dev/null +++ b/.htaccess @@ -0,0 +1,2 @@ +RewriteEngine on +RewriteRule .? - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] \ No newline at end of file diff --git a/_api_server_vue_20.11.2020.rar b/_api_server_vue_20.11.2020.rar new file mode 100644 index 0000000..5381d9c Binary files /dev/null and b/_api_server_vue_20.11.2020.rar differ diff --git a/api_24.10.2018.rar b/api_24.10.2018.rar new file mode 100644 index 0000000..260a3f7 Binary files /dev/null and b/api_24.10.2018.rar differ diff --git a/connection.php b/connection.php new file mode 100644 index 0000000..9a8bdea --- /dev/null +++ b/connection.php @@ -0,0 +1,41 @@ + $Database, 'UID' => $UID, 'PWD' => $PWD); +$conn = sqlsrv_connect($serverName, $connectionInfo); +if ($conn) { + header('Content-Type:text/html; charset=UTF-8', true, 200); +} else { + header('Content-Type:text/html; charset=UTF-8', true, 301); + if (($errors = sqlsrv_errors()) != null) { + foreach ($errors as $error) { + echo "SQLSTATE: ".$error[ 'SQLSTATE']."
"; + echo "code: ".$error[ 'code']."
"; + echo "message: ".iconv('windows-1251', 'UTF-8', $error['message'])."
"; + } + } +} + diff --git a/core.php b/core.php new file mode 100644 index 0000000..9a5b18f --- /dev/null +++ b/core.php @@ -0,0 +1,44 @@ + + * @author Anant Narayanan + * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD + * @link https://github.com/firebase/php-jwt + */ +class JWT +{ + + /** + * When checking nbf, iat or expiration times, + * we want to provide some extra leeway time to + * account for clock skew. + */ + public static $leeway = 0; + + /** + * Allow the current timestamp to be specified. + * Useful for fixing a value within unit testing. + * + * Will default to PHP time() value if null. + */ + public static $timestamp = null; + + public static $supported_algs = array( + 'HS256' => array('hash_hmac', 'SHA256'), + 'HS512' => array('hash_hmac', 'SHA512'), + 'HS384' => array('hash_hmac', 'SHA384'), + 'RS256' => array('openssl', 'SHA256'), + 'RS384' => array('openssl', 'SHA384'), + 'RS512' => array('openssl', 'SHA512'), + ); + + /** + * Decodes a JWT string into a PHP object. + * + * @param string $jwt The JWT + * @param string|array $key The key, or map of keys. + * If the algorithm used is asymmetric, this is the public key + * @param array $allowed_algs List of supported verification algorithms + * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' + * + * @return object The JWT's payload as a PHP object + * + * @throws UnexpectedValueException Provided JWT was invalid + * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed + * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf' + * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat' + * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim + * + * @uses jsonDecode + * @uses urlsafeB64Decode + */ + public static function decode($jwt, $key, array $allowed_algs = array()) + { + $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp; + + if (empty($key)) { + throw new InvalidArgumentException('Key may not be empty'); + } + $tks = explode('.', $jwt); + if (count($tks) != 3) { + throw new UnexpectedValueException('Wrong number of segments'); + } + list($headb64, $bodyb64, $cryptob64) = $tks; + if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) { + throw new UnexpectedValueException('Invalid header encoding'); + } + if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) { + throw new UnexpectedValueException('Invalid claims encoding'); + } + if (false === ($sig = static::urlsafeB64Decode($cryptob64))) { + throw new UnexpectedValueException('Invalid signature encoding'); + } + if (empty($header->alg)) { + throw new UnexpectedValueException('Empty algorithm'); + } + if (empty(static::$supported_algs[$header->alg])) { + throw new UnexpectedValueException('Algorithm not supported'); + } + if (!in_array($header->alg, $allowed_algs)) { + throw new UnexpectedValueException('Algorithm not allowed'); + } + if (is_array($key) || $key instanceof \ArrayAccess) { + if (isset($header->kid)) { + if (!isset($key[$header->kid])) { + throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key'); + } + $key = $key[$header->kid]; + } else { + throw new UnexpectedValueException('"kid" empty, unable to lookup correct key'); + } + } + + // Check the signature + if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) { + throw new SignatureInvalidException('Signature verification failed'); + } + + // Check if the nbf if it is defined. This is the time that the + // token can actually be used. If it's not yet that time, abort. + if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { + throw new BeforeValidException( + 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf) + ); + } + + // Check that this token has been created before 'now'. This prevents + // using tokens that have been created for later use (and haven't + // correctly used the nbf claim). + if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { + throw new BeforeValidException( + 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat) + ); + } + + // Check if this token has expired. + if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { + throw new ExpiredException('Expired token'); + } + + return $payload; + } + + /** + * Converts and signs a PHP object or array into a JWT string. + * + * @param object|array $payload PHP object or array + * @param string $key The secret key. + * If the algorithm used is asymmetric, this is the private key + * @param string $alg The signing algorithm. + * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' + * @param mixed $keyId + * @param array $head An array with header elements to attach + * + * @return string A signed JWT + * + * @uses jsonEncode + * @uses urlsafeB64Encode + */ + public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null) + { + $header = array('typ' => 'JWT', 'alg' => $alg); + if ($keyId !== null) { + $header['kid'] = $keyId; + } + if ( isset($head) && is_array($head) ) { + $header = array_merge($head, $header); + } + $segments = array(); + $segments[] = static::urlsafeB64Encode(static::jsonEncode($header)); + $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload)); + $signing_input = implode('.', $segments); + + $signature = static::sign($signing_input, $key, $alg); + $segments[] = static::urlsafeB64Encode($signature); + + return implode('.', $segments); + } + + /** + * Sign a string with a given key and algorithm. + * + * @param string $msg The message to sign + * @param string|resource $key The secret key + * @param string $alg The signing algorithm. + * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' + * + * @return string An encrypted message + * + * @throws DomainException Unsupported algorithm was specified + */ + public static function sign($msg, $key, $alg = 'HS256') + { + if (empty(static::$supported_algs[$alg])) { + throw new DomainException('Algorithm not supported'); + } + list($function, $algorithm) = static::$supported_algs[$alg]; + switch($function) { + case 'hash_hmac': + return hash_hmac($algorithm, $msg, $key, true); + case 'openssl': + $signature = ''; + $success = openssl_sign($msg, $signature, $key, $algorithm); + if (!$success) { + throw new DomainException("OpenSSL unable to sign data"); + } else { + return $signature; + } + } + } + + /** + * Verify a signature with the message, key and method. Not all methods + * are symmetric, so we must have a separate verify and sign method. + * + * @param string $msg The original message (header and body) + * @param string $signature The original signature + * @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key + * @param string $alg The algorithm + * + * @return bool + * + * @throws DomainException Invalid Algorithm or OpenSSL failure + */ + private static function verify($msg, $signature, $key, $alg) + { + if (empty(static::$supported_algs[$alg])) { + throw new DomainException('Algorithm not supported'); + } + + list($function, $algorithm) = static::$supported_algs[$alg]; + switch($function) { + case 'openssl': + $success = openssl_verify($msg, $signature, $key, $algorithm); + if ($success === 1) { + return true; + } elseif ($success === 0) { + return false; + } + // returns 1 on success, 0 on failure, -1 on error. + throw new DomainException( + 'OpenSSL error: ' . openssl_error_string() + ); + case 'hash_hmac': + default: + $hash = hash_hmac($algorithm, $msg, $key, true); + if (function_exists('hash_equals')) { + return hash_equals($signature, $hash); + } + $len = min(static::safeStrlen($signature), static::safeStrlen($hash)); + + $status = 0; + for ($i = 0; $i < $len; $i++) { + $status |= (ord($signature[$i]) ^ ord($hash[$i])); + } + $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash)); + + return ($status === 0); + } + } + + /** + * Decode a JSON string into a PHP object. + * + * @param string $input JSON string + * + * @return object Object representation of JSON string + * + * @throws DomainException Provided string was invalid JSON + */ + public static function jsonDecode($input) + { + if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) { + /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you + * to specify that large ints (like Steam Transaction IDs) should be treated as + * strings, rather than the PHP default behaviour of converting them to floats. + */ + $obj = json_decode($input, false, 512, JSON_BIGINT_AS_STRING); + } else { + /** Not all servers will support that, however, so for older versions we must + * manually detect large ints in the JSON string and quote them (thus converting + *them to strings) before decoding, hence the preg_replace() call. + */ + $max_int_length = strlen((string) PHP_INT_MAX) - 1; + $json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input); + $obj = json_decode($json_without_bigints); + } + + if (function_exists('json_last_error') && $errno = json_last_error()) { + static::handleJsonError($errno); + } elseif ($obj === null && $input !== 'null') { + throw new DomainException('Null result with non-null input'); + } + return $obj; + } + + /** + * Encode a PHP object into a JSON string. + * + * @param object|array $input A PHP object or array + * + * @return string JSON representation of the PHP object or array + * + * @throws DomainException Provided object could not be encoded to valid JSON + */ + public static function jsonEncode($input) + { + $json = json_encode($input); + if (function_exists('json_last_error') && $errno = json_last_error()) { + static::handleJsonError($errno); + } elseif ($json === 'null' && $input !== null) { + throw new DomainException('Null result with non-null input'); + } + return $json; + } + + /** + * Decode a string with URL-safe Base64. + * + * @param string $input A Base64 encoded string + * + * @return string A decoded string + */ + public static function urlsafeB64Decode($input) + { + $remainder = strlen($input) % 4; + if ($remainder) { + $padlen = 4 - $remainder; + $input .= str_repeat('=', $padlen); + } + return base64_decode(strtr($input, '-_', '+/')); + } + + /** + * Encode a string with URL-safe Base64. + * + * @param string $input The string you want encoded + * + * @return string The base64 encode of what you passed in + */ + public static function urlsafeB64Encode($input) + { + return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); + } + + /** + * Helper method to create a JSON error. + * + * @param int $errno An error number from json_last_error() + * + * @return void + */ + private static function handleJsonError($errno) + { + $messages = array( + JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', + JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', + JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', + JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', + JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3 + ); + throw new DomainException( + isset($messages[$errno]) + ? $messages[$errno] + : 'Unknown JSON error: ' . $errno + ); + } + + /** + * Get the number of bytes in cryptographic strings. + * + * @param string + * + * @return int + */ + private static function safeStrlen($str) + { + if (function_exists('mb_strlen')) { + return mb_strlen($str, '8bit'); + } + return strlen($str); + } +} diff --git a/libs/hs256.php b/libs/hs256.php new file mode 100644 index 0000000..c89a038 --- /dev/null +++ b/libs/hs256.php @@ -0,0 +1,79 @@ + 'HS256', + 'typ' => 'JWT', +]; + +// JWT Payload data +// $payload = [ +// 'sub' => '1234567890', +// 'name' => 'John Doe', +// 'admin' => true, +// ]; + +// Create the JWT +// $jwt = generateJWT('sha256', $header, $payload, $secret); +//var_dump($jwt); // string(149) "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.6pteLozCETeYDL9Dgm-k4INQ1oEsUf0nFy8Tn2OIxgo" + + +// if (strlen($jwtToken)!==0) { + +// } + + +function verifyJWT(string $algo, string $jwt, string $secret): bool +{ + list($headerEncoded, $payloadEncoded, $signatureEncoded) = explode('.', $jwt); + + $dataEncoded = "$headerEncoded.$payloadEncoded"; + + $signature = base64UrlDecode($signatureEncoded); + + $rawSignature = hash_hmac($algo, $dataEncoded, $secret, true); + + return hash_equals($rawSignature, $signature); +} diff --git a/modules/BOFHeatPhase/BOFHeatPhase.php b/modules/BOFHeatPhase/BOFHeatPhase.php new file mode 100644 index 0000000..6f330db --- /dev/null +++ b/modules/BOFHeatPhase/BOFHeatPhase.php @@ -0,0 +1,21 @@ += '".$params['dateStart']."') + AND (HEAT_END < '".$params['dateEnd']."') + ORDER BY [SHOW_AGGREGATE_ID], [HEAT_START]"; + select($query); + + + + // $query = " + // SET NOCOUNT ON + // DECLARE + // @BD DATETIME = '06.03.2024', + // @ED DATETIME = '08.03.2024' + // SELECT + // PBHR.HEAT_START + // ,HB.[HM_Ladle] as [КЧ] + // ,HB.[TorpNO] as [МП350 №] + // ,HB.[DC_Tap_NO] as [Номер выпуска ДЦ] + // ,HB.[HEAT_NUMBER] as [Номер плавки ККЦ] + // ,HB.[RL_Tare] as [Тара, т] + // ,HB.[RL_Gross] as [Брутто, т] + // ,HB.[RL_Net] as [Нетто, т] + // ,round([RL_Net]-([RL_Net]*0.6/100),0) as [Вес со снятием, т] + // ,0.6 as [Снятие, %] + // ,HB.[AFTDS_CRANEWT_Tare] as [Тара, т ] + // ,HB.[AFTDS_CRANEWT_Gross] as [Брутто, т ] + // ,HB.[AFTDS_CRANEWT_Net] as [Нетто, т ] + // ,HB.[DS_LOSS_wt] as [Снятие на десульфурации, т] + // FROM [PasportBOF].[dbo].[PASPORT_BOFHEATREPORT] PBHR + // INNER JOIN [Level3_KKC].[dbo].[HM_BALANCE] HB + // ON PBHR.HEAT_NUMBER=HB.HEAT_NUMBER + // WHERE (ISNULL(DELETED,0)=0) AND + // (HEAT_START >= '".$params['dateStart']."') + // AND (HEAT_START < '".$params['dateEnd']."') + // ORDER BY [SHOW_AGGREGATE_ID], [HEAT_START]"; + // select($query); + + + // $query = " + // SELECT + // [HM_Ladle] as [КЧ] + // ,[TorpNO] as [МП350 №] + // ,[DC_Tap_NO] as [Номер выпуска ДЦ] + // ,[HEAT_NUMBER] as [Номер плавки ККЦ] + // ,[RL_Tare] as [Тара, т] + // ,[RL_Gross] as [Брутто, т] + // ,[RL_Net] as [Нетто, т] + // ,round([RL_Net]-([RL_Net]*0.6/100),0) as [Вес со снятием, т] + // ,0.6 as [Снятие, %] + // ,[AFTDS_CRANEWT_Tare] as [Тара, т ] + // ,[AFTDS_CRANEWT_Gross] as [Брутто, т ] + // ,[AFTDS_CRANEWT_Net] as [Нетто, т ] + // ,[DS_LOSS_wt] as [Снятие на десульфурации, т] + // FROM [Level3_KKC].[dbo].[HM_BALANCE] + // Where [RL_WT_TIME]>='".$params['dateStart']."' and [RL_WT_TIME] <='".$params['dateEnd']."'"; + // select($query); + + } + public function getData_HMCarReport_SUM($params) + { + $query = " + SELECT + sum([RL_Tare]) [RL_Tare] + ,sum([RL_Gross])[RL_Gross] + ,sum([RL_Net]) [RL_Net] + ,sum(round([RL_Net]-([RL_Net]*0.6/100),0)) [RL_Net1] + ,sum([AFTDS_CRANEWT_Tare])[AFTDS_CRANEWT_Tare] + ,sum([AFTDS_CRANEWT_Gross]) [AFTDS_CRANEWT_Gross] + ,sum([AFTDS_CRANEWT_Net])[AFTDS_CRANEWT_Net] + ,sum([DS_LOSS_wt]) [DS_LOSS_wt] + FROM [Level3_KKC].[dbo].[HM_BALANCE] + Where [RL_WT_TIME]>='".$params['dateStart']."' and [RL_WT_TIME] <='".$params['dateEnd']."'"; + select($query); + } + public function getData_HMCarReport_AVG($params) + { + $query = " + SELECT + avg([RL_Tare]) [RL_Tare] + ,avg([RL_Gross])[RL_Gross] + ,avg([RL_Net]) [RL_Net] + ,avg(round([RL_Net]-([RL_Net]*0.6/100),0)) [RL_Net1] + ,avg([AFTDS_CRANEWT_Tare])[AFTDS_CRANEWT_Tare] + ,avg([AFTDS_CRANEWT_Gross]) [AFTDS_CRANEWT_Gross] + ,avg([AFTDS_CRANEWT_Net])[AFTDS_CRANEWT_Net] + ,avg([DS_LOSS_wt]) [DS_LOSS_wt] + FROM [Level3_KKC].[dbo].[HM_BALANCE] + Where [RL_WT_TIME]>='".$params['dateStart']."' and [RL_WT_TIME] <='".$params['dateEnd']."'"; + select($query); + } +} diff --git a/modules/HM_DC/HM_DC.php b/modules/HM_DC/HM_DC.php new file mode 100644 index 0000000..e17db19 --- /dev/null +++ b/modules/HM_DC/HM_DC.php @@ -0,0 +1,15 @@ + 1"; + select($query); + } + + public function appHeadersById($params) + { + if ($params['isAdmin']) { + $query = "SELECT * + FROM [SITE].[dbo].[kkc_headers] + ORDER BY id"; + } else { + $query = "SELECT * FROM [SITE].[dbo].[get_headers_by_user_id] ('".$params['id_user']."')"; + } + select($query); + } + + public function appAllSubheaders($params) + { + $query = "SELECT * + FROM [SITE].[dbo].[kkc_headers] + WHERE isHeader is not null + and idSubHeader is null + "; + select($query); + } + + public function appVisits($params) + { + $query = "SELECT count([isVisit]) countVisits + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1"; + select($query); + } +} diff --git a/modules/KKC/dashboard.php b/modules/KKC/dashboard.php new file mode 100644 index 0000000..66130e2 --- /dev/null +++ b/modules/KKC/dashboard.php @@ -0,0 +1,300 @@ +='".$params['dateStart']."' and date <='".$params['dateEnd']." 23:59:59' + order by date desc"; + select($query); + } + public function dashboardStatCounts($params) + { + $query = "SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1 + and DATEDIFF(day, date, GETDATE()) = 0 + union all + SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1 + and DATEDIFF(day, date, GETDATE()) = 1 + union all + SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1 + and DATEDIFF(day, date, GETDATE()) <= 7 + union all + SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1 + and DATEDIFF(month, date, GETDATE()) = 0 + union all + SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1 + and DATEDIFF(month, date, GETDATE()) = 1 + union all + SELECT + count(id) as visit_counts + FROM [SITE].[dbo].[kkc_stat] + where [isVisit]=1"; + select($query); + } + ////////////////////////////ITEMS///////////////////////////////////////// + public function dashboardItemsAllHeaders($params) + { + $query = "SELECT * + FROM [SITE].[dbo].[kkc_headers] + ORDER BY id"; + select($query); + } + public function dashboardItemsAdd($params) + { + $convName = iconv('UTF-8', 'windows-1251', $params['data']['name']); + global $conn; + $query = "SET NOCOUNT ON + DECLARE @insert_id int + INSERT INTO [SITE].[dbo].[kkc_headers] + VALUES(".$params['data']['idSubHeader'].", + ".$params['data']['parent'].", + '$convName', + '".$params['data']['path']."', + '".$params['data']['pathFrame']."', + ".$params['data']['isFrame'].", + ".$params['data']['isHeader'].") + SELECT SCOPE_IDENTITY() as insert_id; + SET @insert_id=(SELECT SCOPE_IDENTITY())"; + $result = sqlsrv_query($conn, $query); + sqlsrv_fetch($result); + + if ($params['data']['isFrame']===1) { + $id_insert = sqlsrv_get_field($result, 0); + $query = "UPDATE [SITE].[dbo].[kkc_headers] + SET path='".$params['data']['path']."'+'$id_insert' + WHERE id=$id_insert"; + $result = sqlsrv_query($conn, $query); + sqlsrv_fetch($result); + } + } + public function dashboardItemsEdit($params) + { + $convName = iconv('UTF-8', 'windows-1251', $params['data']['name']); + $query = "UPDATE [SITE].[dbo].[kkc_headers] + SET name='$convName', + path='".$params['data']['path']."', + pathFrame='".$params['data']['pathFrame']."' + WHERE id=".$params['data']['id'].""; + update($query); + } + public function dashboardItemsDelete($params) + { + $query = "DELETE [SITE].[dbo].[kkc_groups_roles] + WHERE id_header in + (select id from [SITE].[dbo].[kkc_headers] + where idSubHeader=".$params['data']['id'].") + + DELETE [SITE].[dbo].[kkc_groups_roles] + WHERE id_header=".$params['data']['id']." + + DELETE [SITE].[dbo].[kkc_headers] + WHERE id=".$params['data']['id']." + OR idSubHeader=".$params['data']['id']." + "; + delete($query); + } + ////////////////////////////USERS///////////////////////////////////////// + public function dashboardUsers($params) + { + $query = "SELECT [id] + ,[ip] + ,[user_desc] + ,[isAdmin] + ,[isBan] + FROM [SITE].[dbo].[kkc_users]"; + select($query); + } + + public function dashboardUsersWithoutAdmin($params) + { + $query = "SELECT [id] + ,[ip] + ,[user_desc] + ,[isAdmin] + ,[isBan] + FROM [SITE].[dbo].[kkc_users] + WHERE isAdmin=0 and isBan=0"; + select($query); + } + + public function dashboardGroups($params) + { + $query = "SELECT + g.id, + g.name, + users.id as user_id, + users.user_desc as user_name, + users.ip as user_ip, + users.isAdmin as isAdmin + FROM [SITE].[dbo].[kkc_groups] g + inner join [SITE].[dbo].[kkc_users_groups] ug on + g.id=ug.group_id + inner join [SITE].[dbo].[kkc_users] users on + ug.user_id=users.id"; + select($query); + } + + public function dashboardUsersAdmin($params) + { + $query = "UPDATE [SITE].[dbo].[kkc_users] + SET isAdmin='".$params['data']['value']."' + WHERE id=".$params['data']['id'].""; + update($query); + } + public function dashboardUsersBan($params) + { + $query = "UPDATE [SITE].[dbo].[kkc_users] + SET isBan='".$params['data']['value']."' + WHERE id=".$params['data']['id'].""; + update($query); + } + + + public function dashboardUsersAdd($params) + { + $name = iconv('UTF-8', 'windows-1251', $params['data']['user_desc']); + $query = "INSERT INTO [SITE].[dbo].[kkc_users] + VALUES('".$params['data']['ip']."', + '$name', + 0,0)"; + insert($query); + } + + public function dashboardUsersEdit($params) + { + $name = iconv('UTF-8', 'windows-1251', $params['data']['user_desc']); + $query = "UPDATE [SITE].[dbo].[kkc_users] + SET [user_desc]='$name', + ip='".$params['data']['ip']."' + WHERE id=".$params['data']['id'].""; + update($query); + } + + public function dashboardUsersDelete($params) + { + $query = "DELETE [SITE].[dbo].[kkc_users] + WHERE id=".$params['data']['id']." + + DELETE [SITE].[dbo].[kkc_users_groups] + WHERE [user_id]=".$params['data']['id'].""; + delete($query); + } + + + ////////////////////////////////GROUPS////////////////////////////////////////////////// + public function dashboardGroupsAll($params) + { + $query = "SELECT g.id, + g.name, + count(ug.id) as group_count + FROM [SITE].[dbo].[kkc_groups] g + left join [SITE].[dbo].[kkc_users_groups] ug on + g.id=ug.group_id + left join [SITE].[dbo].[kkc_users] users on + ug.user_id=users.id + group by g.id, g.name"; + select($query); + } + + public function dashboardUsersGroupsAdd($params) + { + $name = iconv('UTF-8', 'windows-1251', $params['data']['name']); + $query = "INSERT INTO [SITE].[dbo].[kkc_groups] + VALUES('$name')"; + insert($query); + } + + public function dashboardUsersGroupsEdit($params) + { + $name = iconv('UTF-8', 'windows-1251', $params['data']['name']); + $query = "UPDATE [SITE].[dbo].[kkc_groups] + SET [name]='$name' + WHERE id=".$params['data']['id'].""; + update($query); + } + + public function dashboardUsersGroupsDelete($params) + { + $query = "DELETE [SITE].[dbo].[kkc_groups] + WHERE id=".$params['data']['id']." + + DELETE [SITE].[dbo].[kkc_users_groups] + WHERE [group_id]=".$params['data']['id']." + + DELETE [SITE].[dbo].[kkc_groups_roles] + WHERE [id_group]=".$params['data']['id']." + "; + delete($query); + } + + ////////////////////////////////ROLES////////////////////////////////////////////////// + public function dashboardRoles($params) + { + $query = "SELECT [id] + ,[id_group] + ,[id_header] + FROM [SITE].[dbo].[kkc_groups_roles]"; + select($query); + } + + public function dashboardGroupsCheckUser($params) + { + $query = "INSERT INTO [SITE].[dbo].[kkc_users_groups] + VALUES(".$params['data']['userID'].", + ".$params['data']['groupID'].")"; + insert($query); + } + + public function dashboardGroupsUnCheckUser($params) + { + $query = "DELETE [SITE].[dbo].[kkc_users_groups] + WHERE [user_id] =".$params['data']['userID']." + AND [group_id]=".$params['data']['groupID'].""; + delete($query); + } + + public function dashboardRolesDel($params) + { + $query = "DELETE [SITE].[dbo].[kkc_groups_roles] + WHERE [id_group] =".$params['data']['groupId'].""; + delete($query); + } + + public function dashboardRolesAdd($params) + { + foreach ($params['data']['values'] as $key => $value) { + $query = "INSERT INTO [SITE].[dbo].[kkc_groups_roles] + VALUES(".$params['data']['groupId'].", + ".$value['id'].")"; + insert($query); + } + } +} diff --git a/modules/KKC/mega_report.php b/modules/KKC/mega_report.php new file mode 100644 index 0000000..898912b --- /dev/null +++ b/modules/KKC/mega_report.php @@ -0,0 +1,256 @@ +='".$params['dateStart']."' and DT <='".$params['dateEnd']."' + --and BOF_AGGREGATE_ID = 1 + order by HEAT_NUMBER,CCM_ccm,CCM_TREATMENTNO,LF_TREATMENTNO"; + select($query); + } + public function getSteelData($params) + { + $query = "SELECT distinct + hm.[HEAT_NUMBER] + ,[Name] [Установка] + ,convert(varchar, cast(ANALYSISDATE as datetime),108) as 'Время' + ,[Sample_number] [№] + ,[value_1] Fe + ,[value_2] P + ,[value_3] S + ,[value_4] Al + ,[value_5] Cu + ,[value_6] Cr + ,[value_7] N + ,[value_8] V + ,[value_9] Nb + ,[value_10] Ti + ,[value_11] Sn + ,[value_12] C + ,[value_13] Mo + ,[value_14] Si + ,[value_15] W + ,[value_16] Ni + ,[value_17] Mn + ,[value_18] Pb + ,[value_19] Sb + ,[value_20] B + ,[value_21] Zr + ,[value_22] Co + ,[value_23] [As] + ,[value_24] Zn + ,[value_25] Ca + from( + (select distinct HEAT_NUMBER + FROM Level3_KKC.dbo.BOF_CCM_TOTAL_REPORT + Where DT>='".$params['dateStart']."' and DT <='".$params['dateEnd']."')) tr + left join [ANA_Operator].[dbo].[ANA_ALL_TRU] hm + on tr.HEAT_NUMBER=hm.Heat_number + where Sample_number<>0 + and (Name IN ('LF', 'CCM1', 'CCM2', 'VD', 'BOF1', 'BOF2','AS1','AS2', 'DS', 'RL', 'ВАК')) + order by hm.HEAT_NUMBER, hm.Sample_number, Name"; + select($query); + } + public function getHmData($params) + { + $query = "SELECT distinct + hm.[HEAT_NUMBER] + ,[Name] [Установка] + ,convert(varchar, cast(ANALYSISDATE as datetime),108) as 'Время' + ,[Sample_number] [№] + ,[value_1] C + ,[value_2] Si + ,[value_3] Mn + ,[value_4] P + ,[value_5] S + ,[value_6] Cr + ,[value_7] Mo + ,[value_8] Ni + ,[value_9] V + ,[value_10] Al + ,[value_11] Cu + ,[value_12] Ti + ,[value_13] Nb + ,[value_14] W + ,[value_15] [As] + ,[value_16] Sn + ,[value_17] Co + ,[value_18] Pb + ,[value_19] B + ,[value_20] Sb + ,[value_21] Bi + ,[value_22] Zn + ,[value_23] Ce + ,[value_24] Fe + from( + (select distinct HEAT_NUMBER + FROM Level3_KKC.dbo.BOF_CCM_TOTAL_REPORT + Where DT>='".$params['dateStart']."' and DT <='".$params['dateEnd']."')) tr + left join [ANA_Operator].[dbo].[ANA_CHUGUN_ALL_TRU] hm + on tr.HEAT_NUMBER=hm.Heat_number + where Sample_number<>0 + and (Name IN ('LF', 'CCM1', 'CCM2', 'VD', 'BOF1', 'BOF2', 'DS', 'RL', 'ВАК')) + order by hm.HEAT_NUMBER, hm.Sample_number, Name"; + select($query); + } + public function getSlgData($params) + { + $query = "SELECT distinct + hm.[HEAT_NUMBER] + ,[Name] [Установка] + ,convert(varchar, cast(ANALYSISDATE as datetime),108) as 'Время' + ,[Sample_number] [№] + ,[value_1] Al2O3 + ,[value_2] CaO + ,[value_3] MgO + ,[value_4] MnO + ,[value_5] P + ,[value_6] S + ,[value_7] SiO2 + ,[value_8] Fe + ,[value_9] FeOp + ,[value_10] Fe2O3p + ,[value_11] P2O5p + ,[value_12] [Основнось] + from( + (select distinct HEAT_NUMBER + FROM Level3_KKC.dbo.BOF_CCM_TOTAL_REPORT + Where DT>='".$params['dateStart']."' and DT <='".$params['dateEnd']."')) tr + left join + (select * from (select heatno as HEAT_NUMBER + , sampleno as Sample_number + ,ANALYSISDATE, 'LF' as Name + ,[VALUEELEM1] as value_1 + ,[VALUEELEM2] as value_2 + ,[VALUEELEM4] as value_3 + ,[VALUEELEM5] as value_4 + ,'' as value_5 + ,[VALUEELEM7] as value_6 + ,[VALUEELEM8] as value_7 + ,'' as value_8 + ,[VALUEELEM3] as value_9 + ,'' as value_10 + ,[VALUEELEM6] as value_11 + ,'' as value_12 + from [Level3_KKC].[dbo].[QLC_PRO_SLAGANALYSISHEADER_VD_L3] where [PLANTNO] IN (3,4) + union all + SELECT Heat_number as HEAT_NUMBER + , Sample_number as Sample_number + ,ANALYSISDATE as 'ДАТА', name + , value_1 + , value_2 + , value_3 + , value_4 + , value_5 + , value_6 + , value_7 + , value_8 + , value_9 + , value_10 + , value_11 + , value_12 + FROM [ANA_Operator].[dbo].[ANA_SLG_ALL_TRU])a) hm + on tr.HEAT_NUMBER=hm.Heat_number + where Sample_number<>0 + order by hm.HEAT_NUMBER, hm.Sample_number, Name"; + select($query); + } +} diff --git a/modules/LadleUse/LadleUse.php b/modules/LadleUse/LadleUse.php new file mode 100644 index 0000000..022e5ac --- /dev/null +++ b/modules/LadleUse/LadleUse.php @@ -0,0 +1,14 @@ + $l) { + foreach($l as $i => $v) { + $files[$i][$k] = $v; + } + } + } + + foreach ($files as $file) { + $error = $success = ''; + + // Проверим на ошибки загрузки. + if (!empty($file['error']) || empty($file['tmp_name'])) { + switch (@$file['error']) { + case 1: + case 2: $error = 'Превышен размер загружаемого файла.'; break; + case 3: $error = 'Файл был получен только частично.'; break; + case 4: $error = 'Файл не был загружен.'; break; + case 6: $error = 'Файл не загружен - отсутствует временная директория.'; break; + case 7: $error = 'Не удалось записать файл на диск.'; break; + case 8: $error = 'PHP-расширение остановило загрузку файла.'; break; + case 9: $error = 'Файл не был загружен - директория не существует.'; break; + case 10: $error = 'Превышен максимально допустимый размер файла.'; break; + case 11: $error = 'Данный тип файла запрещен.'; break; + case 12: $error = 'Ошибка при копировании файла.'; break; + default: $error = 'Файл не был загружен - неизвестная ошибка.'; break; + } + } elseif ($file['tmp_name'] == 'none' || !is_uploaded_file($file['tmp_name'])) { + $error = 'Не удалось загрузить файл.'; + } else { + // Оставляем в имени файла только буквы, цифры и некоторые символы. + $pattern = "[^a-zа-яё0-9,~!@#%^-_\$\?\(\)\{\}\[\]\.]"; + $name = mb_eregi_replace($pattern, '-', $file['name']); + $name = mb_ereg_replace('[-]+', '-', $name); + + // Т.к. есть проблема с кириллицей в названиях файлов (файлы становятся недоступны). + // Сделаем их транслит: + // $converter = array( + // 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', + // 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k', + // 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', + // 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', + // 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ь' => '', 'ы' => 'y', 'ъ' => '', + // 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', + + // 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', + // 'Ё' => 'E', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I', 'Й' => 'Y', 'К' => 'K', + // 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', + // 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', + // 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch', 'Ь' => '', 'Ы' => 'Y', 'Ъ' => '', + // 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', + // ); + + // $name = strtr($name, $converter); + $parts = pathinfo($name); + + if (empty($name) || empty($parts['extension'])) { + $error = 'Недопустимое тип файла'; + + } elseif (!empty($allow) && !in_array(strtolower($parts['extension']), $allow)) { + $error = 'Недопустимый тип файла'; + + } elseif (!empty($deny) && in_array(strtolower($parts['extension']), $deny)) { + $error = 'Недопустимый тип файла'; + + } else { + //Чтобы не затереть файл с таким же названием, добавим префикс. + // $i = 0; + // $prefix = ''; + // while (is_file($path . $parts['filename'] . $prefix . '.' . $parts['extension'])) { + // $prefix = '(' . ++$i . ')'; + // } + // $name = $parts['filename'] . $prefix . '.' . $parts['extension']; + + date_default_timezone_set('Europe/Moscow'); + $i = 0; + $prefix = '_(' . date("d-m-Y") . ')'; + while (is_file($path . $parts['filename'] . $prefix . '.' . $parts['extension'])) { + $prefix = '_(' . date("d-m-Y") . ')(' . ++$i . ')'; + } + $name = $parts['filename'] . $prefix . '.' . $parts['extension']; + + // Перемещаем файл в директорию. + if (move_uploaded_file($file['tmp_name'], $path . $name)) { + // Далее можно сохранить название файла в БД и т.п. + + $success = 'Файл «' . $name . '» успешно загружен.'; + } else { + $error = 'Не удалось загрузить файл.'; + var_dump(http_response_code(300)); + } + } + } + + // Выводим сообщение о результате загрузки. + if (!empty($success)) { + $post_data = array( + 'success'=>$success, + 'uploadIP'=>$_SERVER['REMOTE_ADDR'], + 'fileName'=>$name, + 'filePATH'=> $path . $name + ); + echo json_encode(array('item' => $post_data), JSON_FORCE_OBJECT); + } else { + var_dump(http_response_code(300)); + } + } +} + +?> \ No newline at end of file diff --git a/modules/PRB_FileControl/PRB_FileControl.php b/modules/PRB_FileControl/PRB_FileControl.php new file mode 100644 index 0000000..db2e279 --- /dev/null +++ b/modules/PRB_FileControl/PRB_FileControl.php @@ -0,0 +1,81 @@ +=ts.datetime + where CAST([CLOSE_TIME] as DATE) between'".$params['dateStart']."' and '".$params['dateEnd']."' + order by [OPEN_TIME] desc, [CLOSE_TIME] desc"; + select($query); + } + public function getDataValues($params) + { + + $query = "SELECT distinct + [HEAT_NAME] + ,[button_all] + ,[opc_T_sample_value] + ,[count] + ,convert(varchar, [datetime], 104) +' '+convert(varchar, [datetime], 108) as [datetime] + FROM [Level3_KKC].[dbo].[HEAT_CCM1_L3] ccm + inner join [Pasport_CCM].[dbo].[OPC_T_Tundish_sample_VALUES] ts + on [OPEN_TIME]<=ts.datetime and CLOSE_TIME>=ts.datetime + where CAST([CLOSE_TIME] as DATE) between'".$params['dateStart']."' and '".$params['dateEnd']."' + order by [datetime] desc"; + select($query); + } +} diff --git a/modules/weatherAvg/weatherAvg.php b/modules/weatherAvg/weatherAvg.php new file mode 100644 index 0000000..1ca831c --- /dev/null +++ b/modules/weatherAvg/weatherAvg.php @@ -0,0 +1,17 @@ + $query, + )); +} +function select($query) +{ + global $sql; + array_push($sql, array( + 'select' => $query, + )); +} +function select_ru($query) +{ + global $sql; + array_push($sql, array( + 'select_ru' => $query, + )); +} +function update($query) +{ + global $sql; + array_push($sql, array( + 'update' => $query, + )); +} +function delete($query) +{ + global $sql; + array_push($sql, array( + 'delete' => $query, + )); +} +function querySelect_ru($sql_query) +{ + global $conn; + global $response; + global $multiSelect; + $result = sqlsrv_query($conn, $sql_query); + $items = array(); + while ($row = sqlsrv_fetch_object($result)) { + foreach ($row as $key=> &$value) { + if (is_string($value)) { + $value = iconv('windows-1251', 'UTF-8', $value); + } + if (is_numeric($value)) { + $value = round($value, 4); + } + $key = iconv('windows-1251', 'UTF-8', $key); + $a[$key]=$value; + } + unset($value); + unset($key); + array_push($items, $a); + } + if (true == $multiSelect) { + array_push($response, $items); + } else { + echo json_encode($items); + } + + if (false === $result) { + if (null != ($errors = sqlsrv_errors())) { + header('Content-Type:text/html; charset=UTF-8', true, 301); + } + } +} + +function querySelect($sql_query) +{ + global $conn; + global $response; + global $multiSelect; + $result = sqlsrv_query($conn, $sql_query); + $items = array(); + while ($row = sqlsrv_fetch_object($result)) { + foreach ($row as &$value) { + if (is_string($value)) { + $value = iconv('windows-1251', 'UTF-8', $value); + } + if (is_numeric($value)) { + $value = round($value, 4); + } + } + unset($value); + $items[] = $row; + } + if (true == $multiSelect) { + array_push($response, $items); + } else { + echo json_encode($items); + } + + if (false === $result) { + if (null != ($errors = sqlsrv_errors())) { + header('Content-Type:text/html; charset=UTF-8', true, 301); + } + } +} +function queryOther($sql_query) +{ + global $conn; + $result = sqlsrv_query($conn, $sql_query); + $rows_affected = sqlsrv_rows_affected($result); + //if (false === $rows_affected) { + if ($rows_affected >= 1) { + header('Content-Type:text/html; charset=UTF-8', true, 200); + } else { + header('Content-Type:text/html; charset=UTF-8', true, 301); + } + //} +} + +// include("libs/hs256.php"); +// include("libs/JWT.php"); +// use \Firebase\JWT\JWT; + +// try { +// $JWTdecoded = JWT::decode($jwtToken, $secret, array('HS256')); +// } catch (\Throwable $th) { + +// } + +include_once 'connection.php'; +include_once 'core.php'; + +$multiSelect = false; +if (isset($params['multiSelect'])) { + $multiSelect = $params['multiSelect']; + if (true == $multiSelect) { + $response = array(); + } +} + +try { + // $query="SELECT id FROM [dbo].[users] where id=$JWTdecoded->id AND is_logged=1"; + // $params = array(); + // $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); + // $stmt = sqlsrv_query($conn, $query, $params, $options); + // $row_count = sqlsrv_num_rows($stmt); + + // if ($row_count === false || $row_count ===0) { + // header('HTTP/1.0 401 Unauthorized'); + // exit; + // } else { + // $verify = verifyJWT('sha256', $jwtToken, $secret); + // if ($verify) { + foreach ($sql as $key => $value) { + $sql_key = array_keys(array_filter($value))[0]; + $sql_query = array_values(array_filter($value))[0]; + if ('select' === $sql_key) { + querySelect($sql_query); + } elseif ('select_ru' === $sql_key) { + querySelect_ru($sql_query); + } else { + //if ($JWTdecoded->role===1) { + queryOther($sql_query); + // } + } + } + // } else { + // header('HTTP/1.0 401 Unauthorized'); + // } + //} +} catch (Throwable $t) { + header($t); +} + +if (true == $multiSelect) { + echo json_encode($response); +} diff --git a/server__.php b/server__.php new file mode 100644 index 0000000..05535a2 --- /dev/null +++ b/server__.php @@ -0,0 +1,169 @@ + $query, + )); +}; +function select($query) +{ + global $sql; + array_push($sql, array( + 'select' => $query, + )); +}; +function update($query) +{ + global $sql; + array_push($sql, array( + 'update' => $query, + )); +}; +function delete($query) +{ + global $sql; + array_push($sql, array( + 'delete' => $query, + )); +}; + +function querySelect($sql_query) +{ + global $conn; + global $response; + global $multiSelect; + $result = sqlsrv_query($conn, $sql_query); + $items=array(); + while ($row = sqlsrv_fetch_object($result)) { + foreach ($row as &$value) { + //if (gettype($value)=="string") { //Бодавский, не удалять!!! + if (is_string($value)) { //added samofalov + $value = iconv('windows-1251', 'UTF-8', $value); + } + if (is_numeric($value)) { //added samofalov + $value =round($value, 3); + } + } + unset($value); + $items[] = $row; + } + if ($multiSelect==true) { + array_push($response, $items); + } else { + echo json_encode($items); + // $test=json_encode($items); + } + + if ($result === false) { + if (($errors = sqlsrv_errors()) != null) { + header('Content-Type:text/html; charset=UTF-8', true, 301); + } + } +}; + +function queryOther($sql_query) +{ + global $conn; + $result = sqlsrv_query($conn, $sql_query); + $rows_affected = sqlsrv_rows_affected($result); + if ($rows_affected === false) { + if ($rows_affected >= 1) { + header('Content-Type:text/html; charset=UTF-8', true, 200); + } else { + header('Content-Type:text/html; charset=UTF-8', true, 301); + } + } +} + + + + + + + +include("libs/hs256.php"); +include("libs/JWT.php"); +use \Firebase\JWT\JWT; + +try { + $JWTdecoded = JWT::decode($jwtToken, $secret, array('HS256')); +} catch (\Throwable $th) { + +} + + +include("connection.php"); + +include("api.php"); + + +$multiSelect=false; +if (isset($params['multiSelect'])) { + $multiSelect=$params['multiSelect']; + if ($multiSelect==true) { + $response=array(); + } +} + + +try { + $query="SELECT id FROM [dbo].[users] where id=$JWTdecoded->id AND is_logged=1"; + $params = array(); + $options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET ); + $stmt = sqlsrv_query($conn, $query, $params, $options); + $row_count = sqlsrv_num_rows($stmt); + + if ($row_count === false || $row_count ===0) { + header('HTTP/1.0 401 Unauthorized'); + exit; + } else { + $verify = verifyJWT('sha256', $jwtToken, $secret); + if ($verify) { + foreach ($sql as $key => $value) { + $sql_key=array_keys(array_filter($value))[0]; + $sql_query=array_values(array_filter($value))[0]; + if ($sql_key==='select') { + querySelect($sql_query); + } else { + if ($JWTdecoded->role===1) { + queryOther($sql_query); + } + } + } + } else { + header('HTTP/1.0 401 Unauthorized'); + } + } +} catch (Throwable $t) { + header($t); +} + +if ($multiSelect==true) { + echo json_encode($response); +}