Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32dee1692e | ||
|
|
6291ed88c0 | ||
|
|
5e21ead6fa | ||
|
|
07fbd13213 | ||
|
|
44b825310a | ||
|
|
2c234ccef6 | ||
|
|
b493b3c4fd | ||
|
|
e7dd96b5d9 | ||
|
|
bcde36ac17 | ||
|
|
8bde34ec7d | ||
|
|
a345d71306 | ||
|
|
0ff6294faa | ||
|
|
757d7ae01d | ||
|
|
4e78b21c67 | ||
|
|
d7e6434808 | ||
|
|
443cc2751d | ||
|
|
cf6500b55a | ||
|
|
09c2ec653f |
43
.eslintrc.js
43
.eslintrc.js
@@ -1,43 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
'env': {
|
|
||||||
'browser': true,
|
|
||||||
'es6': true,
|
|
||||||
'commonjs': true,
|
|
||||||
'jquery': true
|
|
||||||
},
|
|
||||||
'extends': 'eslint:recommended',
|
|
||||||
'parserOptions': {
|
|
||||||
'ecmaVersion': 6
|
|
||||||
},
|
|
||||||
'rules': {
|
|
||||||
'indent': [
|
|
||||||
'error',
|
|
||||||
'tab',
|
|
||||||
{
|
|
||||||
'SwitchCase': 1
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'linebreak-style': [
|
|
||||||
'error',
|
|
||||||
'unix'
|
|
||||||
],
|
|
||||||
'quotes': [
|
|
||||||
'error',
|
|
||||||
'single'
|
|
||||||
],
|
|
||||||
'semi': [
|
|
||||||
'error',
|
|
||||||
'always'
|
|
||||||
],
|
|
||||||
'no-console': 'off',
|
|
||||||
'no-unused-vars': [
|
|
||||||
'error', {
|
|
||||||
'vars': 'all',
|
|
||||||
'args': 'after-used',
|
|
||||||
'ignoreRestSiblings': false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
// Requires eslint >= v8.14.0
|
|
||||||
'no-constant-binary-expression': 'error'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -48,7 +48,7 @@ header("Content-Type: application/json; charset=UTF-8");
|
|||||||
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
||||||
header("HTTP/1.1 401 Unauthorized");
|
header("HTTP/1.1 401 Unauthorized");
|
||||||
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if server request type is get set file_get to null -> no body
|
// if server request type is get set file_get to null -> no body
|
||||||
@@ -57,7 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
|||||||
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
||||||
header("HTTP/1.1 404 Not Found");
|
header("HTTP/1.1 404 Not Found");
|
||||||
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
print buildContent($http_headers, $file_get);
|
print buildContent($http_headers, $file_get);
|
||||||
|
|||||||
@@ -926,48 +926,114 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
public function daysIntervalProvider(): array
|
public function daysIntervalProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'valid interval /, not named array' => [
|
// normal and format tests
|
||||||
'2020/1/1',
|
'valid interval / not named array' => [
|
||||||
'2020/1/30',
|
'input_a' => '2020/1/1',
|
||||||
false,
|
'input_b' => '2020/1/30',
|
||||||
[29, 22, 8],
|
'return_named' => false, // return_named
|
||||||
|
'include_end_date' => true, // include_end_date
|
||||||
|
'exclude_start_date' => false, // exclude_start_date
|
||||||
|
'expected' => [30, 22, 8, false],
|
||||||
],
|
],
|
||||||
'valid interval /, named array' => [
|
'valid interval / named array' => [
|
||||||
'2020/1/1',
|
'input_a' => '2020/1/1',
|
||||||
'2020/1/30',
|
'input_b' => '2020/1/30',
|
||||||
true,
|
'return_named' => true,
|
||||||
['overall' => 29, 'weekday' => 22, 'weekend' => 8],
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => ['overall' => 30, 'weekday' => 22, 'weekend' => 8, 'reverse' => false],
|
||||||
],
|
],
|
||||||
'valid interval -' => [
|
'valid interval with "-"' => [
|
||||||
'2020-1-1',
|
'input_a' => '2020-1-1',
|
||||||
'2020-1-30',
|
'input_b' => '2020-1-30',
|
||||||
false,
|
'return_named' => false,
|
||||||
[29, 22, 8],
|
'include_end_date' => true,
|
||||||
],
|
'exclude_start_date' => false,
|
||||||
'valid interval switched' => [
|
'expected' => [30, 22, 8, false],
|
||||||
'2020/1/30',
|
|
||||||
'2020/1/1',
|
|
||||||
false,
|
|
||||||
[28, 0, 0],
|
|
||||||
],
|
],
|
||||||
'valid interval with time' => [
|
'valid interval with time' => [
|
||||||
'2020/1/1 12:12:12',
|
'input_a' => '2020/1/1 12:12:12',
|
||||||
'2020/1/30 13:13:13',
|
'input_b' => '2020/1/30 13:13:13',
|
||||||
false,
|
'return_named' => false,
|
||||||
[28, 21, 8],
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [30, 22, 8, false],
|
||||||
],
|
],
|
||||||
|
// invalid
|
||||||
'invalid dates' => [
|
'invalid dates' => [
|
||||||
'abc',
|
'input_a' => 'abc',
|
||||||
'xyz',
|
'input_b' => 'xyz',
|
||||||
false,
|
'return_named' => false,
|
||||||
[0, 0, 0]
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [0, 0, 0, false]
|
||||||
],
|
],
|
||||||
// this test will take a long imte
|
// this test will take a long time
|
||||||
'out of bound dates' => [
|
'out of bound dates' => [
|
||||||
'1900-1-1',
|
'input_a' => '1900-1-1',
|
||||||
'9999-12-31',
|
'input_b' => '9999-12-31',
|
||||||
false,
|
'return_named' => false,
|
||||||
[2958463,2113189,845274],
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [2958463, 2113189, 845274, false],
|
||||||
|
],
|
||||||
|
// tests for include/exclude
|
||||||
|
'exclude end date' => [
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => false,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [29, 21, 8, false],
|
||||||
|
],
|
||||||
|
'exclude start date' => [
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => true,
|
||||||
|
'expected' => [29, 21, 8, false],
|
||||||
|
],
|
||||||
|
'exclude start and end date' => [
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => false,
|
||||||
|
'exclude_start_date' => true,
|
||||||
|
'expected' => [28, 20, 8, false],
|
||||||
|
],
|
||||||
|
// reverse
|
||||||
|
'reverse: valid interval' => [
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [30, 22, 8, true],
|
||||||
|
],
|
||||||
|
'reverse: exclude end date' => [
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => false,
|
||||||
|
'exclude_start_date' => false,
|
||||||
|
'expected' => [29, 21, 8, true],
|
||||||
|
],
|
||||||
|
'reverse: exclude start date' => [
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => true,
|
||||||
|
'exclude_start_date' => true,
|
||||||
|
'expected' => [29, 21, 8, true],
|
||||||
|
],
|
||||||
|
'reverse: exclude start and end date' => [
|
||||||
|
'input_a' => '2020/1/30',
|
||||||
|
'input_b' => '2020/1/1',
|
||||||
|
'return_named' => false,
|
||||||
|
'include_end_date' => false,
|
||||||
|
'exclude_start_date' => true,
|
||||||
|
'expected' => [28, 20, 8, true],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -982,19 +1048,27 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @param string $input_a
|
* @param string $input_a
|
||||||
* @param string $input_b
|
* @param string $input_b
|
||||||
* @param bool $flag
|
* @param bool $return_named
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testCalcDaysInterval(
|
public function testCalcDaysInterval(
|
||||||
string $input_a,
|
string $input_a,
|
||||||
string $input_b,
|
string $input_b,
|
||||||
bool $flag,
|
bool $return_named,
|
||||||
|
bool $include_end_date,
|
||||||
|
bool $exclude_start_date,
|
||||||
$expected
|
$expected
|
||||||
): void {
|
): void {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
\CoreLibs\Combined\DateTime::calcDaysInterval($input_a, $input_b, $flag)
|
\CoreLibs\Combined\DateTime::calcDaysInterval(
|
||||||
|
$input_a,
|
||||||
|
$input_b,
|
||||||
|
return_named:$return_named,
|
||||||
|
include_end_date:$include_end_date,
|
||||||
|
exclude_start_date:$exclude_start_date
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1187,7 +1261,38 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
'2023-07-03',
|
'2023-07-03',
|
||||||
'2023-07-27',
|
'2023-07-27',
|
||||||
true
|
true
|
||||||
]
|
],
|
||||||
|
// reverse
|
||||||
|
'reverse: no weekend' => [
|
||||||
|
'2023-07-04',
|
||||||
|
'2023-07-03',
|
||||||
|
false
|
||||||
|
],
|
||||||
|
'reverse: start weekend sat' => [
|
||||||
|
'2023-07-04',
|
||||||
|
'2023-07-01',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'reverse: start weekend sun' => [
|
||||||
|
'2023-07-04',
|
||||||
|
'2023-07-02',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'reverse: end weekend sat' => [
|
||||||
|
'2023-07-08',
|
||||||
|
'2023-07-03',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'reverse: end weekend sun' => [
|
||||||
|
'2023-07-09',
|
||||||
|
'2023-07-03',
|
||||||
|
true
|
||||||
|
],
|
||||||
|
'reverse: long period > 6 days' => [
|
||||||
|
'2023-07-27',
|
||||||
|
'2023-07-03',
|
||||||
|
true
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3692,7 +3692,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function preparedProviderValue(): array
|
public function providerDbGetPrepareCursorValue(): array
|
||||||
{
|
{
|
||||||
// 1: query (can be empty for do not set)
|
// 1: query (can be empty for do not set)
|
||||||
// 2: stm name
|
// 2: stm name
|
||||||
@@ -3736,7 +3736,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
* test return prepare cursor errors
|
* test return prepare cursor errors
|
||||||
*
|
*
|
||||||
* @covers ::dbGetPrepareCursorValue
|
* @covers ::dbGetPrepareCursorValue
|
||||||
* @dataProvider preparedProviderValue
|
* @dataProvider providerDbGetPrepareCursorValue
|
||||||
* @testdox prepared query $stm_name with $key expect error id $error_id [$_dataName]
|
* @testdox prepared query $stm_name with $key expect error id $error_id [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query
|
||||||
@@ -3769,6 +3769,94 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerDbPreparedCursorStatus(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'empty statement pararm' => [
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'stm_name' => 'test_stm_a',
|
||||||
|
'check_stm_name' => '',
|
||||||
|
'check_query' => '',
|
||||||
|
'expected' => false
|
||||||
|
],
|
||||||
|
'different stm_name' => [
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'stm_name' => 'test_stm_b',
|
||||||
|
'check_stm_name' => 'other_name',
|
||||||
|
'check_query' => '',
|
||||||
|
'expected' => 0
|
||||||
|
],
|
||||||
|
'same stm_name' => [
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'stm_name' => 'test_stm_c',
|
||||||
|
'check_stm_name' => 'test_stm_c',
|
||||||
|
'check_query' => '',
|
||||||
|
'expected' => 1
|
||||||
|
],
|
||||||
|
'same stm_name and query' => [
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'stm_name' => 'test_stm_d',
|
||||||
|
'check_stm_name' => 'test_stm_d',
|
||||||
|
'check_query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'expected' => 2
|
||||||
|
],
|
||||||
|
'same stm_name and different query' => [
|
||||||
|
'query' => 'SELECT row_int, uid FROM table_with_primary_key',
|
||||||
|
'stm_name' => 'test_stm_e',
|
||||||
|
'check_stm_name' => 'test_stm_e',
|
||||||
|
'check_query' => 'SELECT row_int, uid, row_int FROM table_with_primary_key',
|
||||||
|
'expected' => 1
|
||||||
|
],
|
||||||
|
'insert query test' => [
|
||||||
|
'query' => 'INSERT INTO table_with_primary_key (row_int, uid) VALUES ($1, $2)',
|
||||||
|
'stm_name' => 'test_stm_f',
|
||||||
|
'check_stm_name' => 'test_stm_f',
|
||||||
|
'check_query' => 'INSERT INTO table_with_primary_key (row_int, uid) VALUES ($1, $2)',
|
||||||
|
'expected' => 2
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test cursor status for prepared statement
|
||||||
|
*
|
||||||
|
* @covers ::dbPreparedCursorStatus
|
||||||
|
* @dataProvider providerDbPreparedCursorStatus
|
||||||
|
* @testdox Check prepared $stm_name ($check_stm_name) status is $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $query
|
||||||
|
* @param string $stm_name
|
||||||
|
* @param string $check_stm_name
|
||||||
|
* @param string $check_query
|
||||||
|
* @param bool|int $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDbPreparedCursorStatus(
|
||||||
|
string $query,
|
||||||
|
string $stm_name,
|
||||||
|
string $check_stm_name,
|
||||||
|
string $check_query,
|
||||||
|
bool|int $expected
|
||||||
|
): void {
|
||||||
|
$db = new \CoreLibs\DB\IO(
|
||||||
|
self::$db_config['valid'],
|
||||||
|
self::$log
|
||||||
|
);
|
||||||
|
$db->dbPrepare($stm_name, $query);
|
||||||
|
// $db->dbExecute($stm_name);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$db->dbPreparedCursorStatus($check_stm_name, $check_query),
|
||||||
|
'check prepared stement cursor status'
|
||||||
|
);
|
||||||
|
unset($db);
|
||||||
|
}
|
||||||
|
|
||||||
// - schema set/get tests
|
// - schema set/get tests
|
||||||
// dbGetSchema, dbSetSchema
|
// dbGetSchema, dbSetSchema
|
||||||
|
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
}
|
}
|
||||||
$per_run_id = $log->getLogUniqueId();
|
$per_run_id = $log->getLogUniqueId();
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
"/^\d{4}-\d{2}-\d{2}_\d{6}_U_[a-z0-9]{8}$/",
|
"/^\d{4}-\d{2}-\d{2}_\d{6}\.U_[a-z0-9]{8}$/",
|
||||||
$per_run_id,
|
$per_run_id,
|
||||||
'assert per log run id 1st'
|
'assert per log run id 1st'
|
||||||
);
|
);
|
||||||
@@ -403,7 +403,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
$log->setLogUniqueId(true);
|
$log->setLogUniqueId(true);
|
||||||
$per_run_id_2nd = $log->getLogUniqueId();
|
$per_run_id_2nd = $log->getLogUniqueId();
|
||||||
$this->assertMatchesRegularExpression(
|
$this->assertMatchesRegularExpression(
|
||||||
"/^\d{4}-\d{2}-\d{2}_\d{6}_U_[a-z0-9]{8}$/",
|
"/^\d{4}-\d{2}-\d{2}_\d{6}\.U_[a-z0-9]{8}$/",
|
||||||
$per_run_id_2nd,
|
$per_run_id_2nd,
|
||||||
'assert per log run id 2nd'
|
'assert per log run id 2nd'
|
||||||
);
|
);
|
||||||
@@ -824,13 +824,13 @@ final class CoreLibsLoggingLoggingTest extends TestCase
|
|||||||
$this->assertTrue($log_ok, 'assert ::log (debug) OK');
|
$this->assertTrue($log_ok, 'assert ::log (debug) OK');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$log->getLogFile(),
|
$log->getLogFile(),
|
||||||
$log->getLogFileId() . '_DEBUG.log'
|
$log->getLogFileId() . '.DEBUG.log'
|
||||||
);
|
);
|
||||||
$log_ok = $log->log(Level::Info, 'INFO', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
$log_ok = $log->log(Level::Info, 'INFO', group_id: 'GROUP_ID', prefix: 'PREFIX:');
|
||||||
$this->assertTrue($log_ok, 'assert ::log (info) OK');
|
$this->assertTrue($log_ok, 'assert ::log (info) OK');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$log->getLogFile(),
|
$log->getLogFile(),
|
||||||
$log->getLogFileId() . '_INFO.log'
|
$log->getLogFileId() . '.INFO.log'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -969,44 +969,76 @@ final class CoreLibsUrlRequestsCurlTest extends TestCase
|
|||||||
"query" => ["foo-get" => "bar"]
|
"query" => ["foo-get" => "bar"]
|
||||||
]);
|
]);
|
||||||
$this->assertEquals("200", $response["code"], "multi call: get response code not matching");
|
$this->assertEquals("200", $response["code"], "multi call: get response code not matching");
|
||||||
$this->assertEquals(
|
if (PHP_VERSION_ID >= 80400) {
|
||||||
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
$this->assertEquals(
|
||||||
. '"HTTP_FIRST_CALL":"get","HTTP_ACCEPT":"*\/*",'
|
'{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",'
|
||||||
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
. '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1","HTTP_FIRST_CALL":"get",'
|
||||||
. '"REQUEST_TYPE":"GET",'
|
. '"HTTP_ACCEPT":"*\/*"},"REQUEST_TYPE":"GET","PARAMS":{"foo-get":"bar"},"BODY":null}',
|
||||||
. '"PARAMS":{"foo-get":"bar"},"BODY":null}',
|
$response['content'],
|
||||||
$response['content'],
|
'multi call: get content not matching'
|
||||||
'multi call: get content not matching'
|
);
|
||||||
);
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
||||||
|
. '"HTTP_FIRST_CALL":"get","HTTP_ACCEPT":"*\/*",'
|
||||||
|
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
||||||
|
. '"REQUEST_TYPE":"GET",'
|
||||||
|
. '"PARAMS":{"foo-get":"bar"},"BODY":null}',
|
||||||
|
$response['content'],
|
||||||
|
'multi call: get content not matching'
|
||||||
|
);
|
||||||
|
}
|
||||||
// post
|
// post
|
||||||
$response = $curl->post($this->url_basic, [
|
$response = $curl->post($this->url_basic, [
|
||||||
"headers" => ["second-call" => "post"],
|
"headers" => ["second-call" => "post"],
|
||||||
"body" => ["foo-post" => "baz"]
|
"body" => ["foo-post" => "baz"]
|
||||||
]);
|
]);
|
||||||
$this->assertEquals("200", $response["code"], "multi call: post response code not matching");
|
$this->assertEquals("200", $response["code"], "multi call: post response code not matching");
|
||||||
$this->assertEquals(
|
if (PHP_VERSION_ID >= 80400) {
|
||||||
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
$this->assertEquals(
|
||||||
. '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*",'
|
'{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",'
|
||||||
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
. '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
||||||
. '"REQUEST_TYPE":"POST",'
|
. '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*"},'
|
||||||
. '"PARAMS":[],"BODY":{"foo-post":"baz"}}',
|
. '"REQUEST_TYPE":"POST","PARAMS":[],"BODY":{"foo-post":"baz"}}',
|
||||||
$response['content'],
|
$response['content'],
|
||||||
'multi call: post content not matching'
|
'multi call: post content not matching'
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
||||||
|
. '"HTTP_SECOND_CALL":"post","HTTP_ACCEPT":"*\/*",'
|
||||||
|
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
||||||
|
. '"REQUEST_TYPE":"POST",'
|
||||||
|
. '"PARAMS":[],"BODY":{"foo-post":"baz"}}',
|
||||||
|
$response['content'],
|
||||||
|
'multi call: post content not matching'
|
||||||
|
);
|
||||||
|
}
|
||||||
// delete
|
// delete
|
||||||
$response = $curl->delete($this->url_basic, [
|
$response = $curl->delete($this->url_basic, [
|
||||||
"headers" => ["third-call" => "delete"],
|
"headers" => ["third-call" => "delete"],
|
||||||
]);
|
]);
|
||||||
$this->assertEquals("200", $response["code"], "multi call: delete response code not matching");
|
$this->assertEquals("200", $response["code"], "multi call: delete response code not matching");
|
||||||
$this->assertEquals(
|
if (PHP_VERSION_ID >= 80400) {
|
||||||
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
$this->assertEquals(
|
||||||
. '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*",'
|
'{"HEADERS":{"HTTP_HOST":"soba.egplusww.jp",'
|
||||||
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
. '"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
||||||
. '"REQUEST_TYPE":"DELETE",'
|
. '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*"},'
|
||||||
. '"PARAMS":[],"BODY":[]}',
|
. '"REQUEST_TYPE":"DELETE","PARAMS":[],"BODY":[]}',
|
||||||
$response['content'],
|
$response['content'],
|
||||||
'multi call: delete content not matching'
|
'multi call: delete content not matching'
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
'{"HEADERS":{"HTTP_USER_AGENT":"CoreLibsUrlRequestCurl\/1",'
|
||||||
|
. '"HTTP_THIRD_CALL":"delete","HTTP_ACCEPT":"*\/*",'
|
||||||
|
. '"HTTP_HOST":"soba.egplusww.jp"},'
|
||||||
|
. '"REQUEST_TYPE":"DELETE",'
|
||||||
|
. '"PARAMS":[],"BODY":[]}',
|
||||||
|
$response['content'],
|
||||||
|
'multi call: delete content not matching'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: auth header set via config
|
// MARK: auth header set via config
|
||||||
|
|||||||
59
eslint.config.mjs
Normal file
59
eslint.config.mjs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import globals from 'globals';
|
||||||
|
import pluginJs from '@eslint/js';
|
||||||
|
|
||||||
|
/*
|
||||||
|
module.exports = {
|
||||||
|
// in globals block
|
||||||
|
'extends': 'eslint:recommended',
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 6
|
||||||
|
},
|
||||||
|
// rules copied
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @type {import('eslint').Linter.Config[]} */
|
||||||
|
export default [
|
||||||
|
{languageOptions: {
|
||||||
|
globals: {
|
||||||
|
...globals.browser,
|
||||||
|
...globals.jquery
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
pluginJs.configs.recommended,
|
||||||
|
{
|
||||||
|
'rules': {
|
||||||
|
'indent': [
|
||||||
|
'error',
|
||||||
|
'tab',
|
||||||
|
{
|
||||||
|
'SwitchCase': 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
// 'quotes': [
|
||||||
|
// 'error',
|
||||||
|
// 'single'
|
||||||
|
// ],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'no-console': 'off',
|
||||||
|
'no-unused-vars': [
|
||||||
|
'error', {
|
||||||
|
'vars': 'all',
|
||||||
|
'args': 'after-used',
|
||||||
|
'ignoreRestSiblings': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// Requires eslint >= v8.14.0
|
||||||
|
'no-constant-binary-expression': 'error'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
|
// https://www.typescriptlang.org/tsconfig/#compilerOptions
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"moduleResolution": "Node",
|
"moduleResolution": "Node",
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
|
"checkJs": true,
|
||||||
"allowImportingTsExtensions": true,
|
"allowImportingTsExtensions": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictFunctionTypes": true
|
"strictFunctionTypes": true
|
||||||
|
|||||||
1567
package-lock.json
generated
Normal file
1567
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
package.json
Normal file
17
package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "core-libraries",
|
||||||
|
"version": "9.26.8",
|
||||||
|
"main": "",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "Clemens Schwaighofer",
|
||||||
|
"license": "",
|
||||||
|
"description": "Core Libraries",
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.20.0",
|
||||||
|
"esbuild": "^0.25.0",
|
||||||
|
"eslint": "^9.20.1",
|
||||||
|
"globals": "^15.15.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ header("Content-Type: application/json; charset=UTF-8");
|
|||||||
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
if (!empty($http_headers['HTTP_AUTHORIZATION']) && !empty($http_headers['HTTP_RUNAUTHTEST'])) {
|
||||||
header("HTTP/1.1 401 Unauthorized");
|
header("HTTP/1.1 401 Unauthorized");
|
||||||
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
print buildContent($http_headers, '{"code": 401, "content": {"Error": "Not Authorized"}}');
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if server request type is get set file_get to null -> no body
|
// if server request type is get set file_get to null -> no body
|
||||||
@@ -61,7 +61,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") {
|
|||||||
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
} elseif (($file_get = file_get_contents('php://input')) === false) {
|
||||||
header("HTTP/1.1 404 Not Found");
|
header("HTTP/1.1 404 Not Found");
|
||||||
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
print buildContent($http_headers, '{"code": 404, "content": {"Error": "file_get_contents failed"}}');
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
// str_replace('\"', '"', trim($file_get, '"'));
|
// str_replace('\"', '"', trim($file_get, '"'));
|
||||||
|
|
||||||
|
|||||||
@@ -268,7 +268,9 @@ foreach ($compare_datetimes as $compare_datetime) {
|
|||||||
print "COMPAREDATE: $compare_datetime[0] = $compare_datetime[1]: "
|
print "COMPAREDATE: $compare_datetime[0] = $compare_datetime[1]: "
|
||||||
. (string)DateTime::compareDateTime($compare_datetime[0], $compare_datetime[1]) . "<br>";
|
. (string)DateTime::compareDateTime($compare_datetime[0], $compare_datetime[1]) . "<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
print "<h2>calcDaysInterval</h2>";
|
||||||
$compare_dates = [
|
$compare_dates = [
|
||||||
[ '2021-05-01', '2021-05-10', ],
|
[ '2021-05-01', '2021-05-10', ],
|
||||||
[ '2021-05-10', '2021-05-01', ],
|
[ '2021-05-10', '2021-05-01', ],
|
||||||
@@ -279,9 +281,21 @@ foreach ($compare_dates as $compare_date) {
|
|||||||
print "CALCDAYSINTERVAL: $compare_date[0] = $compare_date[1]: "
|
print "CALCDAYSINTERVAL: $compare_date[0] = $compare_date[1]: "
|
||||||
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1])) . "<br>";
|
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1])) . "<br>";
|
||||||
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: "
|
print "CALCDAYSINTERVAL(named): $compare_date[0] = $compare_date[1]: "
|
||||||
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], true)) . "<br>";
|
. DgS::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], return_named:true)) . "<br>";
|
||||||
|
print "CALCDAYSINTERVAL(EXCLUDE END): $compare_date[0] = $compare_date[1]: "
|
||||||
|
. Dgs::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], include_end_date:false));
|
||||||
|
print "CALCDAYSINTERVAL(EXCLUDE START): $compare_date[0] = $compare_date[1]: "
|
||||||
|
. Dgs::printAr(DateTime::calcDaysInterval($compare_date[0], $compare_date[1], exclude_start_date:true));
|
||||||
|
print "CALCDAYSINTERVAL(EXCLUDE END, EXCLUDE START): $compare_date[0] = $compare_date[1]: "
|
||||||
|
. Dgs::printAr(DateTime::calcDaysInterval(
|
||||||
|
$compare_date[0],
|
||||||
|
$compare_date[1],
|
||||||
|
include_end_date:false,
|
||||||
|
exclude_start_date:true
|
||||||
|
));
|
||||||
}
|
}
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
print "<h2>setWeekdayNameFromIsoDow</h2>";
|
||||||
// test date conversion
|
// test date conversion
|
||||||
$dow = 2;
|
$dow = 2;
|
||||||
print "DOW[$dow]: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
|
print "DOW[$dow]: " . DateTime::setWeekdayNameFromIsoDow($dow) . "<br>";
|
||||||
@@ -297,26 +311,25 @@ $date = '2022-70-242';
|
|||||||
print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
|
print "DATE-dow[$date];invalid: " . DateTime::setWeekdayNameFromDate($date) . "<br>";
|
||||||
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
|
print "DATE-dow[$date],long;invalid: " . DateTime::setWeekdayNameFromDate($date, true) . "<br>";
|
||||||
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
|
print "DOW-date[$date];invalid: " . DateTime::setWeekdayNumberFromDate($date) . "<br>";
|
||||||
print "<hr>";
|
|
||||||
// check date range includes a weekend
|
|
||||||
// does not:
|
|
||||||
$start_date = '2023-07-03';
|
|
||||||
$end_date = '2023-07-05';
|
|
||||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
|
||||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
|
||||||
$start_date = '2023-07-03';
|
|
||||||
$end_date = '2023-07-10';
|
|
||||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
|
||||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
|
||||||
$start_date = '2023-07-03';
|
|
||||||
$end_date = '2023-07-31';
|
|
||||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
|
||||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
|
||||||
$start_date = '2023-07-01';
|
|
||||||
$end_date = '2023-07-03';
|
|
||||||
print "Has Weekend: " . $start_date . " ~ " . $end_date . ": "
|
|
||||||
. Dgs::prBl(DateTime::dateRangeHasWeekend($start_date, $end_date)) . "<br>";
|
|
||||||
|
|
||||||
|
print "<hr>";
|
||||||
|
print "<h2>dateRangeHasWeekend</h2>";
|
||||||
|
// check date range includes a weekend
|
||||||
|
$has_weekend_list = [
|
||||||
|
['2023-07-03', '2023-07-05'],
|
||||||
|
['2023-07-03', '2023-07-10'],
|
||||||
|
['2023-07-03', '2023-07-31'],
|
||||||
|
['2023-07-01', '2023-07-03'],
|
||||||
|
['2023-07-01', '2023-07-01'],
|
||||||
|
['2023-07-01', '2023-07-02'],
|
||||||
|
['2023-06-30', '2023-07-01'],
|
||||||
|
['2023-06-30', '2023-06-30'],
|
||||||
|
['2023-07-01', '2023-06-30'],
|
||||||
|
];
|
||||||
|
foreach ($has_weekend_list as $days) {
|
||||||
|
print "Has Weekend: " . $days[0] . " ~ " . $days[1] . ": "
|
||||||
|
. Dgs::prBl(DateTime::dateRangeHasWeekend($days[0], $days[1])) . "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
|||||||
@@ -707,6 +707,17 @@ if (
|
|||||||
} else {
|
} else {
|
||||||
print "[PGB] [3] pgb_sel_test_foo prepare OK<br>";
|
print "[PGB] [3] pgb_sel_test_foo prepare OK<br>";
|
||||||
}
|
}
|
||||||
|
$stm_status = $db->dbPreparedCursorStatus('');
|
||||||
|
print "[PGB] Empty statement name: " . $log->prAr($stm_status) . "<br>";
|
||||||
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foobar');
|
||||||
|
print "[PGB] Prepared name not match status: $stm_status<br>";
|
||||||
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo');
|
||||||
|
print "[PGB] Prepared name match status: $stm_status<br>";
|
||||||
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', $q_prep);
|
||||||
|
print "[PGB] prepared exists and query match status: $stm_status<br>";
|
||||||
|
$stm_status = $db->dbPreparedCursorStatus('pgb_sel_test_foo', "SELECT * FROM test_foo");
|
||||||
|
print "[PGB] prepared exists and query not match status: $stm_status<br>";
|
||||||
|
|
||||||
$db_pgb->dbClose();
|
$db_pgb->dbClose();
|
||||||
|
|
||||||
# db write class test
|
# db write class test
|
||||||
|
|||||||
107
www/admin/class_test.deprecated.helper.php
Normal file
107
www/admin/class_test.deprecated.helper.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?php // phpcs:ignore warning
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
error_reporting(E_ALL | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
|
||||||
|
// basic class test file
|
||||||
|
define('USE_DATABASE', false);
|
||||||
|
// sample config
|
||||||
|
require 'config.php';
|
||||||
|
// define log file id
|
||||||
|
$LOG_FILE_ID = 'classTest-phpv';
|
||||||
|
ob_end_flush();
|
||||||
|
|
||||||
|
$log = new CoreLibs\Logging\Logging([
|
||||||
|
'log_folder' => BASE . LOG,
|
||||||
|
'log_file_id' => $LOG_FILE_ID,
|
||||||
|
'log_per_date' => true,
|
||||||
|
]);
|
||||||
|
$_phpv = new CoreLibs\Check\PhpVersion();
|
||||||
|
$phpv_class = 'CoreLibs\Check\PhpVersion';
|
||||||
|
|
||||||
|
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||||
|
print "<body>";
|
||||||
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||||
|
|
||||||
|
// fputcsv
|
||||||
|
print "<h3>\CoreLibs\DeprecatedHelper\Deprecated84::fputcsv()</h3>";
|
||||||
|
$test_csv = BASE . TMP . 'DeprecatedHelper.test.csv';
|
||||||
|
print "File: $test_csv<br>";
|
||||||
|
|
||||||
|
$fp = fopen($test_csv, "w");
|
||||||
|
if (!is_resource($fp)) {
|
||||||
|
die("Cannot open file: $test_csv");
|
||||||
|
}
|
||||||
|
\CoreLibs\DeprecatedHelper\Deprecated84::fputcsv($fp, ["A", "B", "C"]);
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
$fp = fopen($test_csv, "r");
|
||||||
|
if (!is_resource($fp)) {
|
||||||
|
die("Cannot open file: $test_csv");
|
||||||
|
}
|
||||||
|
while ($entry = \CoreLibs\DeprecatedHelper\Deprecated84::fgetcsv($fp)) {
|
||||||
|
print "fgetcsv: <pre>" . print_r($entry, true) . "</pre>";
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
$out = \CoreLibs\DeprecatedHelper\Deprecated84::str_getcsv("A,B,C");
|
||||||
|
print "str_getcsv: <pre>" . print_r($out, true) . "</pre>";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* temporary different CSV function, because fgetcsv seems to be broken on some systems
|
||||||
|
* (does not read out japanese text)
|
||||||
|
*
|
||||||
|
* @param string $string full line for csv split
|
||||||
|
* @param string $encoding optional, if given, converts string to the internal encoding
|
||||||
|
* before we do anything
|
||||||
|
* @param string $delimiter sepperate character, default ','
|
||||||
|
* @param string $enclosure string line marker, default '"'
|
||||||
|
* @param string $flag INTERN | EXTERN. if INTERN uses the PHP function, else uses explode
|
||||||
|
* @return array<int,string|null> array with split data from input line
|
||||||
|
*/
|
||||||
|
function mtParseCSV(
|
||||||
|
string $string,
|
||||||
|
string $encoding = '',
|
||||||
|
string $delimiter = ',',
|
||||||
|
string $enclosure = '"',
|
||||||
|
string $flag = 'INTERN'
|
||||||
|
): array {
|
||||||
|
$lines = [];
|
||||||
|
if ($encoding) {
|
||||||
|
$string = \CoreLibs\Convert\Encoding::convertEncoding(
|
||||||
|
$string,
|
||||||
|
'UTF-8',
|
||||||
|
$encoding
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($flag == 'INTERN') {
|
||||||
|
// split with PHP function
|
||||||
|
$lines = str_getcsv($string, $delimiter, $enclosure);
|
||||||
|
} else {
|
||||||
|
// split up with delimiter
|
||||||
|
$lines = explode(',', $string) ?: [];
|
||||||
|
}
|
||||||
|
// strip " from beginning and end of line
|
||||||
|
for ($i = 0; $i < count($lines); $i++) {
|
||||||
|
// remove line breaks
|
||||||
|
$lines[$i] = preg_replace("/\r\n?/", '', (string)$lines[$i]) ?? '';
|
||||||
|
// lingering " at the beginning and end of the line
|
||||||
|
$lines[$i] = preg_replace("/^\"/", '', (string)$lines[$i]) ?? '';
|
||||||
|
$lines[$i] = preg_replace("/\"$/", '', (string)$lines[$i]) ?? '';
|
||||||
|
}
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
print "</body></html>";
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -117,7 +117,7 @@ if (isset($login->loginGetAcl()['unit'])) {
|
|||||||
if ($login->loginCheckEditAccessCuid($edit_access_cuid)) {
|
if ($login->loginCheckEditAccessCuid($edit_access_cuid)) {
|
||||||
print "Set new:" . $edit_access_cuid . "<br>";
|
print "Set new:" . $edit_access_cuid . "<br>";
|
||||||
} else {
|
} else {
|
||||||
print "Load default unit id: " . $login->loginGetAcl()['unit_id'] . "<br>";
|
print "Load default unit id: " . $login->loginGetAcl()['unit_cuid'] . "<br>";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "Something went wrong with the login<br>";
|
print "Something went wrong with the login<br>";
|
||||||
@@ -140,4 +140,17 @@ $login->writeLog(
|
|||||||
write_type:'JSON'
|
write_type:'JSON'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
echo "<hr>";
|
||||||
|
print "<h3>Legacy Lookups</h3>";
|
||||||
|
|
||||||
|
$edit_access_id = 1;
|
||||||
|
$edit_access_cuid = $login->loginGetEditAccessCuidFromId($edit_access_id);
|
||||||
|
$edit_access_id_rev = null;
|
||||||
|
if (is_string($edit_access_cuid)) {
|
||||||
|
$edit_access_id_rev = $login->loginGetEditAccessIdFromCuid($edit_access_cuid);
|
||||||
|
}
|
||||||
|
print "EA ID: " . $edit_access_id . "<br>";
|
||||||
|
print "EA CUID: " . $log->prAr($edit_access_cuid) . "<br>";
|
||||||
|
print "REV EA CUID: " . $log->prAr($edit_access_id_rev) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ $test_files = [
|
|||||||
'class_test.error_msg.php' => 'Class Test: ERROR MSG',
|
'class_test.error_msg.php' => 'Class Test: ERROR MSG',
|
||||||
'class_test.url-requests.curl.php' => 'Class Test: URL REQUESTS: CURL',
|
'class_test.url-requests.curl.php' => 'Class Test: URL REQUESTS: CURL',
|
||||||
'subfolder/class_test.config.direct.php' => 'Class Test: CONFIG DIRECT SUB',
|
'subfolder/class_test.config.direct.php' => 'Class Test: CONFIG DIRECT SUB',
|
||||||
|
'class_test.deprecated.helper.php' => 'Class Test: DEPRECATED HELPERS',
|
||||||
];
|
];
|
||||||
|
|
||||||
asort($test_files);
|
asort($test_files);
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ $log = new CoreLibs\Logging\Logging([
|
|||||||
$_phpv = new CoreLibs\Check\PhpVersion();
|
$_phpv = new CoreLibs\Check\PhpVersion();
|
||||||
$phpv_class = 'CoreLibs\Check\PhpVersion';
|
$phpv_class = 'CoreLibs\Check\PhpVersion';
|
||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
|
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/* general edit javascript */
|
/* general edit javascript */
|
||||||
/* jquery version */
|
/* jquery version */
|
||||||
|
|
||||||
/* jshint esversion: 11 */
|
|
||||||
|
|
||||||
/* global i18n */
|
/* global i18n */
|
||||||
|
|
||||||
// debug set
|
// debug set
|
||||||
@@ -18,6 +16,21 @@ if (!DEBUG) {
|
|||||||
var GL_OB_S = 100;
|
var GL_OB_S = 100;
|
||||||
var GL_OB_BASE = 100;
|
var GL_OB_BASE = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets html element or throws an error
|
||||||
|
* @param {string} el_id Element ID to get
|
||||||
|
* @returns {HTMLElement}
|
||||||
|
* @throws Error
|
||||||
|
*/
|
||||||
|
function loadEl(el_id)
|
||||||
|
{
|
||||||
|
let el = document.getElementById(el_id);
|
||||||
|
if (el === null) {
|
||||||
|
throw new Error('Cannot find: ' + el_id);
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* opens a popup window with winName and given features (string)
|
* opens a popup window with winName and given features (string)
|
||||||
* @param {String} theURL the url
|
* @param {String} theURL the url
|
||||||
@@ -156,6 +169,18 @@ function goToPos(element, offset = 0, duration = 500, base = 'body,html') // esl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* go to element, scroll
|
||||||
|
* non jquery
|
||||||
|
* @param {string} target
|
||||||
|
*/
|
||||||
|
function goTo(target) // eslint-disable-line no-unused-vars
|
||||||
|
{
|
||||||
|
loadEl(target).scrollIntoView({
|
||||||
|
behavior: 'smooth'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uses the i18n object created in the translation template
|
* uses the i18n object created in the translation template
|
||||||
* that is filled from gettext in PHP
|
* that is filled from gettext in PHP
|
||||||
@@ -402,9 +427,9 @@ function keyInObject(key, object)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* returns matching key of value
|
* returns matching key of value
|
||||||
* @param {Object} obj object to search value in
|
* @param {Object} object object to search value in
|
||||||
* @param {Mixed} value any value (String, Number, etc)
|
* @param {Mixed} value any value (String, Number, etc)
|
||||||
* @return {String} the key found for the first matching value
|
* @return {String} the key found for the first matching value
|
||||||
*/
|
*/
|
||||||
function getKeyByValue(object, value) // eslint-disable-line no-unused-vars
|
function getKeyByValue(object, value) // eslint-disable-line no-unused-vars
|
||||||
{
|
{
|
||||||
@@ -416,9 +441,9 @@ function getKeyByValue(object, value) // eslint-disable-line no-unused-vars
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* returns true if value is found in object with a key
|
* returns true if value is found in object with a key
|
||||||
* @param {Object} obj object to search value in
|
* @param {Object} object object to search value in
|
||||||
* @param {Mixed} value any value (String, Number, etc)
|
* @param {Mixed} value any value (String, Number, etc)
|
||||||
* @return {Boolean} true on value found, false on not found
|
* @return {Boolean} true on value found, false on not found
|
||||||
*/
|
*/
|
||||||
function valueInObject(object, value) // eslint-disable-line no-unused-vars
|
function valueInObject(object, value) // eslint-disable-line no-unused-vars
|
||||||
{
|
{
|
||||||
@@ -533,22 +558,20 @@ function errorCatch(err)
|
|||||||
if (err.stack) {
|
if (err.stack) {
|
||||||
// only FF
|
// only FF
|
||||||
if (err.lineNumber) {
|
if (err.lineNumber) {
|
||||||
console.log('ERROR[%s:%s] %s', err.name, err.lineNumber, err.message);
|
console.error('ERROR[%s:%s] ', err.name, err.lineNumber, err);
|
||||||
} else if (err.line) {
|
} else if (err.line) {
|
||||||
// only Safari
|
// only Safari
|
||||||
console.log('ERROR[%s:%s] %s', err.name, err.line, err.message);
|
console.error('ERROR[%s:%s] ', err.name, err.line, err);
|
||||||
} else {
|
} else {
|
||||||
console.log('ERROR[%s] %s', err.name, err.message);
|
console.error('ERROR[%s] ', err.name, err);
|
||||||
}
|
}
|
||||||
// stack trace
|
|
||||||
console.log('ERROR[stack] %s', err.stack);
|
|
||||||
} else if (err.number) {
|
} else if (err.number) {
|
||||||
// IE
|
// IE
|
||||||
console.log('ERROR[%s:%s] %s', err.name, err.number, err.message);
|
console.error('ERROR[%s:%s] %s', err.name, err.number, err.message);
|
||||||
console.log('ERROR[description] %s', err.description);
|
console.error('ERROR[description] %s', err.description);
|
||||||
} else {
|
} else {
|
||||||
// the rest
|
// the rest
|
||||||
console.log('ERROR[%s] %s', err.name, err.message);
|
console.error('ERROR[%s] %s', err.name, err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -800,7 +823,7 @@ function showOverlayBoxLayers(el_id) // eslint-disable-line no-unused-vars
|
|||||||
* else just set zIndex to the new GL_OB_S value
|
* else just set zIndex to the new GL_OB_S value
|
||||||
* @param {String} el_id Target to hide layer
|
* @param {String} el_id Target to hide layer
|
||||||
*/
|
*/
|
||||||
function hideOverlayBoxLayers(el_id)
|
function hideOverlayBoxLayers(el_id='')
|
||||||
{
|
{
|
||||||
// console.log('HIDE overlaybox: %s', GL_OB_S);
|
// console.log('HIDE overlaybox: %s', GL_OB_S);
|
||||||
// remove on layer
|
// remove on layer
|
||||||
@@ -1113,7 +1136,9 @@ function phfa(list) // eslint-disable-line no-unused-vars
|
|||||||
function html_options(name, data, selected = '', options_only = false, return_string = false, sort = '') // eslint-disable-line no-unused-vars
|
function html_options(name, data, selected = '', options_only = false, return_string = false, sort = '') // eslint-disable-line no-unused-vars
|
||||||
{
|
{
|
||||||
// wrapper to new call
|
// wrapper to new call
|
||||||
return html_options_block(name, data, selected, false, options_only, return_string, sort);
|
return html_options_block(
|
||||||
|
name, data, selected, 0, options_only, return_string, sort
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1135,8 +1160,9 @@ function html_options(name, data, selected = '', options_only = false, return_st
|
|||||||
* @param {String} [onchange=''] onchange trigger call, default unset
|
* @param {String} [onchange=''] onchange trigger call, default unset
|
||||||
* @return {String} html with build options block
|
* @return {String} html with build options block
|
||||||
*/
|
*/
|
||||||
function html_options_block(name, data, selected = '', multiple = 0, options_only = false, return_string = false, sort = '', onchange = '')
|
function html_options_block(
|
||||||
{
|
name, data, selected = '', multiple = 0, options_only = false, return_string = false, sort = '', onchange = ''
|
||||||
|
) {
|
||||||
var content = [];
|
var content = [];
|
||||||
var element_select;
|
var element_select;
|
||||||
var select_options = {};
|
var select_options = {};
|
||||||
@@ -1173,7 +1199,8 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl
|
|||||||
// basic options init
|
// basic options init
|
||||||
options = {
|
options = {
|
||||||
'label': value,
|
'label': value,
|
||||||
'value': key
|
'value': key,
|
||||||
|
'selected': ''
|
||||||
};
|
};
|
||||||
// add selected if matching
|
// add selected if matching
|
||||||
if (multiple == 0 && !Array.isArray(selected) && selected == key) {
|
if (multiple == 0 && !Array.isArray(selected) && selected == key) {
|
||||||
@@ -1184,7 +1211,7 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl
|
|||||||
options.selected = '';
|
options.selected = '';
|
||||||
}
|
}
|
||||||
// create the element option
|
// create the element option
|
||||||
element_option = cel('option', '', value, '', options);
|
element_option = cel('option', '', value, [], options);
|
||||||
// attach it to the select element
|
// attach it to the select element
|
||||||
ael(element_select, element_option);
|
ael(element_select, element_option);
|
||||||
}
|
}
|
||||||
@@ -1236,7 +1263,7 @@ function html_options_refill(name, data, sort = '') // eslint-disable-line no-un
|
|||||||
[].forEach.call(document.querySelectorAll('#' + name + ' :checked'), function(elm) {
|
[].forEach.call(document.querySelectorAll('#' + name + ' :checked'), function(elm) {
|
||||||
option_selected = elm.value;
|
option_selected = elm.value;
|
||||||
});
|
});
|
||||||
document.getElementById(name).innerHTML = '';
|
loadEl(name).innerHTML = '';
|
||||||
for (const key of data_list) {
|
for (const key of data_list) {
|
||||||
value = data[key];
|
value = data[key];
|
||||||
// console.log('add [%s] options: key: %s, value: %s', name, key, value);
|
// console.log('add [%s] options: key: %s, value: %s', name, key, value);
|
||||||
@@ -1247,7 +1274,7 @@ function html_options_refill(name, data, sort = '') // eslint-disable-line no-un
|
|||||||
if (key == option_selected) {
|
if (key == option_selected) {
|
||||||
element_option.selected = true;
|
element_option.selected = true;
|
||||||
}
|
}
|
||||||
document.getElementById(name).appendChild(element_option);
|
loadEl(name).appendChild(element_option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1311,7 +1338,7 @@ function parseQueryString(query = '', return_key = '') // eslint-disable-line no
|
|||||||
* all parameters are returned
|
* all parameters are returned
|
||||||
* @param {String} [query=''] different query string to parse, if not
|
* @param {String} [query=''] different query string to parse, if not
|
||||||
* set (default) the current window href is used
|
* set (default) the current window href is used
|
||||||
* @param {Bool} [single=false] if set to true then only the first found
|
* @param {Boolean} [single=false] if set to true then only the first found
|
||||||
* will be returned
|
* will be returned
|
||||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||||
* and only one entry, then string, else array
|
* and only one entry, then string, else array
|
||||||
@@ -1323,7 +1350,7 @@ function getQueryStringParam(search = '', query = '', single = false) // eslint-
|
|||||||
query = window.location.href;
|
query = window.location.href;
|
||||||
}
|
}
|
||||||
const url = new URL(query);
|
const url = new URL(query);
|
||||||
let param = '';
|
let param = null;
|
||||||
if (search) {
|
if (search) {
|
||||||
let _params = url.searchParams.getAll(search);
|
let _params = url.searchParams.getAll(search);
|
||||||
if (_params.length == 1 || single === true) {
|
if (_params.length == 1 || single === true) {
|
||||||
|
|||||||
@@ -183,8 +183,9 @@ if (file_exists(BASE . CONFIGS . 'config.path.php')) {
|
|||||||
define('HOST_NAME', $HOST_NAME);
|
define('HOST_NAME', $HOST_NAME);
|
||||||
// BAIL ON MISSING MASTER SITE CONFIG
|
// BAIL ON MISSING MASTER SITE CONFIG
|
||||||
if (!isset($SITE_CONFIG[HOST_NAME]['location'])) {
|
if (!isset($SITE_CONFIG[HOST_NAME]['location'])) {
|
||||||
echo 'Missing SITE_CONFIG entry for: "' . HOST_NAME . '". Contact Administrator';
|
throw new \InvalidArgumentException(
|
||||||
exit;
|
'Missing SITE_CONFIG entry for: "' . HOST_NAME . '". Contact Administrator'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// BAIL ON MISSING DB CONFIG:
|
// BAIL ON MISSING DB CONFIG:
|
||||||
// we have either no db selction for this host but have db config entries
|
// we have either no db selction for this host but have db config entries
|
||||||
@@ -200,8 +201,9 @@ if (
|
|||||||
empty($DB_CONFIG[$SITE_CONFIG[HOST_NAME]['db_host']]))
|
empty($DB_CONFIG[$SITE_CONFIG[HOST_NAME]['db_host']]))
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
echo 'No matching DB config found for: "' . HOST_NAME . '". Contact Administrator';
|
throw new \InvalidArgumentException(
|
||||||
exit;
|
'No matching DB config found for: "' . HOST_NAME . '". Contact Administrator'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// set SSL on
|
// set SSL on
|
||||||
$is_secure = false;
|
$is_secure = false;
|
||||||
|
|||||||
@@ -1478,6 +1478,8 @@ class Login
|
|||||||
// username (login), group name
|
// username (login), group name
|
||||||
$this->acl['user_name'] = $_SESSION['LOGIN_USER_NAME'];
|
$this->acl['user_name'] = $_SESSION['LOGIN_USER_NAME'];
|
||||||
$this->acl['group_name'] = $_SESSION['LOGIN_GROUP_NAME'];
|
$this->acl['group_name'] = $_SESSION['LOGIN_GROUP_NAME'];
|
||||||
|
// DEPRECATED
|
||||||
|
$this->acl['euid'] = $_SESSION['LOGIN_EUID'];
|
||||||
// edit user cuid
|
// edit user cuid
|
||||||
$this->acl['eucuid'] = $_SESSION['LOGIN_EUCUID'];
|
$this->acl['eucuid'] = $_SESSION['LOGIN_EUCUID'];
|
||||||
$this->acl['eucuuid'] = $_SESSION['LOGIN_EUCUUID'];
|
$this->acl['eucuuid'] = $_SESSION['LOGIN_EUCUUID'];
|
||||||
@@ -1530,7 +1532,7 @@ class Login
|
|||||||
$this->acl['page'] = $_SESSION['LOGIN_PAGES_ACL_LEVEL'][$this->page_name];
|
$this->acl['page'] = $_SESSION['LOGIN_PAGES_ACL_LEVEL'][$this->page_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->acl['unit_id'] = null;
|
$this->acl['unit_cuid'] = null;
|
||||||
$this->acl['unit_name'] = null;
|
$this->acl['unit_name'] = null;
|
||||||
$this->acl['unit_uid'] = null;
|
$this->acl['unit_uid'] = null;
|
||||||
$this->acl['unit'] = [];
|
$this->acl['unit'] = [];
|
||||||
@@ -1558,6 +1560,7 @@ class Login
|
|||||||
'uid' => $unit['uid'],
|
'uid' => $unit['uid'],
|
||||||
'cuuid' => $unit['cuuid'],
|
'cuuid' => $unit['cuuid'],
|
||||||
'level' => $this->default_acl_list[$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
'level' => $this->default_acl_list[$this->acl['unit'][$ea_cuid]]['name'] ?? -1,
|
||||||
|
'level_number' => $this->acl['unit'][$ea_cuid],
|
||||||
'default' => $unit['default'],
|
'default' => $unit['default'],
|
||||||
'data' => $unit['data'],
|
'data' => $unit['data'],
|
||||||
'additional_acl' => $unit['additional_acl']
|
'additional_acl' => $unit['additional_acl']
|
||||||
@@ -2536,7 +2539,7 @@ HTML;
|
|||||||
$this->login_user_id,
|
$this->login_user_id,
|
||||||
-1,
|
-1,
|
||||||
$login_user_id_changed
|
$login_user_id_changed
|
||||||
);
|
) ?? '';
|
||||||
// flag unclean input data
|
// flag unclean input data
|
||||||
if ($login_user_id_changed > 0) {
|
if ($login_user_id_changed > 0) {
|
||||||
$this->login_user_id_unclear = true;
|
$this->login_user_id_unclear = true;
|
||||||
@@ -3215,7 +3218,7 @@ HTML;
|
|||||||
* @return int|null same edit access id if ok
|
* @return int|null same edit access id if ok
|
||||||
* or the default edit access id
|
* or the default edit access id
|
||||||
* if given one is not valid
|
* if given one is not valid
|
||||||
* @deprecated Please switch to using edit access cuid check with ->loginCheckEditAccessValidCuid()
|
* @#deprecated Please switch to using edit access cuid check with ->loginCheckEditAccessValidCuid()
|
||||||
*/
|
*/
|
||||||
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
||||||
{
|
{
|
||||||
@@ -3288,10 +3291,24 @@ HTML;
|
|||||||
*/
|
*/
|
||||||
public function loginGetEditAccessCuidFromId(int $id): string|false
|
public function loginGetEditAccessCuidFromId(int $id): string|false
|
||||||
{
|
{
|
||||||
if (!isset($_SESSION['LOGIN_UNIT_ACL_LEVEL'][$id])) {
|
if (!isset($_SESSION['LOGIN_UNIT_LEGACY'][$id])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (string)$_SESSION['LOGIN_UNIT_ACL_LEVEL'][$id]['cuid'];
|
return (string)$_SESSION['LOGIN_UNIT_LEGACY'][$id]['cuid'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a Legacy lookup from the edit access id to cuid for further lookups in the normal list
|
||||||
|
*
|
||||||
|
* @param string $cuid edit access cuid
|
||||||
|
* @return int|false false on not found or edit access id PK
|
||||||
|
*/
|
||||||
|
public function loginGetEditAccessIdFromCuid(string $cuid): int|false
|
||||||
|
{
|
||||||
|
if (!isset($_SESSION['LOGIN_UNIT'][$cuid])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $_SESSION['LOGIN_UNIT'][$cuid]['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class EditBase
|
|||||||
);
|
);
|
||||||
if ($this->form->mobile_phone) {
|
if ($this->form->mobile_phone) {
|
||||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
// $this->log->debug('POST', $this->log->prAr($_POST));
|
// $this->log->debug('POST', $this->log->prAr($_POST));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -639,16 +639,26 @@ class DateTime
|
|||||||
*
|
*
|
||||||
* @param string $start_date valid start date (y/m/d)
|
* @param string $start_date valid start date (y/m/d)
|
||||||
* @param string $end_date valid end date (y/m/d)
|
* @param string $end_date valid end date (y/m/d)
|
||||||
* @param bool $return_named return array type, false (default), true for named
|
* @param bool $return_named [default=false] return array type, false (default), true for named
|
||||||
* @return array<mixed> 0/overall, 1/weekday, 2/weekend
|
* @param bool $include_end_date [default=true] include end date in calc
|
||||||
|
* @param bool $exclude_start_date [default=false] include end date in calc
|
||||||
|
* @return array{0:int,1:int,2:int,3:bool}|array{overall:int,weekday:int,weekend:int,reverse:bool}
|
||||||
|
* 0/overall, 1/weekday, 2/weekend, 3/reverse
|
||||||
*/
|
*/
|
||||||
public static function calcDaysInterval(
|
public static function calcDaysInterval(
|
||||||
string $start_date,
|
string $start_date,
|
||||||
string $end_date,
|
string $end_date,
|
||||||
bool $return_named = false
|
bool $return_named = false,
|
||||||
|
bool $include_end_date = true,
|
||||||
|
bool $exclude_start_date = false
|
||||||
): array {
|
): array {
|
||||||
// pos 0 all, pos 1 weekday, pos 2 weekend
|
// pos 0 all, pos 1 weekday, pos 2 weekend
|
||||||
$days = [];
|
$days = [
|
||||||
|
0 => 0,
|
||||||
|
1 => 0,
|
||||||
|
2 => 0,
|
||||||
|
3 => false,
|
||||||
|
];
|
||||||
// if anything invalid, return 0,0,0
|
// if anything invalid, return 0,0,0
|
||||||
try {
|
try {
|
||||||
$start = new \DateTime($start_date);
|
$start = new \DateTime($start_date);
|
||||||
@@ -659,19 +669,30 @@ class DateTime
|
|||||||
'overall' => 0,
|
'overall' => 0,
|
||||||
'weekday' => 0,
|
'weekday' => 0,
|
||||||
'weekend' => 0,
|
'weekend' => 0,
|
||||||
|
'reverse' => false
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [0, 0, 0];
|
return $days;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// so we include the last day too, we need to add +1 second in the time
|
// so we include the last day too, we need to add +1 second in the time
|
||||||
$end->setTime(0, 0, 1);
|
// if start is before end, switch dates and flag
|
||||||
// if end date before start date, only this will be filled
|
$days[3] = false;
|
||||||
$days[0] = $end->diff($start)->days;
|
if ($start > $end) {
|
||||||
$days[1] = 0;
|
$new_start = $end;
|
||||||
$days[2] = 0;
|
$end = $start;
|
||||||
|
$start = $new_start;
|
||||||
|
$days[3] = true;
|
||||||
|
}
|
||||||
// get period for weekends/weekdays
|
// get period for weekends/weekdays
|
||||||
$period = new \DatePeriod($start, new \DateInterval('P1D'), $end);
|
$options = 0;
|
||||||
|
if ($include_end_date) {
|
||||||
|
$options |= \DatePeriod::INCLUDE_END_DATE;
|
||||||
|
}
|
||||||
|
if ($exclude_start_date) {
|
||||||
|
$options |= \DatePeriod::EXCLUDE_START_DATE;
|
||||||
|
}
|
||||||
|
$period = new \DatePeriod($start, new \DateInterval('P1D'), $end, $options);
|
||||||
foreach ($period as $dt) {
|
foreach ($period as $dt) {
|
||||||
$curr = $dt->format('D');
|
$curr = $dt->format('D');
|
||||||
if ($curr == 'Sat' || $curr == 'Sun') {
|
if ($curr == 'Sat' || $curr == 'Sun') {
|
||||||
@@ -679,12 +700,14 @@ class DateTime
|
|||||||
} else {
|
} else {
|
||||||
$days[1]++;
|
$days[1]++;
|
||||||
}
|
}
|
||||||
|
$days[0]++;
|
||||||
}
|
}
|
||||||
if ($return_named === true) {
|
if ($return_named === true) {
|
||||||
return [
|
return [
|
||||||
'overall' => $days[0],
|
'overall' => $days[0],
|
||||||
'weekday' => $days[1],
|
'weekday' => $days[1],
|
||||||
'weekend' => $days[2],
|
'weekend' => $days[2],
|
||||||
|
'reverse' => $days[3],
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return $days;
|
return $days;
|
||||||
@@ -705,6 +728,13 @@ class DateTime
|
|||||||
): bool {
|
): bool {
|
||||||
$dd_start = new \DateTime($start_date);
|
$dd_start = new \DateTime($start_date);
|
||||||
$dd_end = new \DateTime($end_date);
|
$dd_end = new \DateTime($end_date);
|
||||||
|
// flip if start is after end
|
||||||
|
if ($dd_start > $dd_end) {
|
||||||
|
$new_start = $dd_end;
|
||||||
|
$dd_end = $dd_start;
|
||||||
|
$dd_start = $new_start;
|
||||||
|
}
|
||||||
|
// if start > end, flip
|
||||||
if (
|
if (
|
||||||
// starts with a weekend
|
// starts with a weekend
|
||||||
$dd_start->format('N') >= 6 ||
|
$dd_start->format('N') >= 6 ||
|
||||||
|
|||||||
@@ -500,7 +500,7 @@ class IO
|
|||||||
die('<!-- Cannot load db functions class for: ' . $this->db_type . ' -->');
|
die('<!-- Cannot load db functions class for: ' . $this->db_type . ' -->');
|
||||||
}
|
}
|
||||||
// write to internal one, once OK
|
// write to internal one, once OK
|
||||||
$this->db_functions = $db_functions;
|
$this->db_functions = $db_functions; /** @phan-suppress-current-line PhanPossiblyNullTypeMismatchProperty */
|
||||||
|
|
||||||
// connect to DB
|
// connect to DB
|
||||||
if (!$this->__connectToDB()) {
|
if (!$this->__connectToDB()) {
|
||||||
@@ -1413,10 +1413,7 @@ class IO
|
|||||||
$this->pk_name_table[$table] ?
|
$this->pk_name_table[$table] ?
|
||||||
$this->pk_name_table[$table] : 'NULL';
|
$this->pk_name_table[$table] : 'NULL';
|
||||||
}
|
}
|
||||||
if (
|
if (!preg_match(self::REGEX_RETURNING, $this->query) && $this->pk_name != 'NULL') {
|
||||||
!preg_match(self::REGEX_RETURNING, $this->query) &&
|
|
||||||
$this->pk_name && $this->pk_name != 'NULL'
|
|
||||||
) {
|
|
||||||
// check if this query has a ; at the end and remove it
|
// check if this query has a ; at the end and remove it
|
||||||
$__query = preg_replace("/(;\s*)$/", '', $this->query);
|
$__query = preg_replace("/(;\s*)$/", '', $this->query);
|
||||||
// must be query, if preg replace failed, use query as before
|
// must be query, if preg replace failed, use query as before
|
||||||
@@ -1426,7 +1423,7 @@ class IO
|
|||||||
} elseif (
|
} elseif (
|
||||||
preg_match(self::REGEX_RETURNING, $this->query, $matches)
|
preg_match(self::REGEX_RETURNING, $this->query, $matches)
|
||||||
) {
|
) {
|
||||||
if ($this->pk_name && $this->pk_name != 'NULL') {
|
if ($this->pk_name != 'NULL') {
|
||||||
// add the primary key if it is not in the returning set
|
// add the primary key if it is not in the returning set
|
||||||
if (!preg_match("/$this->pk_name/", $matches[1])) {
|
if (!preg_match("/$this->pk_name/", $matches[1])) {
|
||||||
$this->query .= " , " . $this->pk_name;
|
$this->query .= " , " . $this->pk_name;
|
||||||
@@ -2946,7 +2943,7 @@ class IO
|
|||||||
$query_hash = $this->dbGetQueryHash($query, $params);
|
$query_hash = $this->dbGetQueryHash($query, $params);
|
||||||
// clears cache for this query
|
// clears cache for this query
|
||||||
if (empty($this->cursor_ext[$query_hash]['query'])) {
|
if (empty($this->cursor_ext[$query_hash]['query'])) {
|
||||||
$this->__dbError(18, context: [
|
$this->__dbWarning(18, context: [
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
'params' => $params,
|
'params' => $params,
|
||||||
'hash' => $query_hash,
|
'hash' => $query_hash,
|
||||||
@@ -3141,6 +3138,7 @@ class IO
|
|||||||
'pk_name' => '',
|
'pk_name' => '',
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
'query' => '',
|
'query' => '',
|
||||||
|
'query_raw' => $query,
|
||||||
'result' => null,
|
'result' => null,
|
||||||
'returning_id' => false,
|
'returning_id' => false,
|
||||||
'placeholder_converted' => [],
|
'placeholder_converted' => [],
|
||||||
@@ -3237,11 +3235,12 @@ class IO
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we try to use the same statement name for a differnt query, error abort
|
// if we try to use the same statement name for a differnt query, error abort
|
||||||
if ($this->prepare_cursor[$stm_name]['query'] != $query) {
|
if ($this->prepare_cursor[$stm_name]['query_raw'] != $query) {
|
||||||
// thrown error
|
// thrown error
|
||||||
$this->__dbError(26, false, context: [
|
$this->__dbError(26, false, context: [
|
||||||
'statement_name' => $stm_name,
|
'statement_name' => $stm_name,
|
||||||
'prepared_query' => $this->prepare_cursor[$stm_name]['query'],
|
'prepared_query' => $this->prepare_cursor[$stm_name]['query'],
|
||||||
|
'prepared_query_raw' => $this->prepare_cursor[$stm_name]['query_raw'],
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
'pk_name' => $pk_name,
|
'pk_name' => $pk_name,
|
||||||
]);
|
]);
|
||||||
@@ -4364,6 +4363,37 @@ class IO
|
|||||||
return $this->prepare_cursor[$stm_name][$key];
|
return $this->prepare_cursor[$stm_name][$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a prepared query eixsts
|
||||||
|
*
|
||||||
|
* @param string $stm_name Statement to check
|
||||||
|
* @param string $query [default=''] If set then query must also match
|
||||||
|
* @return false|int<0,2> False on missing stm_name
|
||||||
|
* 0: ok, 1: stm_name matchin, 2: stm_name and query matching
|
||||||
|
*/
|
||||||
|
public function dbPreparedCursorStatus(string $stm_name, string $query = ''): false|int
|
||||||
|
{
|
||||||
|
if (empty($stm_name)) {
|
||||||
|
$this->__dbError(
|
||||||
|
101,
|
||||||
|
false,
|
||||||
|
'No statement name given'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// does not exist
|
||||||
|
$return_value = 0;
|
||||||
|
if (!empty($this->prepare_cursor[$stm_name]['query_raw'])) {
|
||||||
|
// statement name eixts
|
||||||
|
$return_value = 1;
|
||||||
|
if ($this->prepare_cursor[$stm_name]['query_raw'] == $query) {
|
||||||
|
// query also matches
|
||||||
|
$return_value = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return_value;
|
||||||
|
}
|
||||||
|
|
||||||
// ***************************
|
// ***************************
|
||||||
// ERROR AND WARNING DATA
|
// ERROR AND WARNING DATA
|
||||||
// ***************************
|
// ***************************
|
||||||
|
|||||||
95
www/lib/CoreLibs/DeprecatedHelper/Deprecated84.php
Normal file
95
www/lib/CoreLibs/DeprecatedHelper/Deprecated84.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AUTHOR: Clemens Schwaighofer
|
||||||
|
* CREATED: 2025/1/17
|
||||||
|
* DESCRIPTION:
|
||||||
|
* Deprecated helper for fputcsv
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\DeprecatedHelper;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
|
class Deprecated84
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* This is a wrapper for fputcsv to fix deprecated warning for $escape parameter
|
||||||
|
* See: https://www.php.net/manual/en/function.fputcsv.php
|
||||||
|
* escape parameter deprecation and recommend to set to "" for compatible with PHP 9.0
|
||||||
|
*
|
||||||
|
* @param mixed $stream
|
||||||
|
* @param array<mixed> $fields
|
||||||
|
* @param string $separator
|
||||||
|
* @param string $enclosure
|
||||||
|
* @param string $escape
|
||||||
|
* @param string $eol
|
||||||
|
* @return int|false
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public static function fputcsv(
|
||||||
|
mixed $stream,
|
||||||
|
array $fields,
|
||||||
|
string $separator = ",",
|
||||||
|
string $enclosure = '"',
|
||||||
|
string $escape = '', // set to empty for future compatible
|
||||||
|
string $eol = PHP_EOL
|
||||||
|
): int | false {
|
||||||
|
if (!is_resource($stream)) {
|
||||||
|
throw new \InvalidArgumentException("fputcsv stream parameter must be a resrouce");
|
||||||
|
}
|
||||||
|
return fputcsv($stream, $fields, $separator, $enclosure, $escape, $eol);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a wrapper for fgetcsv to fix deprecated warning for $escape parameter
|
||||||
|
* See: https://www.php.net/manual/en/function.fgetcsv.php
|
||||||
|
* escape parameter deprecation and recommend to set to "" for compatible with PHP 9.0
|
||||||
|
*
|
||||||
|
* @param mixed $stream
|
||||||
|
* @param null|int<0,max> $length
|
||||||
|
* @param string $separator
|
||||||
|
* @param string $enclosure
|
||||||
|
* @param string $escape
|
||||||
|
* @return array<mixed>|false
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
*/
|
||||||
|
public static function fgetcsv(
|
||||||
|
mixed $stream,
|
||||||
|
?int $length = null,
|
||||||
|
string $separator = ',',
|
||||||
|
string $enclosure = '"',
|
||||||
|
string $escape = '' // set to empty for future compatible
|
||||||
|
): array | false {
|
||||||
|
if (!is_resource($stream)) {
|
||||||
|
throw new \InvalidArgumentException("fgetcsv stream parameter must be a resrouce");
|
||||||
|
}
|
||||||
|
return fgetcsv($stream, $length, $separator, $enclosure, $escape);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a wrapper for str_getcsv to fix deprecated warning for $escape parameter
|
||||||
|
* See: https://www.php.net/manual/en/function.str-getcsv.php
|
||||||
|
* escape parameter deprecation and recommend to set to "" for compatible with PHP 9.0
|
||||||
|
*
|
||||||
|
* @param string $string
|
||||||
|
* @param string $separator
|
||||||
|
* @param string $enclosure
|
||||||
|
* @param string $escape
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
// phpcs:disable PSR1.Methods.CamelCapsMethodName
|
||||||
|
public static function str_getcsv(
|
||||||
|
string $string,
|
||||||
|
string $separator = ",",
|
||||||
|
string $enclosure = '"',
|
||||||
|
string $escape = '' // set to empty for future compatible
|
||||||
|
): array {
|
||||||
|
return str_getcsv($string, $separator, $enclosure, $escape);
|
||||||
|
}
|
||||||
|
// phpcs:enable PSR1.Methods.CamelCapsMethodName
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -30,6 +30,10 @@ class Logging
|
|||||||
{
|
{
|
||||||
/** @var int minimum size for a max file size, so we don't set 1 byte, 10kb */
|
/** @var int minimum size for a max file size, so we don't set 1 byte, 10kb */
|
||||||
public const MIN_LOG_MAX_FILESIZE = 10 * 1024;
|
public const MIN_LOG_MAX_FILESIZE = 10 * 1024;
|
||||||
|
/** @var string log file extension, not changeable */
|
||||||
|
private const LOG_FILE_NAME_EXT = "log";
|
||||||
|
/** @var string log file block separator, not changeable */
|
||||||
|
private const LOG_FILE_BLOCK_SEPARATOR = '.';
|
||||||
|
|
||||||
// NOTE: the second party array{} hs some errors
|
// NOTE: the second party array{} hs some errors
|
||||||
/** @var array<string,array<string,string|bool|Level>>|array{string:array{type:string,type_info?:string,mandatory:true,alias?:string,default:string|bool|Level,deprecated:bool,use?:string}} */
|
/** @var array<string,array<string,string|bool|Level>>|array{string:array{type:string,type_info?:string,mandatory:true,alias?:string,default:string|bool|Level,deprecated:bool,use?:string}} */
|
||||||
@@ -104,8 +108,6 @@ class Logging
|
|||||||
private string $log_folder = '';
|
private string $log_folder = '';
|
||||||
/** @var string a alphanumeric name that has to be set as global definition */
|
/** @var string a alphanumeric name that has to be set as global definition */
|
||||||
private string $log_file_id = '';
|
private string $log_file_id = '';
|
||||||
/** @var string log file name extension */
|
|
||||||
private string $log_file_name_ext = 'log';
|
|
||||||
/** @var string log file name with folder, for actual writing */
|
/** @var string log file name with folder, for actual writing */
|
||||||
private string $log_file_name = '';
|
private string $log_file_name = '';
|
||||||
/** @var int set in bytes */
|
/** @var int set in bytes */
|
||||||
@@ -431,7 +433,7 @@ class Logging
|
|||||||
private function buildLogFileName(Level $level, string $group_id = ''): string
|
private function buildLogFileName(Level $level, string $group_id = ''): string
|
||||||
{
|
{
|
||||||
// init base file path
|
// init base file path
|
||||||
$fn = $this->log_print_file . '.' . $this->log_file_name_ext;
|
$fn = $this->log_print_file . '.' . self::LOG_FILE_NAME_EXT;
|
||||||
// log ID prefix settings, if not valid, replace with empty
|
// log ID prefix settings, if not valid, replace with empty
|
||||||
if (!empty($this->log_file_id)) {
|
if (!empty($this->log_file_id)) {
|
||||||
$rpl_string = $this->log_file_id;
|
$rpl_string = $this->log_file_id;
|
||||||
@@ -440,14 +442,15 @@ class Logging
|
|||||||
}
|
}
|
||||||
$fn = str_replace('{LOGID}', $rpl_string, $fn); // log id (like a log file prefix)
|
$fn = str_replace('{LOGID}', $rpl_string, $fn); // log id (like a log file prefix)
|
||||||
|
|
||||||
$rpl_string = !$this->getLogFlag(Flag::per_level) ? '' :
|
$rpl_string = $this->getLogFlag(Flag::per_level) ?
|
||||||
'_' . $level->getName();
|
self::LOG_FILE_BLOCK_SEPARATOR . $level->getName() :
|
||||||
|
'';
|
||||||
$fn = str_replace('{LEVEL}', $rpl_string, $fn); // create output filename
|
$fn = str_replace('{LEVEL}', $rpl_string, $fn); // create output filename
|
||||||
|
|
||||||
// write per level
|
// write per level
|
||||||
$rpl_string = !$this->getLogFlag(Flag::per_group) ? '' :
|
$rpl_string = $this->getLogFlag(Flag::per_group) ?
|
||||||
// normalize level, replace all non alphanumeric characters with -
|
// normalize level, replace all non alphanumeric characters with -
|
||||||
'_' . (
|
self::LOG_FILE_BLOCK_SEPARATOR . (
|
||||||
// if return is only - then set error string
|
// if return is only - then set error string
|
||||||
preg_match(
|
preg_match(
|
||||||
"/^-+$/",
|
"/^-+$/",
|
||||||
@@ -455,25 +458,29 @@ class Logging
|
|||||||
) ?
|
) ?
|
||||||
'INVALID-LEVEL-STRING' :
|
'INVALID-LEVEL-STRING' :
|
||||||
$level_string
|
$level_string
|
||||||
);
|
) :
|
||||||
|
'';
|
||||||
$fn = str_replace('{GROUP}', $rpl_string, $fn); // create output filename
|
$fn = str_replace('{GROUP}', $rpl_string, $fn); // create output filename
|
||||||
// set per class, but don't use get_class as we will only get self
|
// set per class, but don't use get_class as we will only get self
|
||||||
$rpl_string = !$this->getLogFlag(Flag::per_class) ? '' : '_'
|
$rpl_string = $this->getLogFlag(Flag::per_class) ?
|
||||||
// set sub class settings
|
// set sub class settings
|
||||||
. str_replace('\\', '-', Support::getCallerTopLevelClass());
|
self::LOG_FILE_BLOCK_SEPARATOR . str_replace('\\', '-', Support::getCallerTopLevelClass()) :
|
||||||
|
'';
|
||||||
$fn = str_replace('{CLASS}', $rpl_string, $fn); // create output filename
|
$fn = str_replace('{CLASS}', $rpl_string, $fn); // create output filename
|
||||||
|
|
||||||
// if request to write to one file
|
// if request to write to one file
|
||||||
$rpl_string = !$this->getLogFlag(Flag::per_page) ?
|
$rpl_string = $this->getLogFlag(Flag::per_page) ?
|
||||||
'' :
|
self::LOG_FILE_BLOCK_SEPARATOR . System::getPageName(System::NO_EXTENSION) :
|
||||||
'_' . System::getPageName(System::NO_EXTENSION);
|
'';
|
||||||
$fn = str_replace('{PAGENAME}', $rpl_string, $fn); // create output filename
|
$fn = str_replace('{PAGENAME}', $rpl_string, $fn); // create output filename
|
||||||
|
|
||||||
// if run id, we auto add ymd, so we ignore the log file date
|
// if run id, we auto add ymd, so we ignore the log file date
|
||||||
if ($this->getLogFlag(Flag::per_run)) {
|
if ($this->getLogFlag(Flag::per_run)) {
|
||||||
$rpl_string = '_' . $this->getLogUniqueId(); // add 8 char unique string
|
// add 8 char unique string and date block with time
|
||||||
|
$rpl_string = self::LOG_FILE_BLOCK_SEPARATOR . $this->getLogUniqueId();
|
||||||
} elseif ($this->getLogFlag(Flag::per_date)) {
|
} elseif ($this->getLogFlag(Flag::per_date)) {
|
||||||
$rpl_string = '_' . $this->getLogDate(); // add date to file
|
// add date to file
|
||||||
|
$rpl_string = self::LOG_FILE_BLOCK_SEPARATOR . $this->getLogDate();
|
||||||
} else {
|
} else {
|
||||||
$rpl_string = '';
|
$rpl_string = '';
|
||||||
}
|
}
|
||||||
@@ -739,7 +746,10 @@ class Logging
|
|||||||
{
|
{
|
||||||
if (empty($this->log_file_unique_id) || $override == true) {
|
if (empty($this->log_file_unique_id) || $override == true) {
|
||||||
$this->log_file_unique_id =
|
$this->log_file_unique_id =
|
||||||
date('Y-m-d_His') . '_U_'
|
date('Y-m-d_His')
|
||||||
|
. self::LOG_FILE_BLOCK_SEPARATOR
|
||||||
|
. 'U_'
|
||||||
|
// this doesn't have to be unique for everything, just for this logging purpose
|
||||||
. substr(hash(
|
. substr(hash(
|
||||||
'sha1',
|
'sha1',
|
||||||
random_bytes(63)
|
random_bytes(63)
|
||||||
|
|||||||
Reference in New Issue
Block a user