diff --git a/www/admin/class_test.error_msg.php b/www/admin/class_test.error_msg.php index 1d1ba0ac..e2aa5901 100644 --- a/www/admin/class_test.error_msg.php +++ b/www/admin/class_test.error_msg.php @@ -35,19 +35,32 @@ print '

' . $PAGE_NAME . '

'; $em = new \CoreLibs\Logging\ErrorMessage($log); +print "Log ERROR: " . $log->prAr($em->getFlagLogError()) . "
"; + print "FN: " . ml::fromName('Affe')->name . "
"; print "NU: " . ml::fromValue(100)->name . "
"; print "NU: " . ml::fromValue(1000)->name . "
"; -$em->setErrorMsg('123', 'error', 'msg this is bad, not logged'); -$em->setErrorMsg('123', 'error', 'msg this is bad, logged', log_error:true); +$em->setErrorMsg('123', 'error', 'msg this is bad, auto logged if debug'); +$em->setErrorMsg('123', 'error', 'msg this is bad, auto logged if debug', 'target-id', 'other-style'); +$em->setErrorMsg('123', 'error', 'msg this is bad, logged always', log_error:true); +$em->setErrorMsg('123', 'error', 'msg this is bad, never logged', log_error:false); $em->setErrorMsg('1000', 'info', 'This is good'); $em->setErrorMsg('9999', 'abort', 'BAD: This is critical (abort)'); $em->setErrorMsg('10-1000', 'wrong', 'Wrong level: This is emergency'); +// set some jump targets too +$em->setErrorMsg('100-1', 'error', 'Input wring', jump_target:['target' => 'foo-123', 'info' => 'Jump Target 123']); +$em->setErrorMsg('100-2', 'error', 'Input wring', jump_target:['target' => 'foo-123', 'info' => 'Jump Target 456']); +$em->setMessage('error', 'I have no id set', jump_target:['target' => 'bar-123', 'info' => 'Jump Bar']); +$em->setMessage('error', 'Jump empty', jump_target:['target' => 'bar-empty']); + print "ErrorsLast:
" . $log->prAr($em->getLastErrorMsg()) . "
"; print "ErrorsIds:
" . $log->prAr($em->getErrorIds()) . "
"; print "Errors:
" . $log->prAr($em->getErrorMsg()) . "
"; +print "JumpTargets:
" . $log->prAr($em->getJumpTarget()) . "
"; print ""; +$log->debug('[END]', '==========================================>'); + // __END__ diff --git a/www/admin/class_test.image.php b/www/admin/class_test.image.php index d2be61c6..0ae756ba 100644 --- a/www/admin/class_test.image.php +++ b/www/admin/class_test.image.php @@ -46,7 +46,13 @@ $image = BASE . LAYOUT . CONTENT_PATH . IMAGES . 'no_picture_square.jpg'; $cache_folder = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES; $web_folder = LAYOUT . CACHE . IMAGES; // rotate image first -$_image->correctImageOrientation($image); +try { + $_image->correctImageOrientation($image); +} catch (\UnexpectedValueException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; +} catch (\RuntimeException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; +} // thumbnail tests echo "
CLASS->CREATETHUMBNAILSIMPLE: " . basename($image) . ": WIDTH: $thumb_width
CLASS->CREATETHUMBNAILSIMPLE: " // static $image = BASE . LAYOUT . CONTENT_PATH . IMAGES . 'no_picture.jpg'; // rotate image first -$image_class::correctImageOrientation($image); +try { + $image_class::correctImageOrientation($image); +} catch (\UnexpectedValueException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; +} catch (\RuntimeException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; +} // thumbnail tests echo "
S::CREATETHUMBNAILSIMPLE: " . basename($image) . ": WIDTH: $thumb_width
IMAGE INFO: " . $height . "x" . $width . ", TYPE: " . \CoreLibs\Debug\Support::dumpVar($img_type) . " [" . $finfo->file($image) . "]
"; // rotate image first - Image::correctImageOrientation($image); + try { + Image::correctImageOrientation($image); + } catch (\UnexpectedValueException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; + } catch (\RuntimeException $e) { + print "Message:
" . $e->getMessage() . "
" . $e . "
"; + } // thumbnail tests echo "
" . basename($image) . ": WIDTH: $thumb_width
"; diff --git a/www/composer.lock b/www/composer.lock index 79828e84..0798480e 100644 --- a/www/composer.lock +++ b/www/composer.lock @@ -12,7 +12,7 @@ "dist": { "type": "path", "url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All", - "reference": "67fd7b172aabff319e5612a78946de4124573bdd" + "reference": "4ab382990ecb9db90386f8ec1a4d87ac8f7c5dd7" }, "require": { "php": ">=8.2", @@ -20,11 +20,7 @@ }, "require-dev": { "egrajp/smarty-extended": "^4.3", - "gullevek/dotenv": "dev-master", - "phan/phan": "v5.x-dev", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9", - "vimeo/psalm": "^5.0@dev" + "gullevek/dotenv": "dev-master" }, "type": "library", "autoload": { diff --git a/www/vendor/composer/installed.json b/www/vendor/composer/installed.json index e57e1fa6..c12e083e 100644 --- a/www/vendor/composer/installed.json +++ b/www/vendor/composer/installed.json @@ -7,7 +7,7 @@ "dist": { "type": "path", "url": "/storage/var/www/html/developers/clemens/core_data/composer-packages/CoreLibs-Composer-All", - "reference": "67fd7b172aabff319e5612a78946de4124573bdd" + "reference": "4ab382990ecb9db90386f8ec1a4d87ac8f7c5dd7" }, "require": { "php": ">=8.2", @@ -15,11 +15,7 @@ }, "require-dev": { "egrajp/smarty-extended": "^4.3", - "gullevek/dotenv": "dev-master", - "phan/phan": "v5.x-dev", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9", - "vimeo/psalm": "^5.0@dev" + "gullevek/dotenv": "dev-master" }, "type": "library", "installation-source": "dist", diff --git a/www/vendor/composer/installed.php b/www/vendor/composer/installed.php index 6e3f12a0..acd2e994 100644 --- a/www/vendor/composer/installed.php +++ b/www/vendor/composer/installed.php @@ -13,7 +13,7 @@ 'egrajp/corelibs-composer-all' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '67fd7b172aabff319e5612a78946de4124573bdd', + 'reference' => '4ab382990ecb9db90386f8ec1a4d87ac8f7c5dd7', 'type' => 'library', 'install_path' => __DIR__ . '/../egrajp/corelibs-composer-all', 'aliases' => array(), diff --git a/www/vendor/egrajp/corelibs-composer-all/.phan/config.php b/www/vendor/egrajp/corelibs-composer-all/.phan/config.php index dace5350..84e03646 100644 --- a/www/vendor/egrajp/corelibs-composer-all/.phan/config.php +++ b/www/vendor/egrajp/corelibs-composer-all/.phan/config.php @@ -360,10 +360,7 @@ return [ 'directory_list' => [ 'src', 'vendor/egrajp/smarty-extended/src', - 'vendor/phan/phan/src/Phan', - 'vendor/phpunit/phpunit/src', 'vendor/psr/log/src', - 'vendor/vimeo/psalm/src/Psalm', 'vendor/gullevek/dotenv', ], diff --git a/www/vendor/egrajp/corelibs-composer-all/.phive/phars.xml b/www/vendor/egrajp/corelibs-composer-all/.phive/phars.xml new file mode 100644 index 00000000..f6d3d32b --- /dev/null +++ b/www/vendor/egrajp/corelibs-composer-all/.phive/phars.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/www/vendor/egrajp/corelibs-composer-all/ReadMe.md b/www/vendor/egrajp/corelibs-composer-all/ReadMe.md index 2c609314..355aea36 100644 --- a/www/vendor/egrajp/corelibs-composer-all/ReadMe.md +++ b/www/vendor/egrajp/corelibs-composer-all/ReadMe.md @@ -23,3 +23,21 @@ Alternative setup composer local zip file repot: ## Install package `composer require egrajp/corelibs-composer-all:^8.0` + +## Tests + +All tests must be run from the base folder + +### phan + +`phan --progress-bar -C --analyze-twic` + +### phpstan + +`phpstan` + +### phpunit + +PHP unit is installed via "phiev" + +`tools/phpunit test/phpunit` diff --git a/www/vendor/egrajp/corelibs-composer-all/composer.json b/www/vendor/egrajp/corelibs-composer-all/composer.json index e34000c0..6867202d 100644 --- a/www/vendor/egrajp/corelibs-composer-all/composer.json +++ b/www/vendor/egrajp/corelibs-composer-all/composer.json @@ -20,11 +20,7 @@ "psr/log": "^3.0@dev" }, "require-dev": { - "phpstan/phpstan": "^1.10", - "phan/phan": "v5.x-dev", - "phpunit/phpunit": "^9", "egrajp/smarty-extended": "^4.3", - "vimeo/psalm": "^5.0@dev", "gullevek/dotenv": "dev-master" }, "repositories": { diff --git a/www/vendor/egrajp/corelibs-composer-all/phpunit.xml b/www/vendor/egrajp/corelibs-composer-all/phpunit.xml index 23d3de4c..3edd6bbb 100644 --- a/www/vendor/egrajp/corelibs-composer-all/phpunit.xml +++ b/www/vendor/egrajp/corelibs-composer-all/phpunit.xml @@ -2,5 +2,6 @@ cacheResultFile="/tmp/phpunit-corelibs-composer.result.cache" colors="true" verbose="true" + bootstrap="test/phpunit/bootstrap.php" > diff --git a/www/vendor/egrajp/corelibs-composer-all/publish/last.published b/www/vendor/egrajp/corelibs-composer-all/publish/last.published index 23ca8cda..5d24a8f4 100644 --- a/www/vendor/egrajp/corelibs-composer-all/publish/last.published +++ b/www/vendor/egrajp/corelibs-composer-all/publish/last.published @@ -1 +1 @@ -9.7.3 +9.8.2 diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php b/www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php index 05538daf..fa8033ef 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php @@ -35,6 +35,8 @@ class EditBase private \CoreLibs\Output\Form\Generate $form; /** @var \CoreLibs\Logging\Logging */ public \CoreLibs\Logging\Logging $log; + /** @var \CoreLibs\Language\L10n */ + public \CoreLibs\Language\L10n $l; /** @var \CoreLibs\ACL\Login */ public \CoreLibs\ACL\Login $login; @@ -57,6 +59,7 @@ class EditBase ) { $this->log = $log; $this->login = $login; + $this->l = $l10n; // smarty template engine (extended Translation version) $this->smarty = new \CoreLibs\Template\SmartyExtend( $l10n, @@ -77,7 +80,7 @@ class EditBase echo "I am sorry, but this page cannot be viewed by a mobile phone"; exit; } - // $this->form->log->debug('POST', $this->form->log->prAr($_POST)); + // $this->log->debug('POST', $this->log->prAr($_POST)); } /** @@ -151,7 +154,7 @@ class EditBase $q = "UPDATE " . $table_name . " SET order_number = " . $row_data_order[$i] . " WHERE " . $table_name . "_id = " . $row_data_id[$i]; - $q = $this->form->dbExec($q); + $q = $this->form->dba->dbExec($q); } } // for all article ids ... } // if write @@ -170,7 +173,7 @@ class EditBase $options_name = []; $options_selected = []; // DB read data for menu - while (is_array($res = $this->form->dbReturn($q))) { + while (is_array($res = $this->form->dba->dbReturn($q))) { $row_data[] = [ "id" => $res[$table_name . "_id"], "name" => $res["name"], @@ -179,7 +182,7 @@ class EditBase } // while read data ... // html title - $this->HEADER['HTML_TITLE'] = $this->form->l->__('Edit Order'); + $this->HEADER['HTML_TITLE'] = $this->l->__('Edit Order'); $messages = []; $error = $_POST['error'] ?? 0; @@ -428,9 +431,9 @@ class EditBase $elements[] = $this->form->formCreateElement('template'); break; case 'edit_pages': - if (!isset($this->form->table_array['edit_page_id']['value'])) { + if (!isset($this->form->dba->getTableArray()['edit_page_id']['value'])) { $q = "DELETE FROM temp_files"; - $this->form->dbExec($q); + $this->form->dba->dbExec($q); // gets all files in the current dir and dirs given ending with .php $folders = ['../admin/', '../frontend/']; $files = ['*.php']; @@ -458,16 +461,16 @@ class EditBase if ($t_q) { $t_q .= ', '; } - $t_q .= "('" . $this->form->dbEscapeString($pathinfo['dirname']) . "', '" - . $this->form->dbEscapeString($pathinfo['basename']) . "')"; + $t_q .= "('" . $this->form->dba->dbEscapeString($pathinfo['dirname']) . "', '" + . $this->form->dba->dbEscapeString($pathinfo['basename']) . "')"; } - $this->form->dbExec($q . $t_q, 'NULL'); + $this->form->dba->dbExec($q . $t_q, 'NULL'); $elements[] = $this->form->formCreateElement('filename'); } else { // show file menu // just show name of file ... $this->DATA['filename_exist'] = 1; - $this->DATA['filename'] = $this->form->table_array['filename']['value']; + $this->DATA['filename'] = $this->form->dba->getTableArray()['filename']['value']; } // File Name View IF $elements[] = $this->form->formCreateElement('hostname'); $elements[] = $this->form->formCreateElement('name'); @@ -632,7 +635,7 @@ class EditBase 'editAdmin_' . $this->smarty->lang ); - $this->form->log->debug('DEBUGEND', '==================================== [Form END]'); + $this->log->debug('DEBUGEND', '==================================== [Form END]'); } } diff --git a/www/vendor/egrajp/corelibs-composer-all/src/DB/Extended/ArrayIO.php b/www/vendor/egrajp/corelibs-composer-all/src/DB/Extended/ArrayIO.php index 7c2ed514..b0e6f659 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/DB/Extended/ArrayIO.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/DB/Extended/ArrayIO.php @@ -39,13 +39,13 @@ class ArrayIO extends \CoreLibs\DB\IO { // main calss variables /** @var array */ - public array $table_array; // the array from the table to work on + private array $table_array; // the array from the table to work on /** @var string */ - public string $table_name; // the table_name + private string $table_name; // the table_name /** @var string */ - public string $pk_name = ''; // the primary key from this table + private string $pk_name = ''; // the primary key from this table /** @var int|string|null */ - public int|string|null $pk_id; // the PK id + private int|string|null $pk_id; // the PK id // security values /** @var int base acl for current page */ private int $base_acl_level = 0; @@ -74,24 +74,21 @@ class ArrayIO extends \CoreLibs\DB\IO // instance db_io class parent::__construct($db_config, $log); // more error vars for this class - $this->error_string['1999'] = 'No table array or table name set'; + $this->error_string['1998'] = 'No table name set'; + $this->error_string['1999'] = 'No table array set'; $this->error_string['1021'] = 'No Primary Key given'; $this->error_string['1022'] = 'Could not run Array Query'; - $this->table_array = $table_array; - $this->table_name = $table_name; - - // error abort if no table array or no table name - if (empty($table_array) || empty($table_name)) { - $this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing'); - throw new \RuntimeException('MAJOR ERROR: Core settings missing', 1999); - } + $this->setTableArray($table_array); + $this->setTableName($table_name); // set primary key for given table_array foreach ($this->table_array as $key => $value) { - if (!empty($value['pk'])) { - $this->pk_name = $key; + if (empty($value['pk'])) { + continue; } + $this->setPkName($key); + break; } $this->dbArrayIOSetAcl($base_acl_level, $acl_admin); } @@ -104,6 +101,144 @@ class ArrayIO extends \CoreLibs\DB\IO parent::__destruct(); } + /** + * Set the overall table array + * + * @param array $table_array + * @return void + * @throws \RuntimeException 1999 for empty table array + */ + public function setTableArray(array $table_array): void + { + $this->table_array = $table_array; + if (empty($this->table_array)) { + $this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing: table_arrry'); + throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_array', 1999); + } + } + + /** + * return full table array, or [] if empty + * of reset is set to true, will reset array first + * + * @param bool $reset [=false] run a reset before returning + * @return array + */ + public function getTableArray(bool $reset = false): array + { + if (!$reset) { + return $this->table_array ?? []; + } + $table_array = $this->table_array ?? []; + reset($table_array); + return $table_array; + } + + /** + * get a table array entry under the key with element pos + * + * @param string $key + * @param string $pos + * @return mixed + */ + public function getTableArrayEntry(string $key, string $pos): mixed + { + return $this->table_array[$key][$pos] ?? null; + } + + /** + * set a new value at key with pos + * + * @param mixed $value + * @param string $key + * @param string $pos + * @return void + */ + public function setTableArrayEntry(mixed $value, string $key, string $pos): void + { + $this->table_array[$key][$pos] = $value; + } + + /** + * unset entry at key with pos + * + * @param string $key + * @param string $pos + * @return void + */ + public function unsetTableArrayEntry(string $key, string $pos): void + { + unset($this->table_array[$key][$pos]); + } + + /** + * Set table name + * + * @param string $table_name + * @return void + * @throws \RuntimeException 1998 for empty table name + */ + public function setTableName(string $table_name): void + { + $this->table_name = $table_name; + if (empty($this->table_name)) { + $this->__dbError(1998, false, 'MAJOR ERROR: Core settings missing: table_name'); + throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_name', 1998); + } + } + + /** + * Return table name or empty string if not net + * + * @return string + */ + public function getTableName(): string + { + return $this->table_name ?? ''; + } + + /** + * Set primary key name + * + * @param string $pk_name + * @return void + */ + public function setPkName(string $pk_name): void + { + $this->pk_name = $pk_name; + } + + /** + * get primary key name + * + * @return string + */ + public function getPkName(): string + { + return $this->pk_name; + } + + /** + * set primary key id, can be null for not yet set + * + * @param int|string|null $pk_id + * @return void + */ + public function setPkId(int|string|null $pk_id): void + { + $this->pk_id = $pk_id; + } + + /** + * return primary key id, or null if not set + * + * @return int|string|null + */ + public function getPkId(): int|string|null + { + return $this->pk_id; + } + /** * set the base acl level and admin acl flag * This is needed for table array ACL checks @@ -198,8 +333,8 @@ class ArrayIO extends \CoreLibs\DB\IO public function dbCheckPkSet(): bool { // if pk_id is set, overrule ... - if ($this->pk_id) { - $this->table_array[$this->pk_name]['value'] = $this->pk_id; + if (!empty($this->getPkId())) { + $this->table_array[$this->pk_name]['value'] = $this->getPkId(); } // if not set ... produce error if (!$this->table_array[$this->pk_name]['value']) { @@ -287,7 +422,7 @@ class ArrayIO extends \CoreLibs\DB\IO $q .= ' AND ' . $q_where; } // if 0, error - $this->pk_id = null; + $this->setPkId(null); if (!$this->dbExec($q)) { $this->__dbError(1022); } @@ -374,7 +509,7 @@ class ArrayIO extends \CoreLibs\DB\IO } } // possible dbFetchArray errors ... - $this->pk_id = $this->table_array[$this->pk_name]['value']; + $this->setPkId($this->table_array[$this->pk_name]['value']); } else { $this->__dbError(1022); } @@ -397,10 +532,6 @@ class ArrayIO extends \CoreLibs\DB\IO if (count($table_array)) { $this->table_array = $table_array; } - // PK ID check - // if ($this->pk_id && !$this->table_array[$this->pk_name]["value"]) { - // $this->table_array[$this->pk_name]["value"]=$this->pk_id; - // } // checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR! if (!$this->table_array[$this->pk_name]['value']) { $insert = 1; @@ -624,16 +755,11 @@ class ArrayIO extends \CoreLibs\DB\IO $q .= ' AND ' . $q_where; } // set pk_id ... if it has changed or so - $this->pk_id = $this->table_array[$this->pk_name]['value']; + $this->setPkId($this->table_array[$this->pk_name]['value']); } else { $q = 'INSERT INTO ' . $this->table_name . ' '; $q .= '(' . $q_vars . ') '; $q .= 'VALUES (' . $q_data . ')'; - // write primary key too - // if ($q_data) - // $q .= ", "; - // $q .= $this->pk_name." = ".$this->table_array[$this->pk_name]['value']." "; - // $this->pk_id = $this->table_array[$this->pk_name]['value']; } // return success or not if (!$this->dbExec($q)) { @@ -646,7 +772,7 @@ class ArrayIO extends \CoreLibs\DB\IO $insert_id = 0; } $this->table_array[$this->pk_name]['value'] = $insert_id; - $this->pk_id = $insert_id; + $this->setPkId($insert_id); } // return the table if needed return $this->table_array; diff --git a/www/vendor/egrajp/corelibs-composer-all/src/DB/IO.php b/www/vendor/egrajp/corelibs-composer-all/src/DB/IO.php index 4486b9a4..d5c90c97 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/DB/IO.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/DB/IO.php @@ -281,12 +281,6 @@ class IO public const NO_CACHE = 3; /** @var string default hash type */ public const ERROR_HASH_TYPE = 'adler32'; - /** - * @var string regex for params: only stand alone $number allowed - * never allowed to start with ' - * must be after space/tab, =, ( - */ - public const REGEX_PARAMS = '/[^\'][\s(=](\$[0-9]{1,})/'; /** @var string regex to get returning with matches at position 1 */ public const REGEX_RETURNING = '/\s+returning\s+(.+\s*(?:.+\s*)+);?$/i'; // REGEX_SELECT @@ -1264,6 +1258,32 @@ class IO return $return; } + /** + * count $ leading parameters only + * + * @param string $query Query to check + * @return int Number of parameters found + */ + private function __dbCountQueryParams(string $query): int + { + $match = []; + // regex for params: only stand alone $number allowed + // exclude all '' enclosed strings, ignore all numbers [note must start with digit] + // can have space/tab/new line + // must have = , ( [equal, comma, opening round bracket] + // can have space/tab/new line + // $ number with 1-9 for first and 0-9 for further digits + // /s for matching new line in . list + // [disabled, we don't used ^ or $] /m for multi line match + // Matches in 1:, must be array_filtered to remove empty, count with array_unique + preg_match_all( + '/(?:\'.*?\')?\s*(?:\?\?|[(=,])\s*(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s', + $query, + $match + ); + return count(array_unique(array_filter($match[1]))); + } + /** * Checks if the placeholder count in the query matches the params given * on call @@ -1274,10 +1294,7 @@ class IO */ private function __dbCheckQueryParams(string $query, int $params_count): bool { - // search for $1, $2, in the query and push it into the control array - // skip counts for same eg $1, $1, $2 = 2 and not 3 - preg_match_all(self::REGEX_PARAMS, $query, $match); - $placeholder_count = count(array_unique($match[1])); + $placeholder_count = $this->__dbCountQueryParams($query); if ($params_count != $placeholder_count) { $this->__dbError( 23, @@ -1384,6 +1401,9 @@ class IO ) { $this->returning_id = true; } + // import protection, hash needed + $query_hash = $this->dbGetQueryHash($this->query, $this->params); + // $this->debug('DB IO', 'Q: ' . $this->query . ', RETURN: ' . $this->returning_id); // for DEBUG, only on first time ;) $this->__dbDebug( @@ -1395,8 +1415,6 @@ class IO '__dbPrepareExec', ($this->params === [] ? 'Q' : 'Qp') ); - // import protection, hash needed - $query_hash = $this->dbGetQueryHash($this->query, $this->params); // if the array index does not exists set it 0 if (!array_key_exists($query_hash, $this->query_called)) { $this->query_called[$query_hash] = 0; @@ -2943,11 +2961,8 @@ class IO $this->prepare_cursor[$stm_name]['pk_name'] = $pk_name; } } - $match = []; - // search for $1, $2, in the query and push it into the control array - // skip counts for same eg $1, $1, $2 = 2 and not 3 - preg_match_all(self::REGEX_PARAMS, $query, $match); - $this->prepare_cursor[$stm_name]['count'] = count(array_unique($match[1])); + // check prepared curser parameter count + $this->prepare_cursor[$stm_name]['count'] = $this->__dbCountQueryParams($query); $this->prepare_cursor[$stm_name]['query'] = $query; $result = $this->db_functions->__dbPrepare($stm_name, $query); if ($result) { @@ -3232,7 +3247,7 @@ class IO * * @param array $write_array list of elements to write * @param array $not_write_array list of elements not to write - * @param int $primary_key id key to decide if we write insert or update + * @param int|null $primary_key id key to decide if we write insert or update * @param string $table name for the target table * @param array $data data array to override _POST data * @return int|false primary key @@ -3240,7 +3255,7 @@ class IO public function dbWriteData( array $write_array, array $not_write_array, - int $primary_key, + ?int $primary_key, string $table, array $data = [] ): int|false { @@ -3260,19 +3275,19 @@ class IO * PARAM INFO: $primary key * this can be a plain string/int and will be internal transformed into the array form * or it takes the array form of array [row => column, value => pk value] - * @param array $write_array list of elements to write - * @param int|string|array $primary_key primary key string or array set - * @param string $table name for the target table - * @param array $not_write_array list of elements not to write (optional) - * @param array $not_write_update_array list of elements not - * to write during update (optional) - * @param array $data optional array with data - * if not _POST vars are used - * @return int|false primary key + * @param array $write_array list of elements to write + * @param null|int|string|array $primary_key primary key string or array set + * @param string $table name for the target table + * @param array $not_write_array list of elements not to write (optional) + * @param array $not_write_update_array list of elements not + * to write during update (optional) + * @param array $data optional array with data + * if not _POST vars are used + * @return int|false primary key */ public function dbWriteDataExt( array $write_array, - int|string|array $primary_key, + null|int|string|array $primary_key, string $table, array $not_write_array = [], array $not_write_update_array = [], diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Logging/ErrorMessage.php b/www/vendor/egrajp/corelibs-composer-all/src/Logging/ErrorMessage.php index 2f9278ae..e0b4d001 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/Logging/ErrorMessage.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/Logging/ErrorMessage.php @@ -15,8 +15,10 @@ use CoreLibs\Logging\Logger\MessageLevel; class ErrorMessage { - /** @var array */ + /** @var array */ private array $error_str = []; + /** @var array */ + private array $jump_targets = []; /** @var \CoreLibs\Logging\Logging $log */ public \CoreLibs\Logging\Logging $log; @@ -27,13 +29,19 @@ class ErrorMessage * init ErrorMessage * * @param \CoreLibs\Logging\Logging $log - * @param bool $log_error [=false] + * @param null|bool $log_error [=null], defaults to false if log is not level debug */ public function __construct( \CoreLibs\Logging\Logging $log, - bool $log_error = false + ?bool $log_error = null ) { $this->log = $log; + // if log default logging is debug then log_error is default set to true + if ($this->log->loggingLevelIsDebug() && $log_error === null) { + $log_error = true; + } else { + $log_error = $log_error ?? false; + } $this->log_error = $log_error; } @@ -42,6 +50,7 @@ class ErrorMessage * error_id: internal Error ID (should be unique) * level: error level, can only be ok, info, warn, error, abort, crash * ok and info are positive response: success + * notice: a debug message for information only * warn: success, but there might be some things that are not 100% ok * error: input error or error in executing request * abort: an internal error happened as mandatory information that normally is @@ -52,24 +61,35 @@ class ErrorMessage * not set: unkown, will be logged as "emergency" * target/highlight: id target name for frontend where to attach this message * highlight is a list of other target points to highlight + * for highlight targets css names are $level without a prefix and should be + * nested in the target element "input .error { ... }" + * jump_target: a target id for to jump and message, is stored in separate jump array + * where the target is unique, first one set is used for info message + * target_style: if not set uses 'error-' $level as css style. applies to targets or main only * - * @param string $error_id Any internal error ID for this error - * @param string $level Error level in ok/info/warn/error - * @param string $str Error message (out) - * @param string $target alternate attachment point for this error message - * @param array $highlight Any additional error data as error OR - * highlight points for field highlights - * @param string|null $message If abort/crash, non localized $str - * @param array $context Additionl info for abort/crash messages - * @param bool|null $log_error [=null] log level 'error' to error, if null use global, - * else set for this call only + * @param string $error_id Any internal error ID for this error + * @param string $level Error level in ok/info/warn/error + * @param string $str Error message (out) + * @param string $target alternate attachment point for this error message + * @param string $target_style Alternate color style for the error message + * @param array $highlight Any additional error data as error OR + * highlight points for field highlights + * @param array{}|array{target:string,info?:string} $jump_target with "target" for where to jump and + * "info" for string to show in jump list + * target must be set, if info not set, default message used + * @param string|null $message If abort/crash, non localized $str + * @param array $context Additionl info for abort/crash messages + * @param bool|null $log_error [=null] log level 'error' to error, if null use global, + * else set for this call only */ public function setErrorMsg( string $error_id, string $level, string $str, string $target = '', + string $target_style = '', array $highlight = [], + array $jump_target = [], ?string $message = null, array $context = [], ?bool $log_error = null, @@ -88,10 +108,19 @@ class ErrorMessage 'level' => $level, 'str' => $str, 'target' => $target, + 'target_style' => $target_style, 'highlight' => $highlight, ]; + // set a jump target + $this->setJumpTarget($jump_target['target'] ?? null, $jump_target['info'] ?? null, $level); // write to log for abort/crash switch ($level) { + case 'notice': + $this->log->notice($message ?? $str, array_merge([ + 'id' => $error_id, + 'level' => $original_level, + ], $context)); + break; case 'error': if ($log_error) { $this->log->error($message ?? $str, array_merge([ @@ -126,28 +155,77 @@ class ErrorMessage * Note, the parameter order is different and does not need an error id * This is for backend alerts * - * @param string $level error level (ok/warn/info/error) - * @param string $str error string - * @param string|null $error_id optional error id for precise error lookup - * @param string $target Alternate id name for output target on frontend - * @param array $highlight Any additional error data as error OR - * highlight points for field highlights - * @param string|null $message If abort/crash, non localized $str - * @param array $context Additionl info for abort/crash messages - * @param bool|null $log_error [=null] log level 'error' to error, if null use global, - * else set for this call only + * @param string $level error level (ok/warn/info/error) + * @param string $str error string + * @param string|null $error_id optional error id for precise error lookup + * @param string $target Alternate id name for output target on frontend + * @param string $target_style Alternate color style for the error message + * @param array $highlight Any additional error data as error OR + * highlight points for field highlights + * @param array{}|array{target:string,info?:string} $jump_target with "target" for where to jump and + * "info" for string to show in jump list + * target must be set, if info not set, default message used + * @param string|null $message If abort/crash, non localized $str + * @param array $context Additionl info for abort/crash messages + * @param bool|null $log_error [=null] log level 'error' to error, if null use global, + * else set for this call only */ public function setMessage( string $level, string $str, ?string $error_id = null, string $target = '', + string $target_style = '', array $highlight = [], + array $jump_target = [], ?string $message = null, array $context = [], ?bool $log_error = null, ): void { - $this->setErrorMsg($error_id ?? '', $level, $str, $target, $highlight, $message, $context, $log_error); + $this->setErrorMsg( + $error_id ?? '', + $level, + $str, + $target, + $target_style, + $highlight, + $jump_target, + $message, + $context, + $log_error + ); + } + + /** + * Set a jump target. This can be used to jump directly a frontend html block + * with the target id set + * + * @param string|null $target + * @param string|null $info + * @param string $level [='error'] + * @return void + */ + public function setJumpTarget( + ?string $target, + ?string $info, + string $level = 'error', + ): void { + if ( + empty($target) || + array_key_exists($target, $this->jump_targets) + // !empty($this->jump_targets[$target]) + // also check if this is an alphanumeric string? css id compatible? + ) { + return; + } + if (empty($info)) { + $info = 'Jump to: ' . $target; + } + $level = MessageLevel::fromName($level)->name; + $this->jump_targets[$target] = [ + 'info' => $info, + 'level' => $level, + ]; } // ********************************************************************* @@ -178,7 +256,7 @@ class ErrorMessage * Gets the LAST entry in the array list. * If nothing found returns empty array set * - * @return array{id:string,level:string,str:string,target:string,highlight:string[]} Error block + * @return array{id:string,level:string,str:string,target:string,target:string,highlight:string[]} Error block */ public function getLastErrorMsg(): array { @@ -187,10 +265,31 @@ class ErrorMessage 'str' => '', 'id' => '', 'target' => '', + 'target_string' => '', 'highlight' => [], ]; } + /** + * Return the jump target list + * + * @return array{}|array List of jump targets with info text, + * or empty array if not set + */ + public function getJumpTarget(): array + { + $_jump_target = []; + foreach ($this->jump_targets as $target => $jump) { + $_jump_target[] = array_merge( + $jump, + [ + 'target' => $target, + ] + ); + } + return $_jump_target; + } + // ********************************************************************* // FLAG SETTERS // ********************************************************************* diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Logging/Logger/MessageLevel.php b/www/vendor/egrajp/corelibs-composer-all/src/Logging/Logger/MessageLevel.php index b3d09278..8efc8bca 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/Logging/Logger/MessageLevel.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/Logging/Logger/MessageLevel.php @@ -15,6 +15,7 @@ enum MessageLevel: int { case ok = 100; case info = 200; + case notice = 250; case warn = 300; case error = 400; case abort = 500; @@ -30,6 +31,7 @@ enum MessageLevel: int return match (strtolower($name)) { 'ok' => self::ok, 'info' => self::info, + 'notice' => self::notice, 'warn', 'warning' => self::warn, 'error' => self::error, 'abort' => self::abort, diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/Generate.php b/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/Generate.php index ba23f1ea..a09eab66 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/Generate.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/Generate.php @@ -221,7 +221,7 @@ namespace CoreLibs\Output\Form; use CoreLibs\Get\System; use CoreLibs\Debug\Support; -class Generate extends \CoreLibs\DB\Extended\ArrayIO +class Generate { // for the load statetment describes which elements from // the load query should be shown and i which format @@ -247,7 +247,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO public array $reference_array = []; // reference arrays -> stored in $this->reference_array[$table_name] => []; // NOTE: should be changed to this @var mixed[] /** @var array */ - public array $element_list; // element list for elements next to each other as a special sub group + public array $element_list = []; // element list for elements next to each other as a special sub group /** @var array */ public array $table_array = []; /** @var string */ @@ -300,7 +300,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // log /** @var \CoreLibs\Logging\Logging */ public \CoreLibs\Logging\Logging $log; - + /** @var \CoreLibs\DB\Extended\ArrayIO */ + public \CoreLibs\DB\Extended\ArrayIO $dba; // now some default error msgs (english) /** @var array */ public array $language_array = []; @@ -373,7 +374,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } // $log->debug('CONFIG ARRAY', $log->prAr($config_array)); // start the array_io class which will start db_io ... - parent::__construct( + $this->dba = new \CoreLibs\DB\Extended\ArrayIO( $db_config, $config_array['table_array'], $config_array['table_name'], @@ -392,9 +393,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO if (empty($this->load_query)) { $this->log->error('Missing Load Query for: ' . $this->my_page_name); } - $this->archive_pk_name = 'a_' . $this->pk_name; - $this->col_name = str_replace('_id', '', $this->pk_name); - $this->int_pk_name = $this->pk_name; + $this->archive_pk_name = 'a_' . $this->dba->getPkName(); + $this->col_name = str_replace('_id', '', $this->dba->getPkName()); + $this->int_pk_name = $this->dba->getPkName(); // check if reference_arrays are given and proceed them if (isset($config_array['reference_arrays']) && is_array($config_array['reference_arrays'])) { foreach ($config_array['reference_arrays'] as $key => $value) { @@ -447,17 +448,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $this->email_regex = \CoreLibs\Check\Email::getEmailRegex(); } - /** - * deconstructor - * writes out error msg to global var - * closes db connectio - */ - public function __destruct() - { - // close DB connection - parent::__destruct(); - } - // PRIVATE METHODS |=================================================> /** @@ -526,12 +516,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO */ public function formDumpTableArray() { - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - $string = 'TABLE ARRAY DUMP: ' . $this->table_name . '
'; - foreach ($this->table_array as $key => $value) { + $string = 'TABLE ARRAY DUMP: ' . $this->dba->getTableName() . '
'; + foreach ($this->dba->getTableArray() as $key => $value) { $string .= '' . $key . ': ' . $value['value'] . '
'; } return $string; @@ -550,11 +536,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO string $want_key, ?string $key_value = null ): ?string { - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { + foreach ($this->dba->getTableArray() as $key => $value) { if (isset($value[$want_key]) && !$key_value) { return $key; } elseif (isset($value[$want_key]) && $value[$want_key] == $key_value && $key_value) { @@ -577,11 +559,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO ?string $key_value = null ): array { $key_array = []; - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { + foreach ($this->dba->getTableArray(true) as $key => $value) { if ($value[$want_key] && !$key_value) { array_push($key_array, $key); } @@ -688,7 +666,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $this->delete && $this->base_acl_level >= $this->security_level['delete'] ) { - if (isset($this->table_array['protected']['value']) && $this->table_array['protected']['value']) { + if ( + !empty($this->dba->getTableArray()['protected']['value']) + ) { $this->msg .= $this->l->__('Cannot delete this Dataset, because it is internaly protected!'); $this->error = 2; } @@ -717,13 +697,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $this->log->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: ' . $this->base_acl_level . ' >= ' . $this->security_level['delete']); $this->log->debug('REMOVE ELEMENT', 'Protected Value set: ' - . (string)isset($this->table_array['protected']['value'])); + . (string)isset($this->dba->getTableArray()['protected']['value'])); $this->log->debug('REMOVE ELEMENT', 'Error: ' . $this->error); // only do if the user is allowed to delete if ( isset($this->security_level['delete']) && $this->base_acl_level >= $this->security_level['delete'] && - empty($this->table_array['protected']['value']) && + empty($this->dba->getTableArray()['protected']['value']) && !$this->error ) { for ($i = 0, $i_max = count($element_list); $i < $i_max; $i++) { @@ -753,7 +733,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $flag = $remove_name[$i] . '_flag'; if ($_POST[$flag] == 'true') { $q = 'DELETE FROM ' . $element_list[$i] . ' WHERE ' . $pk_name . ' = ' . $_POST[$id]; - $this->dbExec($q); + $this->dba->dbExec($q); $this->msg .= $this->l->__('Removed entry from list
'); $this->warning = 1; } // post okay true -> delete @@ -787,7 +767,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $q = 'DELETE FROM ' . $element_list[$i] . ' WHERE ' . $pk_name . ' = ' . $_POST[$prfx . $pk_name][$j]; // $this->log->debug('edit_db', 'DEL: $q'); - $this->dbExec($q); + $this->dba->dbExec($q); $this->msg .= $this->l->__('Deleted deselected entries from list
'); $this->warning = 1; } @@ -836,12 +816,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $t_pk_name = $this->archive_pk_name; // load list data - $this->dbExec($this->load_query); - while (is_array($res = $this->dbFetchArray())) { + $this->dba->dbExec($this->load_query); + while (is_array($res = $this->dba->dbFetchArray())) { $pk_ids[] = $res[$this->int_pk_name]; if ( - isset($this->table_array[$this->int_pk_name]['value']) && - $res[$this->int_pk_name] == $this->table_array[$this->int_pk_name]['value'] + isset($this->dba->getTableArray()[$this->int_pk_name]['value']) && + $res[$this->int_pk_name] == $this->dba->getTableArray()[$this->int_pk_name]['value'] ) { $pk_selected = $res[$this->int_pk_name]; } @@ -958,7 +938,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $this->base_acl_level >= $this->security_level['save'] ) { $seclevel_okay = true; - if (empty($this->table_array[$this->int_pk_name]['value'])) { + if (empty($this->dba->getTableArray()[$this->int_pk_name]['value'])) { $save = $this->l->__('Save'); } else { $save = $this->l->__('Update'); @@ -966,12 +946,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // print the old_school hidden if requestet if ($old_school_hidden === true) { $pk_name = $this->int_pk_name; - $pk_value = $this->table_array[$this->int_pk_name]['value']; + $pk_value = $this->dba->getTableArray()[$this->int_pk_name]['value']; } } // show save part // show delete part only if pk is set && we want to see the delete if ( - !empty($this->table_array[$this->int_pk_name]['value']) && + !empty($this->dba->getTableArray()[$this->int_pk_name]['value']) && !$hide_delete && !empty($this->security_level['delete']) && $this->base_acl_level >= $this->security_level['delete'] @@ -1005,47 +985,47 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $data = []; // special 2nd color for 'binary' attribut if ( - $this->table_array[$element_name]['type'] == 'binary' && - !isset($this->table_array[$element_name]['value']) + $this->dba->getTableArray()[$element_name]['type'] == 'binary' && + !isset($this->dba->getTableArray()[$element_name]['value']) ) { $EDIT_FGCOLOR_T = 'edit_fgcolor_no'; } else { $EDIT_FGCOLOR_T = 'edit_fgcolor'; } - $output_name = $this->table_array[$element_name]['output_name']; + $output_name = $this->dba->getTableArray()[$element_name]['output_name']; if ( - isset($this->table_array[$element_name]['mandatory']) && - $this->table_array[$element_name]['mandatory'] + isset($this->dba->getTableArray()[$element_name]['mandatory']) && + $this->dba->getTableArray()[$element_name]['mandatory'] ) { $output_name .= ' *'; } // create right side depending on 'definiton' in table_array - $type = $this->table_array[$element_name]['type']; + $type = $this->dba->getTableArray()[$element_name]['type']; // set default min edit/read to 100 (admin) - $min_edit_acl = $this->table_array[$element_name]['min_edit_acl'] ?? 100; - $min_show_acl = $this->table_array[$element_name]['min_show_acl'] ?? 100; + $min_edit_acl = $this->dba->getTableArray()[$element_name]['min_edit_acl'] ?? 100; + $min_show_acl = $this->dba->getTableArray()[$element_name]['min_show_acl'] ?? 100; $show_value = '-'; // view only output - if ($this->table_array[$element_name]['type'] == 'view') { - $data['value'] = empty($this->table_array[$element_name]['value']) ? - $this->table_array[$element_name]['empty'] : - $this->table_array[$element_name]['value']; + if ($this->dba->getTableArray()[$element_name]['type'] == 'view') { + $data['value'] = empty($this->dba->getTableArray()[$element_name]['value']) ? + $this->dba->getTableArray()[$element_name]['empty'] : + $this->dba->getTableArray()[$element_name]['value']; $show_value = $data['value']; } // binary true/false element - if ($this->table_array[$element_name]['type'] == 'binary') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'binary') { $data['checked'] = 0; - for ($i = (count($this->table_array[$element_name]['element_list']) - 1); $i >= 0; $i--) { + for ($i = (count($this->dba->getTableArray()[$element_name]['element_list']) - 1); $i >= 0; $i--) { $data['value'][] = $i; - $data['output'][] = $this->table_array[$element_name]['element_list'][$i] ?? null; + $data['output'][] = $this->dba->getTableArray()[$element_name]['element_list'][$i] ?? null; $data['name'] = $element_name; if ( - isset($this->table_array[$element_name]['value']) && - (($i && $this->table_array[$element_name]['value']) || - (!$i && !$this->table_array[$element_name]['value'])) + isset($this->dba->getTableArray()[$element_name]['value']) && + (($i && $this->dba->getTableArray()[$element_name]['value']) || + (!$i && !$this->dba->getTableArray()[$element_name]['value'])) ) { - $data['checked'] = $this->table_array[$element_name]['value']; - $show_value = $this->table_array[$element_name]['element_list'][$i] ?? $data['checked']; + $data['checked'] = $this->dba->getTableArray()[$element_name]['value']; + $show_value = $this->dba->getTableArray()[$element_name]['element_list'][$i] ?? $data['checked']; } if ($i) { @@ -1054,85 +1034,84 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } } // checkbox element - if ($this->table_array[$element_name]['type'] == 'checkbox') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'checkbox') { $data['name'] = $element_name; - $data['value'][] = $this->table_array[$element_name]['element_list']; - $data['checked'] = $this->table_array[$element_name]['value']; + $data['value'][] = $this->dba->getTableArray()[$element_name]['element_list']; + $data['checked'] = $this->dba->getTableArray()[$element_name]['value']; // array map element list + value // foreach ($data['checked'] as $checked) $show_value = join(', ', $data['checked']); } // normal text element - if ($this->table_array[$element_name]['type'] == 'text') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'text') { $data['name'] = $element_name; - $data['value'] = $this->table_array[$element_name]['value'] ?? ''; - $data['size'] = $this->table_array[$element_name]['size'] ?? ''; - $data['length'] = $this->table_array[$element_name]['length'] ?? ''; + $data['value'] = $this->dba->getTableArray()[$element_name]['value'] ?? ''; + $data['size'] = $this->dba->getTableArray()[$element_name]['size'] ?? ''; + $data['length'] = $this->dba->getTableArray()[$element_name]['length'] ?? ''; $show_value = $data['value']; } // password element, does not write back the value - if ($this->table_array[$element_name]['type'] == 'password') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'password') { $data['name'] = $element_name; - $data['HIDDEN_value'] = $this->table_array[$element_name]['HIDDEN_value']; - $data['size'] = $this->table_array[$element_name]['size'] ?? ''; - $data['length'] = $this->table_array[$element_name]['length'] ?? ''; + $data['HIDDEN_value'] = $this->dba->getTableArray()[$element_name]['HIDDEN_value']; + $data['size'] = $this->dba->getTableArray()[$element_name]['size'] ?? ''; + $data['length'] = $this->dba->getTableArray()[$element_name]['length'] ?? ''; } // date (YYYY-MM-DD) - if ($this->table_array[$element_name]['type'] == 'date') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'date') { $data['name'] = $element_name; - $data['value'] = $this->table_array[$element_name]['value'] ?? ''; + $data['value'] = $this->dba->getTableArray()[$element_name]['value'] ?? ''; $show_value = $data['value']; } // date time (no sec) (YYYY-MM-DD HH:mm) - if ($this->table_array[$element_name]['type'] == 'datetime') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'datetime') { $data['name'] = $element_name; - $data['value'] = $this->table_array[$element_name]['value'] ?? ''; + $data['value'] = $this->dba->getTableArray()[$element_name]['value'] ?? ''; $show_value = $data['value']; } // textarea - if ($this->table_array[$element_name]['type'] == 'textarea') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'textarea') { $data['name'] = $element_name; - $data['value'] = $this->table_array[$element_name]['value'] ?? ''; - $data['rows'] = $this->table_array[$element_name]['rows'] ?? ''; - $data['cols'] = $this->table_array[$element_name]['cols'] ?? ''; + $data['value'] = $this->dba->getTableArray()[$element_name]['value'] ?? ''; + $data['rows'] = $this->dba->getTableArray()[$element_name]['rows'] ?? ''; + $data['cols'] = $this->dba->getTableArray()[$element_name]['cols'] ?? ''; $show_value = $data['value']; } // for drop_down_* - if (preg_match("/^drop_down_/", $this->table_array[$element_name]['type'])) { + if (preg_match("/^drop_down_/", $this->dba->getTableArray()[$element_name]['type'])) { $type = 'drop_down'; // outer query overrules inner - if (empty($query) && !empty($this->table_array[$element_name]['query'])) { - $query = $this->table_array[$element_name]['query']; + if (empty($query) && !empty($this->dba->getTableArray()[$element_name]['query'])) { + $query = $this->dba->getTableArray()[$element_name]['query']; } } // for drop_down_db* $data['drop_down_input'] = 0; - if (preg_match("/^drop_down_db/", $this->table_array[$element_name]['type'])) { + if (preg_match("/^drop_down_db/", $this->dba->getTableArray()[$element_name]['type'])) { // if still NO query if (empty($query)) { // select pk_name, input_name from table_name (order by order_by) $query = "SELECT " . ( ( - isset($this->table_array[$element_name]['select_distinct']) && - $this->table_array[$element_name]['select_distinct'] + isset($this->dba->getTableArray()[$element_name]['select_distinct']) && + $this->dba->getTableArray()[$element_name]['select_distinct'] ) ? "DISTINCT" : '' ) . " " - . $this->table_array[$element_name]['pk_name'] . ", " - . $this->table_array[$element_name]['input_name'] . " "; - if (!empty($this->table_array[$element_name]['order_by'])) { - $query .= ", " . $this->table_array[$element_name]['order_by'] . " "; + . $this->dba->getTableArray()[$element_name]['pk_name'] . ", " + . $this->dba->getTableArray()[$element_name]['input_name'] . " "; + if (!empty($this->dba->getTableArray()[$element_name]['order_by'])) { + $query .= ", " . $this->dba->getTableArray()[$element_name]['order_by'] . " "; } - $query .= "FROM " . $this->table_array[$element_name]['table_name']; + $query .= "FROM " . $this->dba->getTableArray()[$element_name]['table_name']; // possible where statements - if (!empty($this->table_array[$element_name]['where'])) { - $query .= " WHERE " . $this->table_array[$element_name]['where']; + if (!empty($this->dba->getTableArray()[$element_name]['where'])) { + $query .= " WHERE " . $this->dba->getTableArray()[$element_name]['where']; } // not self where if ( - !empty($this->table_array[$element_name]['where_not_self']) && - isset($this->table_array[$this->int_pk_name]['value']) && - $this->table_array[$this->int_pk_name]['value'] + !empty($this->dba->getTableArray()[$element_name]['where_not_self']) && + !empty($this->dba->getTableArray()[$this->int_pk_name]['value']) ) { // check if query has where already if (strstr($query, 'WHERE') === false) { @@ -1140,104 +1119,119 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } else { $query .= " AND "; } - $query .= " " . $this->int_pk_name . " <> " . $this->table_array[$this->int_pk_name]['value']; + $query .= " " . $this->int_pk_name . " <> " + . $this->dba->getTableArray()[$this->int_pk_name]['value']; } // possible order statements - if (!empty($this->table_array[$element_name]['order_by'])) { - $query .= " ORDER BY " . $this->table_array[$element_name]['order_by']; + if (!empty($this->dba->getTableArray()[$element_name]['order_by'])) { + $query .= " ORDER BY " . $this->dba->getTableArray()[$element_name]['order_by']; } } // set output data $data['selected'] = ''; $data['name'] = $element_name; $data['value'][] = ''; - $data['output'][] = $this->l->__('Please choose .. . '); - while (is_array($res = $this->dbReturn($query))) { + $data['output'][] = $this->l->__('Please choose ... '); + // $this->log->debug('DROP DOWN DB', 'TABLE ARRAY [' . $element_name . ']: ' + // . $this->log->prAr($this->dba->getTableArray())); + while (is_array($res = $this->dba->dbReturn($query))) { + // $this->log->debug('DROP DOWN DB', 'Hightlight: [' . $element_name . '] ' + // . ($this->dba->getTableArray()[$element_name]['value'] ?? '-') + // . ' RES[0]: ' . $res[0] . ', Sel: ' . $res[1]); $data['value'][] = $res[0]; $data['output'][] = $res[1]; if ( - isset($this->table_array[$element_name]['value']) && - $this->table_array[$element_name]['value'] == $res[0] + isset($this->dba->getTableArray()[$element_name]['value']) && + $this->dba->getTableArray()[$element_name]['value'] == $res[0] ) { - $data['selected'] = $this->table_array[$element_name]['value']; + $data['selected'] = $this->dba->getTableArray()[$element_name]['value']; $show_value = $res[1]; + // $this->log->debug('DROP DOWN DB', 'Selectd [' . $element_name . ']: ' + // . $data['selected'] . '/' . $show_value); + // break; + // continue; } } + // $this->dbCacheReset($query); // for _input put additional field next to drop down - if (preg_match("/^drop_down_db_input/", $this->table_array[$element_name]['type'])) { + if (preg_match("/^drop_down_db_input/", $this->dba->getTableArray()[$element_name]['type'])) { $data['drop_down_input'] = 1; // pre fill the temp if empty and other side is selected, only for same_db if ( - $this->table_array[$element_name]['type'] == 'drop_down_db_input_same_db' && - !$this->table_array[$element_name]['input_value'] && - $this->table_array[$element_name]['value'] + $this->dba->getTableArray()[$element_name]['type'] == 'drop_down_db_input_same_db' && + !$this->dba->getTableArray()[$element_name]['input_value'] && + $this->dba->getTableArray()[$element_name]['value'] ) { - $this->table_array[$element_name]['input_value'] = $this->table_array[$element_name]['value']; + $this->dba->getTableArray()[$element_name]['input_value'] = + $this->dba->getTableArray()[$element_name]['value']; } - $data['input_value'] = $this->table_array[$element_name]['input_value']; - $data['input_name'] = $this->table_array[$element_name]['input_name'] - . (($this->table_array[$element_name]['type'] == 'drop_down_db_input_same_db') ? '_temp' : ''); - $data['input_size'] = $this->table_array[$element_name]['size']; - $data['input_length'] = $this->table_array[$element_name]['length']; + $data['input_value'] = $this->dba->getTableArray()[$element_name]['input_value']; + $data['input_name'] = $this->dba->getTableArray()[$element_name]['input_name'] + . (($this->dba->getTableArray()[$element_name]['type'] == 'drop_down_db_input_same_db') ? + '_temp' : '' + ); + $data['input_size'] = $this->dba->getTableArray()[$element_name]['size']; + $data['input_length'] = $this->dba->getTableArray()[$element_name]['length']; } } // drop down array - if ($this->table_array[$element_name]['type'] == 'drop_down_array') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'drop_down_array') { $data['selected'] = ''; $data['name'] = $element_name; $data['value'][] = ''; - $data['output'][] = $this->l->__('Please choose .. . '); + $data['output'][] = $this->l->__('Please choose ... '); // outer query overrules inner foreach ($query as $key => $value) { $data['value'][] = $key; $data['output'][] = $value; - if ($this->table_array[$element_name]['value'] == $key) { - $data['selected'] = $this->table_array[$element_name]['value']; + if ($this->dba->getTableArray()[$element_name]['value'] == $key) { + $data['selected'] = $this->dba->getTableArray()[$element_name]['value']; $show_value = $value; } } } // radio array - if ($this->table_array[$element_name]['type'] == 'radio_array') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'radio_array') { if (!$query) { - $query = $this->table_array[$element_name]['query']; + $query = $this->dba->getTableArray()[$element_name]['query']; } $data['name'] = $element_name; foreach ($query as $key => $value) { $data['value'][] = $key; $data['output'][] = $value; - if ($this->table_array[$element_name]['value'] == $key) { - $data['checked'] = $this->table_array[$element_name]['value']; + if ($this->dba->getTableArray()[$element_name]['value'] == $key) { + $data['checked'] = $this->dba->getTableArray()[$element_name]['value']; $show_value = $value; } $data['separator'] = ''; } } // for media / not yet implemented - if ($this->table_array[$element_name]['type'] == 'media') { - //media::insert_file($element_name,$this->table_array[$element_name]['value'],$query); + if ($this->dba->getTableArray()[$element_name]['type'] == 'media') { + //media::insert_file($element_name,$this->dba->getTableArray()[$element_name]['value'],$query); } // order button - if ($this->table_array[$element_name]['type'] == 'order') { - $data['output_name'] = $this->table_array[$element_name]['output_name']; + if ($this->dba->getTableArray()[$element_name]['type'] == 'order') { + $data['output_name'] = $this->dba->getTableArray()[$element_name]['output_name']; $data['name'] = $element_name; - $data['value'] = $this->table_array[$element_name]['value'] ?? 0; + $data['value'] = $this->dba->getTableArray()[$element_name]['value'] ?? 0; $data['col_name'] = $this->col_name; - $data['table_name'] = $this->table_name; + $data['table_name'] = $this->dba->getTableName(); $data['query'] = $query !== null ? urlencode($query) : ''; } // file upload - if ($this->table_array[$element_name]['type'] == 'file') { + if ($this->dba->getTableArray()[$element_name]['type'] == 'file') { $data['name'] = $element_name; // if file for this exsists, print 'delete, view stuff' - if ($this->table_array[$element_name]['value']) { + if ($this->dba->getTableArray()[$element_name]['value']) { $data['content'] = 1; - $data['url'] = $this->table_array[$element_name]['open_dir'] - . $this->table_array[$element_name]['value']; - $data['output'] = $this->table_array[$element_name]['value']; - $data['value'] = $this->table_array[$element_name]['value']; + $data['url'] = $this->dba->getTableArray()[$element_name]['open_dir'] + . $this->dba->getTableArray()[$element_name]['value']; + $data['output'] = $this->dba->getTableArray()[$element_name]['value']; + $data['value'] = $this->dba->getTableArray()[$element_name]['value']; } } + // $this->log->debug('ELEMENT CREATE', 'Data: [' . $output_name . '] ' . $this->log->prAr($data)); return [ 'output_name' => $output_name, 'color' => $EDIT_FGCOLOR_T, @@ -1260,11 +1254,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO */ public function formErrorCheck(): void { - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { + foreach ($this->dba->getTableArray() as $key => $value) { // skip if we are not allowe to write this anyway // $this->log->debug('ERROR CHECK', 'ACL K: ' . $key . ', ' // . ($value['min_edit_acl'] ?? 100) . ' < ' . $this->base_acl_level); @@ -1275,8 +1265,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // if error value set && somethign input, check if input okay if ( isset($value['error_check']) && - isset($this->table_array[$key]['value']) && - !empty($this->table_array[$key]['value']) + !empty($this->dba->getTableArray()[$key]['value']) ) { $this->log->debug('ERROR CHECK', 'Key: ' . $key . ' => ' . $value['error_check']); // each error check can be a piped seperated value, lets split it @@ -1284,41 +1273,45 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO foreach (explode('|', $value['error_check']) as $error_check) { switch ($error_check) { case 'number': - if (!is_numeric($this->table_array[$key]['value'])) { + if (!is_numeric($this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__('Please enter a vailid Number for the %s Field!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'date': // YYYY-MM-DD - if (!\CoreLibs\Combined\DateTime::checkDate($this->table_array[$key]['value'])) { + if (!\CoreLibs\Combined\DateTime::checkDate($this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__( 'Please enter a valid date (YYYY-MM-DD) for the %s Field!
' ), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'time': // HH:MM[:SS] - if (!\CoreLibs\Combined\DateTime::checkDateTime($this->table_array[$key]['value'])) { + if ( + !\CoreLibs\Combined\DateTime::checkDateTime($this->dba->getTableArray()[$key]['value']) + ) { $this->msg .= sprintf( $this->l->__( 'Please enter a valid time (HH:mm[:SS]) for the %s Field!
' ), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'datetime': // YYYY-MM-DD HH:MM[:SS] - if (!\CoreLibs\Combined\DateTime::checkDateTime($this->table_array[$key]['value'])) { + if ( + !\CoreLibs\Combined\DateTime::checkDateTime($this->dba->getTableArray()[$key]['value']) + ) { $this->msg .= sprintf( $this->l->__( 'Please enter a valid date time (YYYY-MM-DD HH:mm) ' . 'for the %s Field!
' ), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; @@ -1326,7 +1319,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO if ( !preg_match( "/^\d{1,3}\ ?([ymd]{1}|day(s)?|year(s)?|month(s)?)$/i", - $this->table_array[$key]['value'] + $this->dba->getTableArray()[$key]['value'] ) ) { $this->msg .= sprintf( @@ -1334,98 +1327,104 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO 'Please enter a valid time interval in the format ' . ' Y|M|D for the %s Field!
' ), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'email': - if (!preg_match("/$this->email_regex/", $this->table_array[$key]['value'])) { + if (!preg_match("/$this->email_regex/", $this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__( 'Please enter a valid E-Mail Address for the %s Field!
' ), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; // check unique, check if field in table is not yet exist case 'unique': $q = 'SELECT ' . $key . ' AS unique_row ' - . 'FROM ' . $this->table_name . ' ' + . 'FROM ' . $this->dba->getTableName() . ' ' . 'WHERE ' . $key . ' = ' - . "'" . $this->dbEscapeString($this->table_array[$key]['value']) . "'"; - if ($this->table_array[$this->int_pk_name]['value']) { + . "'" . $this->dba->dbEscapeString($this->dba->getTableArray()[$key]['value']) . "'"; + if ($this->dba->getTableArray()[$this->int_pk_name]['value']) { $q .= ' AND ' . $this->int_pk_name . ' <> ' - . $this->table_array[$this->int_pk_name]['value']; + . $this->dba->getTableArray()[$this->int_pk_name]['value']; } if ( - is_array($s_res = $this->dbReturnRow($q)) && + is_array($s_res = $this->dba->dbReturnRow($q)) && !empty($s_res['unique_row']) ) { $this->msg .= sprintf( $this->l->__('The field %s can be used only once!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'custom': if ( - !preg_match($this->table_array[$key]['error_regex'], $this->table_array[$key]['value']) + !preg_match( + $this->dba->getTableArray()[$key]['error_regex'], + $this->dba->getTableArray()[$key]['value'] + ) ) { $this->msg .= sprintf( $this->l->__('Please enter a valid (%s) input for the %s Field!
'), - $this->table_array[$key]['error_example'], - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['error_example'], + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'alphanumericspace': // $this->log->debug('edit', 'IN Alphanumericspace'); - if (!preg_match("/^[0-9A-Za-z_\-\ ]+$/", $this->table_array[$key]['value'])) { + if (!preg_match("/^[0-9A-Za-z_\-\ ]+$/", $this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__('Please enter a valid alphanumeric (Numbers and Letters, -, _ ' . 'and spaces allowed) value for the %s Field!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'alphanumeric': // $this->log->debug('edit', 'IN Alphanumeric'); - if (!preg_match("/^[0-9A-Za-z_\-]+$/", $this->table_array[$key]['value'])) { + if (!preg_match("/^[0-9A-Za-z_\-]+$/", $this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__('Please enter a valid alphanumeric (Numbers and Letters only ' . 'also - and _, no spaces) value for the %s Field!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; // this one also allows @ and . case 'alphanumericextended': // $this->log->debug('edit', 'IN Alphanumericextended'); - if (!preg_match("/^[0-9A-Za-z_\-@\.]+$/", $this->table_array[$key]['value'])) { + if (!preg_match("/^[0-9A-Za-z_\-@\.]+$/", $this->dba->getTableArray()[$key]['value'])) { $this->msg .= sprintf( $this->l->__('Please enter a valid alphanumeric extended (Numbers, Letters, -, ' . '_, @ and . only, no spaces) value for the %s Field!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } break; case 'password': // password can only be alphanumeric + special chars // password and CONFIRM_password need to be the same - if ($this->table_array[$key]['value'] != $this->table_array[$key]['CONFIRM_value']) { + if ( + $this->dba->getTableArray()[$key]['value'] != + $this->dba->getTableArray()[$key]['CONFIRM_value'] + ) { // error } break; case 'json': // check if valid json - $json_out = json_decode($this->table_array[$key]['value'], true); + $json_out = json_decode($this->dba->getTableArray()[$key]['value'], true); $this->log->debug('JSON ENCODE', 'LAST ERROR: ' . json_last_error() - . ' WITH: ' . $this->table_array[$key]['value']); + . ' WITH: ' . $this->dba->getTableArray()[$key]['value']); if (json_last_error()) { $this->msg .= sprintf( $this->l->__('Please enter a valid JSON string for the field %s: %s'), - $this->table_array[$key]['output_name'], + $this->dba->getTableArray()[$key]['output_name'], json_last_error_msg() ); } @@ -1438,48 +1437,49 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO ( // for all 'normal' fields ( - $this->table_array[$key]['type'] != 'password' && - $this->table_array[$key]['type'] != 'drop_down_db_input' && - !$this->table_array[$key]['value'] + $this->dba->getTableArray()[$key]['type'] != 'password' && + $this->dba->getTableArray()[$key]['type'] != 'drop_down_db_input' && + !$this->dba->getTableArray()[$key]['value'] ) || // for drop_down_db_input check if one of both fields filled ( - $this->table_array[$key]['type'] == 'drop_down_db_input' && - !$this->table_array[$key]['input_value'] && - !$this->table_array[$key]['value'] + $this->dba->getTableArray()[$key]['type'] == 'drop_down_db_input' && + !$this->dba->getTableArray()[$key]['input_value'] && + !$this->dba->getTableArray()[$key]['value'] ) || // for password ( - $this->table_array[$key]['type'] == 'password' && - !$this->table_array[$key]['value'] && - !$this->table_array[$key]['HIDDEN_value'] + $this->dba->getTableArray()[$key]['type'] == 'password' && + !$this->dba->getTableArray()[$key]['value'] && + !$this->dba->getTableArray()[$key]['HIDDEN_value'] ) ) // main if end ) { // if mandatory && no input - // $this->log->debug('form', 'A: ' . $this->table_array[$key]['type'] . ' -- ' - // . $this->table_array[$key]['input_value'] . ' -- ' . $this->table_array[$key]['value']); + // $this->log->debug('form', 'A: ' . $this->dba->getTableArray()[$key]['type'] . ' -- ' + // . $this->dba->getTableArray()[$key]['input_value'] . ' -- ' + // . $this->dba->getTableArray()[$key]['value']); if ( - empty($this->table_array[$key]['value']) && - $this->table_array[$key]['type'] != 'binary' + empty($this->dba->getTableArray()[$key]['value']) && + $this->dba->getTableArray()[$key]['type'] != 'binary' ) { $this->msg .= sprintf( $this->l->__('Please enter something into the %s field!
'), - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } } // mandatory // check file upload if ( - isset($this->table_array[$key]['type']) && - $this->table_array[$key]['type'] == 'file' && + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'file' && $GLOBALS['_FILES'][$key . '_file']['name'] && - is_array($this->table_array[$key]['accept_type']) + is_array($this->dba->getTableArray()[$key]['accept_type']) ) { // check against allowed types $mime_okay = 0; - foreach ($this->table_array[$key]['accept_type'] as $mime_type) { + foreach ($this->dba->getTableArray()[$key]['accept_type'] as $mime_type) { if ($GLOBALS['_FILES'][$key . '_file']['type'] == $mime_type) { $mime_okay = 1; } @@ -1490,7 +1490,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO . 'theallowed MIME List for Upload Field %s!
'), $GLOBALS['_FILES'][$key . '_file']['name'], $GLOBALS['_FILES'][$key . '_file']['type'], - $this->table_array[$key]['output_name'] + $this->dba->getTableArray()[$key]['output_name'] ); } } @@ -1505,8 +1505,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO continue; } if ( - isset($this->reference_array[$key]['mandatory']) && - $this->reference_array[$key]['mandatory'] && + !empty($this->reference_array[$key]['mandatory']) && !$this->reference_array[$key]['selected'][0] ) { $this->msg .= sprintf( @@ -1516,7 +1515,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } } // $this->log->debug('edit_error', 'QS:
' . print_r($_POST, true) . '
'); - if (is_array($this->element_list)) { + if (!empty($this->element_list)) { // check the mandatory stuff // if mandatory, check that at least on pk exists or // if at least the mandatory field is filled @@ -1572,8 +1571,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // either one of the post pks is set, or the mandatory foreach ($reference_array['elements'] as $el_name => $data_array) { if ( - isset($data_array['mandatory']) && - $data_array['mandatory'] + /** @phan-suppress-next-line PhanTypeMismatchDimAssignment This error makes no sense */ + !empty($data_array['mandatory']) ) { $mand_name = $data_array['output_name']; } @@ -1710,35 +1709,35 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // get order name $order_name = $this->formGetColNameFromKey('order'); if (empty($order_name)) { - return $this->table_array; + return $this->dba->getTableArray(); } // first check out of order ... - if (empty($this->table_array[$order_name]['value'])) { + if (empty($this->dba->getTableArray()[$order_name]['value'])) { // set order (read max) $q = 'SELECT MAX(' . $order_name . ') + 1 AS max_page_order ' - . 'FROM ' . $this->table_name; + . 'FROM ' . $this->dba->getTableName(); if ( - is_array($res = $this->dbReturnRow($q)) && + is_array($res = $this->dba->dbReturnRow($q)) && !empty($res['max_page_order']) ) { - $this->table_array[$order_name]['value'] = $res['max_page_order']; + $this->dba->setTableArrayEntry($res['max_page_order'], $order_name, 'value'); } // frist element is 0 because NULL gets returned, set to 1 - if (!$this->table_array[$order_name]['value']) { - $this->table_array[$order_name]['value'] = 1; + if (!$this->dba->getTableArray()[$order_name]['value']) { + $this->dba->setTableArrayEntry(1, $order_name, 'value'); } - } elseif (!empty($this->table_array[$this->int_pk_name]['value'])) { + } elseif (!empty($this->dba->getTableArray()[$this->int_pk_name]['value'])) { $q = 'SELECT ' . $order_name . ' AS order_name ' - . 'FROM ' . $this->table_name . ' ' - . 'WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; + . 'FROM ' . $this->dba->getTableName() . ' ' + . 'WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; if ( - is_array($res = $this->dbReturnRow($q)) && + is_array($res = $this->dba->dbReturnRow($q)) && !empty($res['order_name']) ) { - $this->table_array[$order_name]['value'] = $res['order_name']; + $this->dba->setTableArrayEntry($res['order_name'], $order_name, 'value'); } } - return $this->table_array; + return $this->dba->getTableArray(); } /** @@ -1748,17 +1747,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO */ public function formUnsetTableArray(): void { - $this->pk_id = null; - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { - unset($this->table_array[$key]['value']); - unset($this->table_array[$key]['input_value']); + $this->dba->setPkId(null); + foreach ($this->dba->getTableArray() as $key => $value) { + $this->dba->unsetTableArrayEntry($key, 'value'); + $this->dba->unsetTableArrayEntry($key, 'input_value'); // if preset var present preset - if (isset($this->table_array[$key]['preset'])) { - $this->table_array[$key]['value'] = $this->table_array[$key]['preset']; + if (isset($this->dba->getTableArray()[$key]['preset'])) { + $this->dba->setTableArrayEntry($this->dba->getTableArray()[$key]['preset'], $key, 'value'); } } if (is_array($this->reference_array)) { @@ -1783,17 +1778,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO public function formLoadTableArray(?string $pk_id = null): void { if ($pk_id) { - $this->pk_id = $pk_id; + $this->dba->setPkId($pk_id); } - $this->table_array = $this->dbRead(true); + $this->dba->setTableArray($this->dba->dbRead(true)); - // reset all temp fields - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { - unset($this->table_array[$key]['input_value']); + foreach ($this->dba->getTableArray() as $key => $value) { + $this->dba->unsetTableArrayEntry($key, 'input_value'); } if (is_array($this->reference_array)) { @@ -1806,8 +1796,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO unset($this->reference_array[$key]['selected']); $q = 'SELECT ' . $this->reference_array[$key]['other_table_pk'] . ' FROM ' . $this->reference_array[$key]['table_name'] - . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; - while (is_array($res = $this->dbReturn($q))) { + . ' WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; + while (is_array($res = $this->dba->dbReturn($q))) { $this->reference_array[$key]['selected'][] = $res[$this->reference_array[$key]['other_table_pk']]; } } @@ -1828,84 +1818,88 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO { // for drop_down_db_input check if text field is filled and if, if not yet in db ... // and upload files - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { + + foreach ($this->dba->getTableArray() as $key => $value) { // drop_down_db with input + reference table - // $this->log->debug('form', 'A: ' . $this->table_array[$key]['type'] - // . ' --- ' . $this->table_array[$key]['input_value']); + // $this->log->debug('form', 'A: ' . $this->dba->getTableArray()[$key]['type'] + // . ' --- ' . $this->dba->getTableArray()[$key]['input_value']); if ( - isset($this->table_array[$key]['type']) && - $this->table_array[$key]['type'] == 'drop_down_db_input' && - $this->table_array[$key]['input_value'] + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'drop_down_db_input' && + $this->dba->getTableArray()[$key]['input_value'] ) { // $this->log->debug('form', 'HERE'); // check if this text name already exists (lowercase compare) - $q = 'SELECT ' . $this->table_array[$key]['pk_name'] . ' AS pk_name ' - . ' FROM ' . $this->table_array[$key]['table_name'] - . ' WHERE LCASE(' . $this->table_array[$key]['input_name'] . ') = ' - . "'" . $this->dbEscapeString(strtolower($this->table_array[$key]['input_value'])) . "'"; + $q = 'SELECT ' . $this->dba->getTableArray()[$key]['pk_name'] . ' AS pk_name ' + . ' FROM ' . $this->dba->getTableArray()[$key]['table_name'] + . ' WHERE LCASE(' . $this->dba->getTableArray()[$key]['input_name'] . ') = ' + . "'" . $this->dba->dbEscapeString( + strtolower($this->dba->getTableArray()[$key]['input_value']) + ) . "'"; // if a where was given, add here - if ($this->table_array[$key]['where']) { - $q .= ' AND ' . $this->table_array[$key]['where']; + if ($this->dba->getTableArray()[$key]['where']) { + $q .= ' AND ' . $this->dba->getTableArray()[$key]['where']; } if ( - is_array($s_res = $this->dbReturnRow($q)) && + is_array($s_res = $this->dba->dbReturnRow($q)) && !empty($s_res['pk_name']) ) { - // $this->table_array[$key]['value'] = $pk_name_temp; - $this->table_array[$key]['value'] = $s_res['pk_name']; + $this->dba->setTableArrayEntry($s_res['pk_name'], $key, 'value'); } else { // if a where was given, set this key also [dangerous!] // postgreSQL compatible insert - $q = 'INSERT INTO ' . $this->table_array[$key]['table_name'] - . ' (' . $this->table_array[$key]['input_name'] . ') VALUES (' - . "'" . $this->dbEscapeString($this->table_array[$key]['input_value']) . "')"; - $this->dbExec($q); - if (!empty($this->table_array[$key]['where']) && is_numeric($this->dbGetInsertPK())) { + $q = 'INSERT INTO ' . $this->dba->getTableArray()[$key]['table_name'] + . ' (' . $this->dba->getTableArray()[$key]['input_name'] . ') VALUES (' + . "'" . $this->dba->dbEscapeString($this->dba->getTableArray()[$key]['input_value']) . "')"; + $this->dba->dbExec($q); + if (!empty($this->dba->getTableArray()[$key]['where']) && is_numeric($this->dba->dbGetInsertPK())) { // make an update on the just inseted data with the where data als update values - $q = 'UPDATE ' . $this->table_array[$key]['table_name'] . ' SET '; - $q .= $this->table_array[$key]['where'] . ' '; - $q .= 'WHERE ' . $this->table_array[$key]['pk_name'] . ' = ' . $this->dbGetInsertPK(); - $this->dbExec($q); + $q = 'UPDATE ' . $this->dba->getTableArray()[$key]['table_name'] . ' SET '; + $q .= $this->dba->getTableArray()[$key]['where'] . ' '; + $q .= 'WHERE ' . $this->dba->getTableArray()[$key]['pk_name'] + . ' = ' . $this->dba->dbGetInsertPK(); + $this->dba->dbExec($q); } - $this->table_array[$key]['value'] = $this->dbGetInsertPK(); + $this->dba->setTableArrayEntry($this->dba->dbGetInsertPK(), $key, 'value'); } // set value from DB through select or insert - unset($this->table_array[$key]['input_value']); + $this->dba->unsetTableArrayEntry($key, 'input_value'); } // if it is certain field type && if there is something in the temp field // drop_down_db with input and in same table if ( - isset($this->table_array[$key]['type']) && - $this->table_array[$key]['type'] == 'drop_down_db_input_same_db' && - $this->table_array[$key]['input_value'] + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'drop_down_db_input_same_db' && + $this->dba->getTableArray()[$key]['input_value'] ) { // if drop down & input are different - if ($this->table_array[$key]['input_value'] != $this->table_array[$key]['value']) { + if ($this->dba->getTableArray()[$key]['input_value'] != $this->dba->getTableArray()[$key]['value']) { // check if 'right input' is in DB - $q = 'SELECT ' . $this->table_array[$key]['input_name'] . ' AS temp ' - . ' FROM ' . $this->table_array[$key]['table_name'] - . ' WHERE LCASE(' . $this->table_array[$key]['input_name'] . ') = ' - . "'" . strtolower($this->dbEscapeString($this->table_array[$key]['input_value'])) . "'"; + $q = 'SELECT ' . $this->dba->getTableArray()[$key]['input_name'] . ' AS temp ' + . ' FROM ' . $this->dba->getTableArray()[$key]['table_name'] + . ' WHERE LCASE(' . $this->dba->getTableArray()[$key]['input_name'] . ') = ' + . "'" . strtolower($this->dba->dbEscapeString( + $this->dba->getTableArray()[$key]['input_value'] + )) . "'"; // if a where was given, add here - if ($this->table_array[$key]['where']) { - $q .= ' AND ' . $this->table_array[$key]['where']; + if ($this->dba->getTableArray()[$key]['where']) { + $q .= ' AND ' . $this->dba->getTableArray()[$key]['where']; } if ( - is_array($s_res = $this->dbReturnRow($q)) && + is_array($s_res = $this->dba->dbReturnRow($q)) && empty($s_res['temp']) ) { - $this->table_array[$key]['value'] = $this->table_array[$key]['input_value']; + $this->dba->setTableArrayEntry($this->dba->getTableArray()[$key]['input_value'], $key, 'value'); } else { // found in DB - $this->table_array[$key]['input_value'] = $this->table_array[$key]['value']; + $this->dba->setTableArrayEntry($this->dba->getTableArray()[$key]['value'], $key, 'input_value'); } } // key difference ? } // for same_db drop down // upload & save files to locations - if (isset($this->table_array[$key]['type']) && $this->table_array[$key]['type'] == 'file') { + if ( + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'file' + ) { // if smth in $$key_file -> save or overwrite // if smth in $key && $$key_delete && !$$key_file-> delte // if smth in $key, keep as is @@ -1915,20 +1909,25 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // $this->log->debug('form', 'delete: ' . $key . '_delete => ' . $GLOBALS[$key . '_delete']); if ($GLOBALS['_FILES'][$key . '_file']['name']) { // check if dir exists - if (is_dir($this->table_array[$key]['save_dir'])) { + if (is_dir($this->dba->getTableArray()[$key]['save_dir'])) { //if a slash at the end (if not add slash) - if (!preg_match("|/$|", $this->table_array[$key]['save_dir'])) { - $this->table_array[$key]['save_dir'] .= '/'; + if (!preg_match("|/$|", $this->dba->getTableArray()[$key]['save_dir'])) { + $this->dba->getTableArray()[$key]['save_dir'] .= '/'; } if ( move_uploaded_file( $GLOBALS['_FILES'][$key . '_file']['tmp_name'], - $this->table_array[$key]['save_dir'] . $GLOBALS['_FILES'][$key . '_file']['name'] + $this->dba->getTableArray()[$key]['save_dir'] + . $GLOBALS['_FILES'][$key . '_file']['name'] ) ) { // make it unique with a unique number at the beginning - $this->table_array[$key]['value'] = uniqid((string)rand(), true) - . '_' . $GLOBALS['_FILES'][$key . '_file']['name']; + $this->dba->setTableArrayEntry( + uniqid((string)rand(), true) + . '_' . $GLOBALS['_FILES'][$key . '_file']['name'], + $key, + 'value' + ); } else { $this->msg .= $this->l->__('File could not be copied to target directory! ' . 'Perhaps wrong directory permissions . '); @@ -1937,40 +1936,47 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } else { $this->msg .= sprintf( $this->l->__('Target Directory \'%s\' is not a vaild directory!'), - $this->table_array[$key]['save_dir'] + $this->dba->getTableArray()[$key]['save_dir'] ); $this->error = 1; } // could not dir check (dir wrong??) } if ( !empty($GLOBALS[$key . '_delete']) && - $this->table_array[$key]['value'] && !$GLOBALS['_FILES'][$key . '_file']['name'] + $this->dba->getTableArray()[$key]['value'] && !$GLOBALS['_FILES'][$key . '_file']['name'] ) { - unlink($this->table_array[$key]['save_dir'] . $this->table_array[$key]['value']); - unset($this->table_array[$key]['value']); + unlink($this->dba->getTableArray()[$key]['save_dir'] . $this->dba->getTableArray()[$key]['value']); + $this->dba->unsetTableArrayEntry($key, 'value'); } } // for password crypt it as blowfish, or if not available MD5 - if (isset($this->table_array[$key]['type']) && $this->table_array[$key]['type'] == 'password') { - if ($this->table_array[$key]['value']) { + if ( + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'password' + ) { + if ($this->dba->getTableArray()[$key]['value']) { // use the better new passwordSet instead of crypt based - $this->table_array[$key]['value'] = - \CoreLibs\Security\Password::passwordSet($this->table_array[$key]['value']); - $this->table_array[$key]['HIDDEN_value'] = $this->table_array[$key]['value']; + $this->dba->getTableArray()[$key]['value'] = + \CoreLibs\Security\Password::passwordSet($this->dba->getTableArray()[$key]['value']); + $this->dba->setTableArrayEntry( + $this->dba->getTableArray()[$key]['value'], + $key, + 'HIDDEN_value' + ); } else { - // $this->table_array[$key]['HIDDEN_value'] = + // $this->dba->getTableArray()[$key]['HIDDEN_value'] = } } } // go through each field // set object order (if necessary) $this->formSetOrder(); - // $this->log->debug('PK NAME SET', "PK NAME: " . $this->pk_name . "/" . $this->int_pk_name . ": " - // . $this->table_array[$this->pk_name]['value'] . "/" - // . $this->table_array[$this->int_pk_name]['value']); + // $this->log->debug('PK NAME SET', "PK NAME: " . $this->dba->getPkName() . "/" . $this->int_pk_name . ": " + // . $this->dba->getTableArray()[$this->dba->getPkName()]['value'] . "/" + // . $this->dba->getTableArray()[$this->int_pk_name]['value']); // write the object - $this->dbWrite($addslashes, [], true); + $this->dba->dbWrite($addslashes, [], true); // write reference array (s) if necessary if (is_array($this->reference_array)) { if (!is_array($this->reference_array)) { @@ -1979,19 +1985,19 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO reset($this->reference_array); foreach ($this->reference_array as $reference_array) { $q = 'DELETE FROM ' . $reference_array['table_name'] - . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; - $this->dbExec($q); + . ' WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; + $this->dba->dbExec($q); $q = 'INSERT INTO ' . $reference_array['table_name'] . ' (' . $reference_array['other_table_pk'] . ', ' . $this->int_pk_name . ') VALUES '; for ($i = 0, $i_max = count($reference_array['selected']); $i < $i_max; $i++) { $t_q = '(' . $reference_array['selected'][$i] . ', ' - . $this->table_array[$this->int_pk_name]['value'] . ')'; - $this->dbExec($q . $t_q); + . $this->dba->getTableArray()[$this->int_pk_name]['value'] . ')'; + $this->dba->dbExec($q . $t_q); } } // foreach reference arrays } // if reference arrays // write element list - if (is_array($this->element_list)) { + if (!empty($this->element_list)) { $type = []; reset($this->element_list); foreach ($this->element_list as $table_name => $reference_array) { @@ -2169,8 +2175,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $q_values[$i] .= $_value; } else { // normal data gets escaped - $q_data[$i] .= $el_name . ' = ' . "'" . $this->dbEscapeString($_value) . "'"; - $q_values[$i] .= "'" . $this->dbEscapeString($_value) . "'"; + $q_data[$i] .= $el_name . ' = ' . "'" . $this->dba->dbEscapeString($_value) . "'"; + $q_values[$i] .= "'" . $this->dba->dbEscapeString($_value) . "'"; } } } @@ -2198,14 +2204,14 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO . $this->int_pk_name . ($q_middle[$i] ?? '') . ($q_values[$i] ?? '') . ', ' - . $this->table_array[$this->int_pk_name]['value'] + . $this->dba->getTableArray()[$this->int_pk_name]['value'] . $q_end[$i]; } /** @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset */ $this->log->debug('edit', 'Pos[' . $i . '] => ' . $type[$i] . ' Q: ' . $q . '
'); // write the dataset if ($q) { - $this->dbExec($q); + $this->dba->dbExec($q); } } } // for each created query @@ -2230,33 +2236,29 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO reset($this->reference_array); foreach ($this->reference_array as $reference_array) { $q = 'DELETE FROM ' . $reference_array['table_name'] - . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; - $this->dbExec($q); + . ' WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; + $this->dba->dbExec($q); } } // remove any element list references - if (is_array($this->element_list)) { - if (!is_array($this->element_list)) { - $this->element_list = []; - } + if (!empty($this->element_list)) { reset($this->element_list); foreach ($this->element_list as $table_name => $data_array) { $q = 'DELETE FROM ' . $table_name - . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; - $this->dbExec($q); + . ' WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; + $this->dba->dbExec($q); } } // unlink ALL files - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { - if (isset($this->table_array[$key]['type']) && $this->table_array[$key]['type'] == 'file') { - unlink($this->table_array[$key]['save_dir'] . $this->table_array[$key]['value']); + foreach ($this->dba->getTableArray() as $key => $value) { + if ( + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'file' + ) { + unlink($this->dba->getTableArray()[$key]['save_dir'] . $this->dba->getTableArray()[$key]['value']); } } - $this->dbDelete(); + $this->dba->dbDelete(); $this->warning = 1; $this->msg = $this->l->__('Dataset has been deleted!'); } @@ -2270,17 +2272,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO public function formCreateHiddenFields(array $hidden_array = []): array { $hidden = []; - if (!is_array($this->table_array)) { - $this->table_array = []; - } - reset($this->table_array); - foreach ($this->table_array as $key => $value) { + foreach ($this->dba->getTableArray() as $key => $value) { if ( - isset($this->table_array[$key]['type']) && - $this->table_array[$key]['type'] == 'hidden' + isset($this->dba->getTableArray()[$key]['type']) && + $this->dba->getTableArray()[$key]['type'] == 'hidden' ) { - if (array_key_exists($key, $this->table_array)) { - $hidden_array[$key] = $this->table_array[$key]['value'] ?? ''; + if (array_key_exists($key, $this->dba->getTableArray())) { + $hidden_array[$key] = $this->dba->getTableArray()[$key]['value'] ?? ''; } else { $hidden_array[$key] = ''; } @@ -2318,7 +2316,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } $data['name'] = $this->reference_array[$table_name]['other_table_pk']; $data['size'] = $this->reference_array[$table_name]['select_size']; - while (is_array($res = $this->dbReturn($this->reference_array[$table_name]['query']))) { + while (is_array($res = $this->dba->dbReturn($this->reference_array[$table_name]['query']))) { $data['value'][] = $res[0]; $data['output'][] = $res[1]; $selected = (\CoreLibs\Convert\Html::checked( @@ -2434,18 +2432,18 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } // if drop down db read data for element list from the given sub table as from the query // only two elements are allowed: pos 0 is key, pso 1 is visible output name - if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') { - while (is_array($res = $this->dbReturn($data_array['query']))) { + if (!empty($data_array['type']) && $data_array['type'] == 'drop_down_db') { + while (is_array($res = $this->dba->dbReturn($data_array['query']))) { /** @phan-suppress-next-line PhanTypeInvalidDimOffset */ - $this->log->debug('edit', 'Q[' . $this->dbGetQueryHash($data_array['query']) . '] pos: ' - . $this->dbGetCursorPos($data_array['query']) - . ' | want: ' . ($data_array['preset'] ?? '-') - . ' | set: ' . ($data['preset'][$el_name] ?? '-')); + // $this->log->debug('ELEMENT LIST', 'Q[' . $this->dba->dbGetQueryHash($data_array['query']) . '] ' + // . 'pos: ' . $this->dba->dbGetCursorPos($data_array['query']) + // . ' | want: ' . ($data_array['preset'] ?? '-') + // . ' | set: ' . ($data['preset'][$el_name] ?? '-')); // first is default for this element if ( isset($data_array['preset']) && (!isset($data['preset'][$el_name]) || empty($data['preset'][$el_name])) && - ($this->dbGetCursorPos($data_array['query']) == $data_array['preset']) + ($this->dba->dbGetCursorPos($data_array['query']) == $data_array['preset']) ) { $data['preset'][$el_name] = $res[0]; } @@ -2456,11 +2454,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } elseif (isset($data_array['element_list'])) { $data['element_list'][$el_name] = $data_array['element_list']; // this is for the checkboxes } - $this->log->debug('CREATE ELEMENT LIST TABLE', 'Table: ' . $table_name . ', Post: ' . $el_name . ' => ' - . ((isset($_POST[$el_name]) && is_array($_POST[$el_name])) ? - 'AS ARRAY'/*.$this->log->prAr($_POST[$el_name])*/ : - 'NOT SET/OR NOT ARRAY') - . ((isset($_POST[$el_name]) && !is_array($_POST[$el_name])) ? $_POST[$el_name] : '')); + // $this->log->debug('ELEMENT LIST', 'Data: ' + // . (count($data['element_list'][$el_name] ?? []) ? 'YES' : '*NO*') + // . ', B: ' . (is_bool($res ?? null) ? 'Y' : 'N')); + // $this->log->debug('POST CREATE ELEMENT LIST TABLE', 'Table: ' . $table_name + // . ', Post: ' . $el_name . ' => ' + // . ((isset($_POST[$el_name]) && is_array($_POST[$el_name])) ? + // 'AS ARRAY'/*.$this->log->prAr($_POST[$el_name])*/ : + // 'NOT SET/OR NOT ARRAY') + // . ((isset($_POST[$el_name]) && !is_array($_POST[$el_name])) ? $_POST[$el_name] : '')); // if error, check new line addition so we don't lose it if ($this->error) { if (isset($_POST[$el_name]) && is_array($_POST[$el_name])) { @@ -2519,7 +2521,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $data['type'][$data['prefix'] . $this->element_list[$table_name]['read_data']['name']] = 'string'; // build the read query $q = 'SELECT '; - // if (!$this->table_array[$this->int_pk_name]['value']) + // if (!$this->dba->getTableArray()[$this->int_pk_name]['value']) // $q .= 'DISTINCT '; // prefix join key with table name, and implode the query select part $q .= str_replace( @@ -2533,7 +2535,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO implode(', ', $_q_select) ) . ' '; // if ( - // !$this->table_array[$this->int_pk_name]['value'] && + // !$this->dba->getTableArray()[$this->int_pk_name]['value'] && // $this->element_list[$table_name]['read_data']['order'] // ) { // $q .= ', ' . $this->element_list[$table_name]['read_data']['order'] . ' '; @@ -2549,10 +2551,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO . $this->element_list[$table_name]['read_data']['pk_id'] . ' = ' /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */ . $table_name . '.' . $this->element_list[$table_name]['read_data']['pk_id'] . ' '; - // if ($this->table_array[$this->int_pk_name]['value']) + // if ($this->dba->getTableArray()[$this->int_pk_name]['value']) $q .= 'AND ' . $table_name . '.' . $this->int_pk_name . ' = ' - . (!empty($this->table_array[$this->int_pk_name]['value']) ? - $this->table_array[$this->int_pk_name]['value'] : + . (!empty($this->dba->getTableArray()[$this->int_pk_name]['value']) ? + $this->dba->getTableArray()[$this->int_pk_name]['value'] : 'NULL') . ' '; $q .= ') '; if (isset($this->element_list[$table_name]['read_data']['order'])) { @@ -2566,12 +2568,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO // only create query if we have a primary key // reads directly from the reference table if ( - isset($this->table_array[$this->int_pk_name]['value']) && - $this->table_array[$this->int_pk_name]['value'] + isset($this->dba->getTableArray()[$this->int_pk_name]['value']) && + $this->dba->getTableArray()[$this->int_pk_name]['value'] ) { $q = 'SELECT ' . implode(', ', $q_select) . ' FROM ' . $table_name - . ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value']; + . ' WHERE ' . $this->int_pk_name . ' = ' . $this->dba->getTableArray()[$this->int_pk_name]['value']; } } // $this->log->debug('CFG QUERY', 'Q: ' . $q); @@ -2581,7 +2583,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO $prfx = $data['prefix']; // short $pos = 0; // position in while for overwrite if needed // read out the list and add the selected data if needed - while (is_array($res = $this->dbReturn($q))) { + while (is_array($res = $this->dba->dbReturn($q))) { $_data = []; // go through each res for ($i = 0, $i_max = count($q_select); $i < $i_max; $i++) { @@ -2696,9 +2698,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO } elseif ( !empty($data['fk_name']) && $el_name == $data['fk_name'] && - isset($this->table_array[$this->int_pk_name]['value']) + isset($this->dba->getTableArray()[$this->int_pk_name]['value']) ) { - $_data[$el_name] = $this->table_array[$this->int_pk_name]['value']; + $_data[$el_name] = $this->dba->getTableArray()[$this->int_pk_name]['value']; } } $data['content'][] = $_data; diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/TableArrays/EditOrder.php b/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/TableArrays/EditOrder.php new file mode 100644 index 00000000..b67c2ef3 --- /dev/null +++ b/www/vendor/egrajp/corelibs-composer-all/src/Output/Form/TableArrays/EditOrder.php @@ -0,0 +1,40 @@ +form = $form; + $this->form->log->debug('CLASS LOAD', __NAMESPACE__ . __CLASS__); + } + + /** + * NOTE: this is a dummy array to just init the Form\Generate class and is not used for anything else + * + * @return array + */ + public function setTableArray(): array + { + return [ + 'table_array' => [ + '-' + ], + 'table_name' => '-', + 'load_query' => '', + 'show_fields' => [], + ]; + } +} + +// __END__ diff --git a/www/vendor/egrajp/corelibs-composer-all/src/Output/Image.php b/www/vendor/egrajp/corelibs-composer-all/src/Output/Image.php index 5af6ce3f..897e6495 100644 --- a/www/vendor/egrajp/corelibs-composer-all/src/Output/Image.php +++ b/www/vendor/egrajp/corelibs-composer-all/src/Output/Image.php @@ -470,12 +470,20 @@ class Image * * @param string $filename path + filename to rotate. This file must be writeable * @return void + * @throws \RuntimeException if exit_read_data is not found + * @throws \UnexpectedValueException if file name not writeable or file name not found */ public static function correctImageOrientation(string $filename): void { // function exists & file is writeable, else do nothing - if (!function_exists('exif_read_data') || !is_writeable($filename)) { - return; + if (!function_exists('exif_read_data')) { + throw new \RuntimeException('Function \'exit_read_data\' does not exist'); + } + if (!file_exists($filename) || !is_file($filename)) { + throw new \UnexpectedValueException('Missing image file: ' . $filename); + } + if (!is_writeable($filename)) { + throw new \UnexpectedValueException('File name is not writeable: ' . $filename); } [$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [0, 0, null]; // add @ to avoid "file not supported error" diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/DB/CoreLibsDBIOTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/DB/CoreLibsDBIOTest.php index 40479e1a..d1d598f3 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/DB/CoreLibsDBIOTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/DB/CoreLibsDBIOTest.php @@ -3907,7 +3907,8 @@ final class CoreLibsDBIOTest extends TestCase 'id' => '51', 'error' => 'Max query call needs to be set to at least 1', // run:: can be +1 if called in set and not direct - 'source' => "/^include::main::run::run::run::run::run::run::(run::)?runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall$/", + // 'main::run::run::run::run::run::run::run::runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall + 'source' => "/^(include::)?main::(run::)+runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall$/", 'pg_error' => '', 'msg' => '', ] diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Debug/CoreLibsDebugSupportTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Debug/CoreLibsDebugSupportTest.php index 2420d5a6..ab74df7d 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Debug/CoreLibsDebugSupportTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Debug/CoreLibsDebugSupportTest.php @@ -460,8 +460,8 @@ final class CoreLibsDebugSupportTest extends TestCase * Undocumented function * * @cover ::getCallerFileLine - * @testWith ["vendor/phpunit/phpunit/src/Framework/TestCase.php:"] - * @testdox getCallerFileLine check based on regex /[\w\-\/]/vendor/phpunit/phpunit/src/Framework/TestCase.php:\d+ [$_dataName] + * @testWith ["vendor/phpunit/phpunit/src/Framework/TestCase.php:6434","phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php:6434"] + * @testdox getCallerFileLine check based on regex .../Framework/TestCase.php:\d+ [$_dataName] * * @param string $expected * @return void @@ -469,7 +469,14 @@ final class CoreLibsDebugSupportTest extends TestCase public function testGetCallerFileLine(): void { // regex prefix with path "/../" and then fixed vendor + \d+ - $regex = "/^\/[\w\-\/]+\/vendor\/phpunit\/phpunit\/src\/Framework\/TestCase.php:\d+$/"; + // or phar start if phiev installed + // phar:///home/clemens/.phive/phars/phpunit-9.6.13.phar/phpunit/Framework/TestCase.php + $regex = "/^(" + . "\/.*\/vendor\/phpunit\/phpunit\/src" + . "|" + . "phar:\/\/\/.*\.phive\/phars\/phpunit-\d+\.\d+\.\d+\.phar\/phpunit" + . ")" + . "\/Framework\/TestCase.php:\d+$/"; $this->assertMatchesRegularExpression( $regex, Support::getCallerFileLine() @@ -514,27 +521,30 @@ final class CoreLibsDebugSupportTest extends TestCase // add nothing $this->assertEquals( $expected, - Support::getCallerMethodList(), + $compare, 'assert expected 10' ); break; case 11: - // add one "run" before "runBare" - // array_splice( - // $expected, - // 7, - // 0, - // ['run'] - // ); - array_splice( - $expected, - 0, - 0, - ['include'] - ); + if ($compare[0] == 'include') { + // add include at first + array_splice( + $expected, + 0, + 0, + ['include'] + ); + } else { + array_splice( + $expected, + 6, + 0, + ['run'] + ); + } $this->assertEquals( $expected, - Support::getCallerMethodList(), + $compare, 'assert expected 11' ); break; @@ -554,7 +564,7 @@ final class CoreLibsDebugSupportTest extends TestCase ); $this->assertEquals( $expected, - Support::getCallerMethodList(), + $compare, 'assert expected 12' ); break; diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Get/CoreLibsGetSystemTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Get/CoreLibsGetSystemTest.php index 221553cc..a73e91fc 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Get/CoreLibsGetSystemTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Get/CoreLibsGetSystemTest.php @@ -99,7 +99,7 @@ final class CoreLibsGetSystemTest extends TestCase 1 => 'phpunit', 2 => 'phpunit', // NOTE: this can change, so it is a regex check - 3 => "/^(\/?.*\/?)?vendor\/bin\/phpunit$/", + 3 => "/^(\/?.*\/?)?(vendor\/bin|tools)\/phpunit$/", ], 'some path with extension' => [ 0 => '/some/path/to/file.txt', diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php index bfec4227..7e1729cc 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingErrorMessagesTest.php @@ -44,6 +44,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'str' => 'INFO', 'expected' => 'info', ], + 'notice' => [ + 'level' => 'notice', + 'str' => 'NOTICE', + 'expected' => 'notice', + ], 'warn' => [ 'level' => 'warn', 'str' => 'WARN', @@ -91,9 +96,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase public function testErrorMessageLevelOk(string $level, string $str, string $expected): void { $log = new \CoreLibs\Logging\Logging([ - 'log_file_id' => 'testErrorMessages', + 'log_file_id' => 'testErrorMessagesLevelOk', 'log_folder' => self::LOG_FOLDER, - 'log_level' => Level::Debug, + 'log_level' => Level::Error, ]); $em = new \CoreLibs\Logging\ErrorMessage($log); $em->setMessage( @@ -106,6 +111,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'str' => $str, 'id' => '', 'target' => '', + 'target_style' => '', 'highlight' => [], ], $em->getLastErrorMsg() @@ -122,9 +128,9 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase public function testErrorMessageOk(): void { $log = new \CoreLibs\Logging\Logging([ - 'log_file_id' => 'testErrorMessages', + 'log_file_id' => 'testErrorMessagesOk', 'log_folder' => self::LOG_FOLDER, - 'log_level' => Level::Debug + 'log_level' => Level::Error ]); $em = new \CoreLibs\Logging\ErrorMessage($log); $em->setErrorMsg( @@ -139,6 +145,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'level' => 'info', 'str' => 'INFO MESSAGE', 'target' => '', + 'target_style' => '', 'highlight' => [], ], $em->getLastErrorMsg() @@ -154,6 +161,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'level' => 'info', 'str' => 'INFO MESSAGE', 'target' => '', + 'target_style' => '', 'highlight' => [], ] ], @@ -171,6 +179,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'level' => 'error', 'str' => 'ERROR MESSAGE', 'target' => '', + 'target_style' => '', 'highlight' => [], ], $em->getLastErrorMsg() @@ -186,6 +195,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'level' => 'info', 'str' => 'INFO MESSAGE', 'target' => '', + 'target_style' => '', 'highlight' => [], ], [ @@ -193,6 +203,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'level' => 'error', 'str' => 'ERROR MESSAGE', 'target' => '', + 'target_style' => '', 'highlight' => [], ] ], @@ -232,6 +243,22 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase 'log_error' => true, 'expected' => ' OTHER ERROR MESSAGE', ], + 'notice' => [ + 'id' => '100', + 'level' => 'notice', + 'str' => 'NOTICE MESSAGE', + 'message' => null, + 'log_error' => null, + 'expected' => ' NOTICE MESSAGE', + ], + 'notice, message' => [ + 'id' => '100', + 'level' => 'notice', + 'str' => 'NOTICE MESSAGE', + 'message' => 'OTHER NOTICE MESSAGE', + 'log_error' => null, + 'expected' => ' OTHER NOTICE MESSAGE', + ], 'crash' => [ 'id' => '300', 'level' => 'crash', @@ -287,7 +314,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase * Undocumented function * * @dataProvider providerErrorMessageLog - * @testdox Test Log writing [$_dataName] + * @testdox Test Log writing with log level Error [$_dataName] * * @param string $id * @param string $level @@ -297,7 +324,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase * @param string $expected * @return void */ - public function testErrorMessageLog( + public function testErrorMessageLogErrorLevel( string $id, string $level, string $str, @@ -306,7 +333,63 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase string $expected ): void { $log = new \CoreLibs\Logging\Logging([ - 'log_file_id' => 'testErrorMessages', + 'log_file_id' => 'testErrorMessagesLogError', + 'log_folder' => self::LOG_FOLDER, + 'log_level' => Level::Notice, + 'log_per_run' => true + ]); + $em = new \CoreLibs\Logging\ErrorMessage($log); + $em->setErrorMsg( + $id, + $level, + $str, + message: $message, + log_error: $log_error + ); + $file_content = ''; + if (is_file($log->getLogFolder() . $log->getLogFile())) { + $file_content = file_get_contents( + $log->getLogFolder() . $log->getLogFile() + ) ?: ''; + } + // if error, if null or false, it will not be logged + if ($level == 'error' && ($log_error === null || $log_error === false)) { + $this->assertStringNotContainsString( + $expected, + $file_content + ); + } else { + $this->assertStringContainsString( + $expected, + $file_content + ); + } + } + + /** + * Undocumented function + * + * @dataProvider providerErrorMessageLog + * @testdox Test Log writing with log Level Debug [$_dataName] + * + * @param string $id + * @param string $level + * @param string $str + * @param string|null $message + * @param bool|null $log_error + * @param string $expected + * @return void + */ + public function testErrorMessageLogErrorDebug( + string $id, + string $level, + string $str, + ?string $message, + ?bool $log_error, + string $expected + ): void { + $log = new \CoreLibs\Logging\Logging([ + 'log_file_id' => 'testErrorMessagesLogDebug', 'log_folder' => self::LOG_FOLDER, 'log_level' => Level::Debug, 'log_per_run' => true @@ -325,8 +408,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase $log->getLogFolder() . $log->getLogFile() ) ?: ''; } - // if n - if ($level == 'error' && ($log_error === null || $log_error === false)) { + // if error, and log is debug level, only explicit false are not logged + if ($level == 'error' && $log_error === false) { $this->assertStringNotContainsString( $expected, $file_content @@ -338,6 +421,84 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase ); } } + + /** + * Undocumented function + * + * @testdox Test jump target set and reporting + * + * @return void + */ + public function testJumpTarget(): void + { + $log = new \CoreLibs\Logging\Logging([ + 'log_file_id' => 'testErrorMessagesLogDebug', + 'log_folder' => self::LOG_FOLDER, + 'log_level' => Level::Debug, + 'log_per_run' => true + ]); + $em = new \CoreLibs\Logging\ErrorMessage($log); + $em->setJumpTarget( + 'target-f', + 'Target text' + ); + $this->assertEquals( + [ + ['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'] + ], + $em->getJumpTarget() + ); + // set same target, keep as before + $em->setJumpTarget( + 'target-f', + 'Other text' + ); + $this->assertEquals( + [ + ['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'] + ], + $em->getJumpTarget() + ); + // add new now two messages + $em->setJumpTarget( + 'target-s', + 'More text' + ); + $this->assertEquals( + [ + ['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'], + ['target' => 'target-s', 'info' => 'More text', 'level' => 'error'], + ], + $em->getJumpTarget() + ); + // add empty info + $em->setJumpTarget( + 'target-e', + '' + ); + $this->assertEquals( + [ + ['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'], + ['target' => 'target-s', 'info' => 'More text', 'level' => 'error'], + ['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'], + ], + $em->getJumpTarget() + ); + // add through message + $em->setErrorMsg('E-101', 'abort', 'Abort message', jump_target:[ + 'target' => 'abort-target', + 'info' => 'Abort error' + ]); + $this->assertEquals( + [ + ['target' => 'target-f', 'info' => 'Target text', 'level' => 'error'], + ['target' => 'target-s', 'info' => 'More text', 'level' => 'error'], + ['target' => 'target-e', 'info' => 'Jump to: target-e', 'level' => 'error'], + ['target' => 'abort-target', 'info' => 'Abort error', 'level' => 'abort'], + ], + $em->getJumpTarget() + ); + } } // __END__ diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingLoggingTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingLoggingTest.php index bf9a189f..da99916d 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingLoggingTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Logging/CoreLibsLoggingLoggingTest.php @@ -20,7 +20,7 @@ final class CoreLibsLoggingLoggingTest extends TestCase private const LOG_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR; private const REGEX_BASE = "\[[\d\-\s\.:]+\]\s{1}" // date . "\[[\w\.]+(:\d+)?\]\s{1}" // host:port - . "\[[\w\-\.\/]+:\d+\]\s{1}" // folder/file + . "\[(phar:\/\/)?[\w\-\.\/]+:\d+\]\s{1}" // folder/file [note phar:// is for phpunit] . "\[\w+\]\s{1}" // run id . "{[\w\\\\]+((::|->)\w+)?}\s{1}"; // class diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Output/CoreLibsOutputImageTest.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Output/CoreLibsOutputImageTest.php index 53840934..aa8dff97 100644 --- a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Output/CoreLibsOutputImageTest.php +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/Output/CoreLibsOutputImageTest.php @@ -16,17 +16,89 @@ final class CoreLibsOutputImageTest extends TestCase /** * Undocumented function * - * @testdox Output\Image Class tests + * @covers ::createThumbnail + * @testdox createThumbnail checks * * @return void */ - public function testOutputImage() + public function testCreateThumbnail(): void { - // $this->assertTrue(true, 'Output Image Tests not implemented'); - $this->markTestIncomplete( - 'Output\Image Tests have not yet been implemented' + // CONVERT does not exist + $this->expectException(\RuntimeException::class); + \CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200); + // set convert + $paths = [ + '/bin', + '/usr/bin', + '/usr/local/bin', + ]; + // find convert + foreach ($paths as $path) { + if ( + file_exists($path . DIRECTORY_SEPARATOR . 'convert') && + is_file($path . DIRECTORY_SEPARATOR . 'convert') + ) { + // image magick convert location + define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert'); + break; + } + } + unset($paths); + // cannot set dummy file + $this->expectException(\Exception::class); + \CoreLibs\Output\Image::createThumbnail('do_not_exist.png', 200, 200); + } + + /** + * Undocumented function + * + * @covers ::createThumbnailSimple + * @testdox createThumbnailSimple checks + * + * @return void + */ + public function testCreateThumbnailSimple(): void + { + // file does not exist + $this->expectException(\UnexpectedValueException::class); + \CoreLibs\Output\Image::createThumbnailSimple( + 'do_not_exist.png', + 200, + 200, + cache_folder: '/tmp/', + web_folder: '/tmp/' ); - // $this->markTestSkipped('No implementation for Output\Image at the moment'); + // cache folder is not dir + $this->expectException(\UnexpectedValueException::class); + \CoreLibs\Output\Image::createThumbnailSimple( + 'do_not_exist.png', + 200, + 200, + cache_folder: '/foo/bar/', + web_folder: '/tmp/' + ); + // target cache folder is not writeable + + // RuntimeException: imagecreatetruecolor failed + // RuntimeException: imagecolorallocatealpha failed + } + + /** + * Undocumented function + * + * @covers ::correctImageOrientation + * @testdox correctImageOrientation checks + * + * @return void + */ + public function testCorrectImageOrientation(): void + { + // test file does not exist + $this->expectException(\UnexpectedValueException::class); + \CoreLibs\Output\Image::correctImageOrientation('do_not_exist.png'); + // test folder not writeable + // test exit_read_data not present (how)? + // test image rotate } } diff --git a/www/vendor/egrajp/corelibs-composer-all/test/phpunit/bootstrap.php b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/bootstrap.php new file mode 100644 index 00000000..ab99d7a2 --- /dev/null +++ b/www/vendor/egrajp/corelibs-composer-all/test/phpunit/bootstrap.php @@ -0,0 +1,15 @@ +