Fix all classes with PHP-DOC style method comments

Also various fixes for clean phan run
Update config base for array type host settings and no long single
entries
This commit is contained in:
Clemens Schwaighofer
2019-09-19 11:56:27 +09:00
parent 9ea8364aab
commit bf96eb755d
20 changed files with 2067 additions and 2109 deletions

View File

@@ -1,4 +1,7 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations $DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
$DEBUG_ALL = 1; $DEBUG_ALL = 1;
@@ -27,7 +30,7 @@ $lang = 'en_utf8';
// init login & backend class // init login & backend class
$login = new CoreLibs\ACL\Login(DB_CONFIG, $lang); $login = new CoreLibs\ACL\Login(DB_CONFIG, $lang);
$basic = new CoreLibs\Admin\Backend(DB_CONFIG, $lang); $basic = new CoreLibs\Admin\Backend(DB_CONFIG, $lang);
$basic->dbInfo(1); $basic->dbInfo(true);
ob_end_flush(); ob_end_flush();
echo "DB_CONFIG_SET constant: <pre>".print_r(DB_CONFIG, true)."</pre><br>"; echo "DB_CONFIG_SET constant: <pre>".print_r(DB_CONFIG, true)."</pre><br>";
@@ -37,15 +40,20 @@ $basic->runningTime();
echo "RANDOM KEY [50]: ".$basic->randomKeyGen(50)."<br>"; echo "RANDOM KEY [50]: ".$basic->randomKeyGen(50)."<br>";
echo "TIMED [hr]: ".$basic->hrRunningTime()."<br>"; echo "TIMED [hr]: ".$basic->hrRunningTime()."<br>";
echo "TIMED [def]: ".$basic->runningTime()."<br>"; echo "TIMED [def]: ".$basic->runningTime()."<br>";
echo "TIMED [string]: ".$basic->runningtime_string."<br>";
$basic->hrRunningTime(); $basic->hrRunningTime();
echo "RANDOM KEY [default]: ".$basic->randomKeyGen()."<br>"; echo "RANDOM KEY [default]: ".$basic->randomKeyGen()."<br>";
echo "TIMED: ".$basic->hrRunningTime()."<br>"; echo "TIMED [hr]: ".$basic->hrRunningTime()."<br>";
// color
print "COLOR: -1, -1, -1: ".$basic->rgb2hex(-1, -1, -1)."<br>";
print "COLOR: 10, 20, 30: ".$basic->rgb2hex(10, 20, 30)."<br>";
// set + check edit access id // set + check edit access id
$edit_access_id = 3; $edit_access_id = 3;
if (is_object($login) && isset($login->acl['unit'])) { if (is_object($login) && isset($login->acl['unit'])) {
print "ACL UNIT: ".print_r(array_keys($login->acl['unit']), true)."<br>"; print "ACL UNIT: ".print_r(array_keys($login->acl['unit']), true)."<br>";
print "ACCESS CHECK: ".$login->loginCheckEditAccess($edit_access_id)."<br>"; print "ACCESS CHECK: ".(string)$login->loginCheckEditAccess($edit_access_id)."<br>";
if ($login->loginCheckEditAccess($edit_access_id)) { if ($login->loginCheckEditAccess($edit_access_id)) {
$basic->edit_access_id = $edit_access_id; $basic->edit_access_id = $edit_access_id;
} else { } else {

View File

@@ -21,19 +21,19 @@ ob_end_flush();
print "Start time: ".$base->runningTime()."<br>"; print "Start time: ".$base->runningTime()."<br>";
print "ByteStringFormat: ".$base->ByteStringFormat(1234567.12)."<br>"; print "ByteStringFormat: ".$base->ByteStringFormat(1234567.12)."<br>";
print "byteStringFormat: ".$base->byteStringFormat(1234567.12)."<br>"; print "byteStringFormat: ".$base->byteStringFormat(1234567.12)."<br>";
print "get_page_name [DEPRECATED]: ".$base->get_page_name()."<br>"; // print "get_page_name [DEPRECATED]: ".$base->get_page_name()."<br>";
print "getPageName: ".$base->getPageName()."<br>"; print "getPageName: ".$base->getPageName()."<br>";
print "DB Info: ".$base->dbInfo(1)."<br>"; print "DB Info: ".$base->dbInfo(true)."<br>";
print "End Time: ".$base->runningTime()."<br>"; print "End Time: ".$base->runningTime()."<br>";
print "Run Time: ".$base->runningTime()."<br>"; print "Start Time: ".$base->runningTime()."<br>";
$base->resetRunningtime();
print "Lang: ".$base->l->__getLang().", MO File: ".$base->l->__getMoFile()."<br>"; print "Lang: ".$base->l->__getLang().", MO File: ".$base->l->__getMoFile()."<br>";
print "Translate test: Year -> ".$base->l->__('Year')."<br>"; print "Translate test: Year -> ".$base->l->__('Year')."<br>";
print "End Time: ".$base->runningTime()."<br>";
// end error print // end error print
print $base->printErrorMsg(); print $base->printErrorMsg();

View File

@@ -1,4 +1,7 @@
<?php <?php
/**
* @phan-file-suppress PhanTypeSuspiciousStringExpression
*/
namespace CoreLibs; namespace CoreLibs;
@@ -16,7 +19,7 @@ print "THIS HOST: ".HOST_NAME.", with PROTOCOL: ".HOST_PROTOCOL." is running SSL
print "DIR: ".DIR."<br>"; print "DIR: ".DIR."<br>";
print "BASE: ".BASE."<br>"; print "BASE: ".BASE."<br>";
print "ROOT: ".ROOT."<br>"; print "ROOT: ".ROOT."<br>";
print "HOST: ".HOST_NAME." => DB HOST: ".DB_CONFIG_NAME." => ".DB_SCHEMA." => ".print_r(DB_CONFIG, true)."<br>"; print "HOST: ".HOST_NAME." => DB HOST: ".DB_CONFIG_NAME." => ".print_r(DB_CONFIG, true)."<br>";
$text = 'I am some text $text = 'I am some text
with some with some

View File

@@ -14,7 +14,7 @@ $DB_CONFIG = array (
'db_user' => 'gullevek', 'db_user' => 'gullevek',
'db_pass' => 'gullevek', 'db_pass' => 'gullevek',
'db_host' => 'db.tokyo.tequila.jp', 'db_host' => 'db.tokyo.tequila.jp',
'db_port' => '5432', 'db_port' => 5432,
'db_schema' => 'public', 'db_schema' => 'public',
'db_type' => 'pgsql', 'db_type' => 'pgsql',
'db_encoding' => '', 'db_encoding' => '',

View File

@@ -13,21 +13,21 @@
*********************************************************************/ *********************************************************************/
// each host has a different db_host // each host has a different db_host
// development host $SITE_CONFIG = array (
$DB_HOST['soba.tokyo.tequila.jp'] = 'test'; // development host
// target host (live) 'soba.tokyo.tequila.jp' => array (
// $DB_TARGET_HOST['soba'] = '<DB ID>'; // db config selection
// url redirect database 'db_host' => 'test',
// $DB_URL_REDIRECT_HOST['soba'] = '<DB ID>'; // other db connections
// location flagging // 'db_host_target' => '',
// test/dev/live // 'db_host_other' => '',
$LOCATION['soba.tokyo.tequila.jp'] = 'test'; // location flagging (test/dev/live) for debug output
// show DEBUG override 'location' => 'test',
// true/false // show DEBUG override
$DEBUG_FLAG['soba.tokyo.tequila.jp'] = true; 'debug_flag' => true,
// set postgresql paths (schemas) // site language
$DB_PATH['soba.tokyo.tequila.jp'] = PUBLIC_SCHEMA; 'site_lang' => 'en_utf8',
// site language )
$SITE_LANG['soba.tokyo.tequila.jp'] = 'en_utf8'; );
// __END__ // __END__

View File

@@ -171,20 +171,8 @@ DEFINE('LIVE_SCHEMA', 'public');
if (file_exists(BASE.CONFIGS.'config.host.php')) { if (file_exists(BASE.CONFIGS.'config.host.php')) {
require BASE.CONFIGS.'config.host.php'; require BASE.CONFIGS.'config.host.php';
} }
if (!isset($DB_HOST)) { if (!isset($SITE_CONFIG)) {
$DB_HOST = array (); $SITE_CONFIG = array ();
}
if (!isset($DB_PATH)) {
$DB_PATH = array ();
}
if (!isset($LOCATION)) {
$LOCATION = array ();
}
if (!isset($DEBUG_FLAG)) {
$DEBUG_FLAG = array ();
}
if (!isset($SITE_LANG)) {
$SITE_LANG = array ();
} }
/************* DB ACCESS *****************/ /************* DB ACCESS *****************/
if (file_exists(BASE.CONFIGS.'config.db.php')) { if (file_exists(BASE.CONFIGS.'config.db.php')) {
@@ -198,15 +186,25 @@ if (file_exists(BASE.CONFIGS.'config.path.php')) {
require BASE.CONFIGS.'config.path.php'; require BASE.CONFIGS.'config.path.php';
} }
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
// live frontend pages // live frontend pages
// ** missing live domains ** // ** missing live domains **
// get the name without the port // get the name without the port
list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null); list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null);
if (!isset($DB_HOST[$HOST_NAME]) && $USE_DATABASE) { // BAIL ON:
echo 'No matching DB config found. Contact Admin<br>'; // we have either no db selction for this host but have db config entries
// or we have a db selection but no db config as array or empty
// or we have a selection but no matching db config entry
if ((!isset($SITE_CONFIG[$HOST_NAME]['db_host']) && isset($DB_CONFIG) && count($DB_CONFIG)) ||
(isset($SITE_CONFIG[$HOST_NAME]['db_host']) &&
// missing DB CONFIG
(!isset($DB_CONFIG)) ||
(isset($DB_CONFIG) && is_array($DB_CONFIG) && !count($DB_CONFIG)) ||
(isset($DB_CONFIG) && !is_array($DB_CONFIG)) ||
// has DB CONFIG but no match
(isset($DB_CONFIG) && is_array($DB_CONFIG) && count($DB_CONFIG) && !isset($DB_CONFIG[$SITE_CONFIG[$HOST_NAME]['db_host']]))
)
) {
echo 'No matching DB config found for: "'.$HOST_NAME.'". Contact Administrator';
exit -1; exit -1;
} }
// set HOST name // set HOST name
@@ -221,25 +219,24 @@ if ((array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVE
DEFINE('HOST_PROTOCOL', 'http://'); DEFINE('HOST_PROTOCOL', 'http://');
} }
// define the db config set name, the db config and the db schema // define the db config set name, the db config and the db schema
DEFINE('DB_CONFIG_NAME', $DB_HOST[$HOST_NAME]); DEFINE('DB_CONFIG_NAME', $SITE_CONFIG[$HOST_NAME]['db_host']);
DEFINE('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME]); DEFINE('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME]);
DEFINE('DB_SCHEMA', $DB_PATH[$HOST_NAME]); // DEFINE('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
// DEFINE('TARGET_DB', $DB_TARGET_HOST[$HOST_NAME]); // DEFINE('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
// DEFINE('URL_REDIRECT_DB', $DB_URL_REDIRECT_HOST[$HOST_NAME]); // override for login and global schemas
// next three if top is not set // DEFINE('LOGIN_DB_SCHEMA', PUBLIC_SCHEMA); // where the edit* tables are
// DEFINE('TEST_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']); // DEFINE('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA); // where global tables are that are used by all schemas (eg queue tables for online, etc)
// DEFINE('DEV_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']); // debug settings, site lang, etc
// DEFINE('PUBLIC_SCHEMA', $DB_CONFIG[TARGET_DB]['db_schema']); DEFINE('TARGET', $SITE_CONFIG[$HOST_NAME]['location']);
DEFINE('LOGIN_DB_SCHEMA', PUBLIC_SCHEMA); // where the edit* tables are DEFINE('DEBUG', $SITE_CONFIG[$HOST_NAME]['debug_flag']);
DEFINE('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA); // where global tables are that are used by all schemas (eg queue tables for online, etc) DEFINE('SITE_LANG', $SITE_CONFIG[$HOST_NAME]['site_lang']);
DEFINE('TARGET', $LOCATION[$HOST_NAME]); // paths
// DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']); // DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']);
// DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']); // DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
// DEFINE('REDIRECT_URL', $PATHS[TARGET]['redirect_url']); // DEFINE('REDIRECT_URL', $PATHS[TARGET]['redirect_url']);
DEFINE('DEBUG', $DEBUG_FLAG[$HOST_NAME]);
DEFINE('SITE_LANG', $SITE_LANG[$HOST_NAME]);
DEFINE('SHOW_ALL_ERRORS', true); // show all errors if debug_all & show_error_handling are enabled // show all errors if debug_all & show_error_handling are enabled
DEFINE('SHOW_ALL_ERRORS', true);
/************* GENERAL PAGE TITLE ********/ /************* GENERAL PAGE TITLE ********/
DEFINE('G_TITLE', '<OVERALL FALLBACK PAGE TITLE>'); DEFINE('G_TITLE', '<OVERALL FALLBACK PAGE TITLE>');

View File

@@ -120,6 +120,7 @@ if (isset($AJAX_PAGE) && !$AJAX_PAGE) {
// if the lang folder is different to the default one // if the lang folder is different to the default one
// if the default lang is not like the lang given, switch lang // if the default lang is not like the lang given, switch lang
/** @phan-suppress-next-line PhanParamSuspiciousOrder */
if (false === strstr(BASE.INCLUDES.LANG.CONTENT_PATH, $cms->lang_dir) || if (false === strstr(BASE.INCLUDES.LANG.CONTENT_PATH, $cms->lang_dir) ||
strcasecmp(defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG, $lang) strcasecmp(defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG, $lang)
) { ) {

View File

@@ -62,7 +62,7 @@ namespace CoreLibs\ACL;
class Login extends \CoreLibs\DB\IO class Login extends \CoreLibs\DB\IO
{ {
private $euid; // the user id var private $euid; // the user id var
private $permission_okay = 0; // is set to one if login okay, or EUID is set and user is okay to access this page private $permission_okay = false; // is set to one if login okay, or EUID is set and user is okay to access this page
public $login; // pressed login public $login; // pressed login
private $action; // master action command private $action; // master action command
private $username; // login name private $username; // login name
@@ -109,11 +109,12 @@ class Login extends \CoreLibs\DB\IO
// language // language
public $l; public $l;
// METHOD: login /**
// PARAMS: db_config -> array for logging in to DB where edit_users tables are * constructor, does ALL, opens db, works through connection checks, closes itself
// db_debug -> sets debug output for db_io (can be overruled with DB_DEBUG) * @param array $db_config db config array
// RETURN: none * @param string $lang language string (default en_utf8)
// DESC : cunstroctuor, does ALL, opens db, works through connection checks, closes itself * @param int $set_control_flag class variable check flags
*/
public function __construct(array $db_config, string $lang = 'en_utf8', int $set_control_flag = 0) public function __construct(array $db_config, string $lang = 'en_utf8', int $set_control_flag = 0)
{ {
// log login data for this class only // log login data for this class only
@@ -149,11 +150,12 @@ class Login extends \CoreLibs\DB\IO
// if we have a search path we need to set it, to use the correct DB to login // if we have a search path we need to set it, to use the correct DB to login
// check what schema to use. if there is a login schema use this, else check if there is a schema set in the config, or fall back to DB_SCHEMA if this exists, if this also does not exists use public schema // check what schema to use. if there is a login schema use this, else check if there is a schema set in the config, or fall back to DB_SCHEMA if this exists, if this also does not exists use public schema
if (defined('LOGIN_DB_SCHEMA')) { if (defined('LOGIN_DB_SCHEMA')) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = LOGIN_DB_SCHEMA; $SCHEMA = LOGIN_DB_SCHEMA;
} elseif ($db_config['db_schema']) { } elseif ($db_config['db_schema']) {
$SCHEMA = $db_config['db_schema']; $SCHEMA = $db_config['db_schema'];
} elseif (defined('DB_SCHEMA')) { } elseif (defined('PUBLIC_SCHEMA')) {
$SCHEMA = DB_SCHEMA; $SCHEMA = PUBLIC_SCHEMA;
} else { } else {
$SCHEMA = 'public'; $SCHEMA = 'public';
} }
@@ -269,19 +271,20 @@ class Login extends \CoreLibs\DB\IO
$this->loginSetAcl(); $this->loginSetAcl();
} }
// METHOD: _login /**
// PARAMS: none * deconstructory, called with the last function to close DB connection
// RETURN: none */
// DESC : deconstructory, called with the last function to close DB connection
public function __destruct() public function __destruct()
{ {
parent::__destruct(); parent::__destruct();
} }
// METHOD: loginPasswordCheck /**
// PARAMS: hash, optional password, to override * checks if password is valid, sets internal error login variable
// RETURN: true or false * @param string $hash password hash
// DESC : checks if password is valid, sets internal error login variable * @param string $password submitted password
* @return bool true or false on password ok or not
*/
private function loginPasswordCheck(string $hash, string $password = ''): bool private function loginPasswordCheck(string $hash, string $password = ''): bool
{ {
// check with what kind of prefix the password begins: // check with what kind of prefix the password begins:
@@ -306,6 +309,7 @@ class Login extends \CoreLibs\DB\IO
(preg_match("/^\\$2(y)\\$/", $hash) && preg_match("/\\$07\\$/", $hash)) || (preg_match("/^\\$2(y)\\$/", $hash) && preg_match("/\\$07\\$/", $hash)) ||
preg_match("/^\\$1\\$/", $hash) || preg_match("/^\\$1\\$/", $hash) ||
preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash)) && preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash)) &&
/** @phan-suppress-next-line PhanDeprecatedFunction */
!$this->verifyCryptString($password, $hash) !$this->verifyCryptString($password, $hash)
) { ) {
// check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES // check passwword as crypted, $2a$ or $2y$ is blowfish start, $1$ is MD5 start, $\w{12} is standard DES
@@ -333,11 +337,10 @@ class Login extends \CoreLibs\DB\IO
return $password_ok; return $password_ok;
} }
// METHOD: loginLoginUser /**
// WAS : login_login_user * if user pressed login button this script is called, but only if there is no preview euid set]
// PARAMS: none * @return void has not return
// RETURN: none */
// DESC : if user pressed login button this script is called, but only if there is no preview euid set
private function loginLoginUser() private function loginLoginUser()
{ {
// have to get the global stuff here for setting it later // have to get the global stuff here for setting it later
@@ -568,16 +571,15 @@ class Login extends \CoreLibs\DB\IO
// if there was an login error, show login screen // if there was an login error, show login screen
if ($this->login_error) { if ($this->login_error) {
// reset the perm var, to confirm logout // reset the perm var, to confirm logout
$this->permission_okay = 0; $this->permission_okay = false;
} }
} // if he pressed login at least and is not yet loggined in } // if he pressed login at least and is not yet loggined in
} }
// METHOD: loginCheckPermissions /**
// WAS : login_check_permission * for every page the user access this script checks if he is allowed to do so
// PARAMS: none * @return bool permission okay as true/false
// RETUNR none */
// DESC : for every page the user access this script checks if he is allowed to do so
public function loginCheckPermissions() public function loginCheckPermissions()
{ {
if ($this->euid && $this->login_error != 103) { if ($this->euid && $this->login_error != 103) {
@@ -590,21 +592,20 @@ class Login extends \CoreLibs\DB\IO
// if (($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] || $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) && ini_get('memory_limit') != -1) // if (($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] || $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) && ini_get('memory_limit') != -1)
// ini_set('memory_limit', -1); // ini_set('memory_limit', -1);
if ($res['filename'] == $this->page_name) { if ($res['filename'] == $this->page_name) {
$this->permission_okay = 1; $this->permission_okay = true;
} else { } else {
$this->login_error = 103; $this->login_error = 103;
$this->permission_okay = 0; $this->permission_okay = false;
} }
} }
// if called from public, so we can check if the permissions are ok // if called from public, so we can check if the permissions are ok
return $this->permission_okay; return $this->permission_okay;
} }
// METHOD: loginLogoutUser /**
// WAS : login_logout_user * if a user pressed on logout, destroyes session and unsets all global vars
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : if a user pressed on logout, destroyes session and unsets all global vars
public function loginLogoutUser() public function loginLogoutUser()
{ {
if ($this->logout || $this->login_error) { if ($this->logout || $this->login_error) {
@@ -626,7 +627,7 @@ class Login extends \CoreLibs\DB\IO
unset($_SESSION['HEADER_COLOR']); unset($_SESSION['HEADER_COLOR']);
session_destroy(); session_destroy();
// then prints the login screen again // then prints the login screen again
$this->permission_okay = 0; $this->permission_okay = false;
} }
} }
@@ -648,6 +649,23 @@ class Login extends \CoreLibs\DB\IO
// * if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies // * if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies
// * if edit access ACL level is set, use this, else use page // * if edit access ACL level is set, use this, else use page
// set all base ACL levels as a list keyword -> ACL number // set all base ACL levels as a list keyword -> ACL number
/**
* sets all the basic ACLs
* init set the basic acl the user has, based on the following rules
* - init set from config DEFAULT ACL
* - if page ACL is set, it overrides the default ACL
* - if group ACL is set, it overrides the page ACL
* - if user ACL is set, it overrides the group ACL
* set the page ACL
* - default ACL set
* - set group ACL if not default overrides default ACL
* - set page ACL if not default overrides group ACL
* set edit access ACL and set default edit access group
* - if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies
* - if edit access ACL level is set, use this, else use page
* set all base ACL levels as a list keyword -> ACL number
* @return void has no return
*/
private function loginSetAcl() private function loginSetAcl()
{ {
// only set acl if we have permission okay // only set acl if we have permission okay
@@ -736,11 +754,11 @@ class Login extends \CoreLibs\DB\IO
} }
} }
// METHOD: loginCheckEditAccess /**
// WAS : login_check_edit_access * checks if this edit access id is valid
// PARAMS: edit_access_id to check * @param int $edit_access_id access id pk to check
// RETURN: true/false: if the edit access is not in the valid list: false * @return bool true/false: if the edit access is not in the valid list: false
// DESC : checks if this edit access id is valid */
public function loginCheckEditAccess($edit_access_id): bool public function loginCheckEditAccess($edit_access_id): bool
{ {
if (array_key_exists($edit_access_id, $this->acl['unit'])) { if (array_key_exists($edit_access_id, $this->acl['unit'])) {
@@ -750,10 +768,11 @@ class Login extends \CoreLibs\DB\IO
} }
} }
// METHOD: loginPasswordChangeValidPassword /**
// PARAMS: the new password * checks if the password is in a valid format
// RETURN: true or false * @param string $password the new password
// DESC : checks if the password is in a valid format * @return bool true or false if valid password or not
*/
private function loginPasswordChangeValidPassword($password) private function loginPasswordChangeValidPassword($password)
{ {
$is_valid_password = true; $is_valid_password = true;
@@ -772,19 +791,20 @@ class Login extends \CoreLibs\DB\IO
return $is_valid_password; return $is_valid_password;
} }
// METHOD: loginPasswordForgot /**
// PARAMS: none * dummy declare for password forget
// RETURN: none * @return void has no return
// DESC : dummy declare for password forget */
private function loginPasswordForgot() private function loginPasswordForgot()
{ {
// will do some password recovert, eg send email // will do some password recovert, eg send email
} }
// METHOD: loginSetPasswordMinLength /**
// PARAMS: set the minimum length * sets the minium length and checks on valid
// RETURN: true/false on success * @param int $length set the minimum length
// DESC : sets the minium length and checks on valid * @return bool true/false on success
*/
public function loginSetPasswordMinLength(int $length): bool public function loginSetPasswordMinLength(int $length): bool
{ {
// check that numeric, positive numeric, not longer than max input string lenght // check that numeric, positive numeric, not longer than max input string lenght
@@ -797,11 +817,10 @@ class Login extends \CoreLibs\DB\IO
} }
} }
// METHOD: loginPasswordChange /**
// WAS : login_password_change * changes a user password
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : changes a user password
private function loginPasswordChange() private function loginPasswordChange()
{ {
if ($this->change_password) { if ($this->change_password) {
@@ -867,7 +886,7 @@ class Login extends \CoreLibs\DB\IO
} }
} else { } else {
// illegal user error // illegal user error
$this->login_error = '220'; $this->login_error = 220;
$data = 'Illegal user for password change: '.$this->pw_username; $data = 'Illegal user for password change: '.$this->pw_username;
} }
// log this password change attempt // log this password change attempt
@@ -875,13 +894,13 @@ class Login extends \CoreLibs\DB\IO
} // button pressed } // button pressed
} }
// METHOD: loginPrintLogin /**
// WAS : login_print_login * prints out login html part if no permission (error) is set
// PARAMS: none * @return ?string html data for login page, or null for nothing
// RETURN: html data for login page */
// DESC : prints out login html part if no permission (error) is set
private function loginPrintLogin() private function loginPrintLogin()
{ {
$html_string = null;
if (!$this->permission_okay) { if (!$this->permission_okay) {
// get global AJAX page trigger // get global AJAX page trigger
// if true, return error ajax // if true, return error ajax
@@ -954,17 +973,17 @@ class Login extends \CoreLibs\DB\IO
$html_string = str_replace('{'.$string.'}', $data, $html_string); $html_string = str_replace('{'.$string.'}', $data, $html_string);
} }
} }
// return the created HTML here
return $html_string;
} // if permission is 0 then print out login } // if permission is 0 then print out login
// return the created HTML here or null for nothing
return $html_string;
} }
// METHOD: loginCloseClass /**
// WAS : login_close_class * last function called, writes log and prints out error msg and
// PARAMS: none * exists script if permission 0
// RETURN: true on permission ok, false on permission wrong * @return bool true on permission ok, false on permission wrong
// DESC : last function called, writes log and prints out error msg and exists script if permission 0 */
private function loginCloseClass() private function loginCloseClass(): bool
{ {
// write to LOG table ... // write to LOG table ...
if ($this->login_error || $this->login || $this->logout) { if ($this->login_error || $this->login || $this->logout) {
@@ -995,11 +1014,10 @@ class Login extends \CoreLibs\DB\IO
} }
} }
// METHOD: loginSetTemplates /**
// WAS : login_set_templates * checks if there are external templates, if not uses internal fallback ones
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : checks if there are external templates, if not uses internal fallback ones
private function loginSetTemplates() private function loginSetTemplates()
{ {
$strings = array ( $strings = array (
@@ -1151,14 +1169,15 @@ EOM;
} }
} }
// METHOD: writeLog /**
// WAS : write_log * writes detailed data into the edit user log table (keep log what user does)
// PARAMS: event -> string of what has been done * @param string $event string of what has been done
// data -> data information (id, etc) * @param string $data data information (id, etc)
// error -> if error, write error string (not enougth data, etc) * @param string|int $error error id (mostly an int)
// RETURN: none * @param string $username login user username
// DESC : writes detailed data into the edit user log table (keep log what user does) * @return void has no return
private function writeLog($event, $data, $error = '', $username = '') */
private function writeLog(string $event, string $data, $error = '', string $username = '')
{ {
if ($this->login) { if ($this->login) {
$this->action = 'Login'; $this->action = 'Login';
@@ -1202,12 +1221,12 @@ EOM;
$this->dbExec($q, 'NULL'); $this->dbExec($q, 'NULL');
} }
// METHOD: loginCheckEditAccessId /**
// WAS : login_check_edit_access_id *checks that the given edit access id is valid for this user
// PARAMS: edit access id to check * @param int $edit_access_id edit access id to check
// RETURN: same edit access id if ok, or the default edit access id if given one is not valud * @return int same edit access id if ok, or the default edit access id if given one is not valid
// DESC : checks that the given edit access id is valid for this user */
public function loginCheckEditAccessId($edit_access_id) public function loginCheckEditAccessId(int $edit_access_id)
{ {
if (!array_key_exists($edit_access_id, $_SESSION["UNIT"])) { if (!array_key_exists($edit_access_id, $_SESSION["UNIT"])) {
return $_SESSION["UNIT_DEFAULT"]; return $_SESSION["UNIT_DEFAULT"];
@@ -1216,12 +1235,13 @@ EOM;
} }
} }
// METHOD: loginSetEditAccessData /**
// WAS : login_set_edit_access_data * [loginSetEditAccessData description]
// PARAMS: edit access id, key value to search for * @param int $edit_access_id edit access id
// RETURN: false for not found or string for found data * @param string|int $data_key key value to search for
// DESC : searchs in the data set for the unit for the data key and returns the value asociated with it * @return bool|string false for not found or string for found data
public function loginSetEditAccessData($edit_access_id, $data_key) */
public function loginSetEditAccessData(int $edit_access_id, $data_key)
{ {
if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key]) { if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key]) {
return false; return false;

View File

@@ -81,10 +81,12 @@ class Backend extends \CoreLibs\DB\IO
public $l; public $l;
// CONSTRUCTOR / DECONSTRUCTOR |====================================> // CONSTRUCTOR / DECONSTRUCTOR |====================================>
// METHOD: __construct /**
// PARAMS: array db config * main class constructor
// string for language set * @param array $db_config db config array
// int set control flag (for core basic set/get var error control) * @param string $lang language string
* @param int|integer $set_control_flag class variable check flag
*/
public function __construct(array $db_config, string $lang, int $set_control_flag = 0) public function __construct(array $db_config, string $lang, int $set_control_flag = 0)
{ {
// get the language sub class & init it // get the language sub class & init it
@@ -106,7 +108,9 @@ class Backend extends \CoreLibs\DB\IO
} }
} }
// deconstructor /**
* class deconstructor
*/
public function __destruct() public function __destruct()
{ {
parent::__destruct(); parent::__destruct();
@@ -117,12 +121,14 @@ class Backend extends \CoreLibs\DB\IO
// PUBLIC METHODS |=================================================> // PUBLIC METHODS |=================================================>
// METHOD: adbEditLog() /**
// PARAMS: event -> any kind of event description, * writes all action vars plus other info into edit_log tabl
// data -> any kind of data related to that event * @param string $event any kind of event description,
// RETURN: none * @param string|array $data any kind of data related to that event
// DESC : writes all action vars plus other info into edit_log table * @param string $write_type write type can bei STRING or BINARY
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING') * @return void has no return
*/
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING'): void
{ {
$data_binary = ''; $data_binary = '';
if ($write_type == 'BINARY') { if ($write_type == 'BINARY') {
@@ -134,7 +140,19 @@ class Backend extends \CoreLibs\DB\IO
$data = $this->dbEscapeString(serialize($data)); $data = $this->dbEscapeString(serialize($data));
} }
$q = "INSERT INTO ".LOGIN_DB_SCHEMA.".edit_log "; // check schema
if (defined('LOGIN_DB_SCHEMA')) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = LOGIN_DB_SCHEMA;
} elseif ($this->dbGetSchema()) {
$SCHEMA = $this->dbGetSchema();
} elseif (defined('PUBLIC_SCHEMA')) {
$SCHEMA = PUBLIC_SCHEMA;
} else {
$SCHEMA = 'public';
}
$q = "INSERT INTO ".$SCHEMA.".edit_log ";
$q .= "(euid, event_date, event, data, data_binary, page, "; $q .= "(euid, event_date, event, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, "; $q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "; $q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
@@ -163,10 +181,11 @@ class Backend extends \CoreLibs\DB\IO
$this->dbExec($q, 'NULL'); $this->dbExec($q, 'NULL');
} }
// METHOD: adbTopMenu /**
// PARAMS: level * menu creater (from login menu session pages)
// RETURN: returns an array for the top menu with all correct settings * @param int $flag visible flag trigger
// DESC : menu creater * @return array menu array for output on page (smarty)
*/
public function adbTopMenu(int $flag = 0): array public function adbTopMenu(int $flag = 0): array
{ {
if ($this->menu_show_flag) { if ($this->menu_show_flag) {
@@ -255,10 +274,11 @@ class Backend extends \CoreLibs\DB\IO
return $this->menu; return $this->menu;
} }
// METHOD: adbShowMenuPoint /**
// PARAMS: filename * checks if this filename is in the current situation (user id, etc) available
// RETURN: returns boolean true/false * @param string $filename filename
// DESC : checks if this filename is in the current situation (user id, etc) available * @return bool true for visible/accessable menu point, false for not
*/
public function adbShowMenuPoint(string $filename): bool public function adbShowMenuPoint(string $filename): bool
{ {
$enabled = false; $enabled = false;
@@ -270,50 +290,56 @@ class Backend extends \CoreLibs\DB\IO
return $enabled; return $enabled;
} }
// REMARK: below function has moved to "Class.Basic" /**
// METHOD: adbAssocArray * @deprecated
// PARAMS: db array, key, value part * creates out of a normal db_return array an assoc array
// RETURN: returns and associative array * @param array $db_array input array
// DESC : creates out of a normal db_return array an assoc array * @param string|int|bool $key key
* @param string|int|bool $value value
* @return array associative array
*/
public function adbAssocArray(array $db_array, $key, $value): array public function adbAssocArray(array $db_array, $key, $value): array
{ {
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->genAssocArray($db_array, $key, $value); return $this->genAssocArray($db_array, $key, $value);
} }
// REMARK: below function has moved to "Class.Basic" /**
// METHOD: adbByteStringFormat * @deprecated
// PARAMS: int * converts bytes into formated string with KB, MB, etc
// RETURN: string * @param string|int|float $number string or int or number
// DESC : converts bytes into formated string with KB, MB, etc * @return string formatted string
*/
public function adbByteStringFormat($number): string public function adbByteStringFormat($number): string
{ {
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->byteStringFormat($number); return $this->byteStringFormat($number);
} }
// REMARK: below function has moved to "Class.Basic" /**
// METHOD: adbCreateThumbnail * @deprecated
// PARAMS: id from picture where from we create a thumbnail * converts picture to a thumbnail with max x and max y size
// x -> max x size of thumbnail * @param string $pic source image file with or without path
// y -> max y size of thumbnail * @param int $size_x maximum size width
// dummy -> if set to true, then if no images was found we show a dummy image * @param int $size_y maximum size height
// path -> if source start is not ROOT path, if empty ROOT is choosen * @param string $dummy empty, or file_type to show an icon instead of nothing if file is not found
// cache -> cache path, if not given TMP is used * @param string $path if source start is not ROOT path, if empty ROOT is choosen
// RETURN: thumbnail name * @param string $cache_source cache path, if not given TMP is used
// DESC : converts picture to a thumbnail with max x and max y size * @return string|bool thumbnail name, or false for error
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "") */
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = '', $path = "", $cache = "")
{ {
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache); return $this->createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
} }
// METHOD: adbMsg /**
// PARAMS: level -> info/warning/error * wrapper function to fill up the mssages array
// msg -> string, can be printf formated * @param string $level info/warning/error
// var array -> optional data for a possible printf formated msg * @param string $msg string, can be printf formated
// RETURN: none * @param array $vars optional data for a possible printf formated msg
// DESC : wrapper function to fill up the mssages array * @return void has no return
*/
public function adbMsg(string $level, string $msg, array $vars = array ()): void public function adbMsg(string $level, string $msg, array $vars = array ()): void
{ {
if (!preg_match("/^info|warning|error$/", $level)) { if (!preg_match("/^info|warning|error$/", $level)) {
@@ -336,28 +362,39 @@ class Backend extends \CoreLibs\DB\IO
} }
} }
// METHOD: adbLiveQueue /**
// PARAMS: queue_key -> string to identfy the queue * writes live queue
// type -> INSERT/UPDATE/DELETE * @param string $queue_key string to identfy the queue
// target -> target table to write to * @param string $type [description]
// data -> SQL part to write, this can include #KEY_VALUE#, #KEY_NAME# for delete sub queries * @param string $target [description]
// key_name -> key name, mostly used for update search * @param string $data [description]
// key_value -> data for the key * @param string $key_name [description]
// associate -> NULL for free, LOCK for first insert, group key for reference to first entry * @param string $key_value [description]
// file -> string for special file copy actions; mostyle "test#live;..." * @param ?string $associate [description]
// RETURN: none * @param ?string $file [description]
// DESC : writes live queue * @return void has no return
*/
public function adbLiveQueue( public function adbLiveQueue(
$queue_key, string $queue_key,
$type, string $type,
$target, string $target,
$data, string $data,
$key_name, string $key_name,
$key_value, string $key_value,
$associate = null, string $associate = null,
$file = null string $file = null
) { ): void {
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue ("; if (defined('GLOBAL_DB_SCHEMA')) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = GLOBAL_DB_SCHEMA;
} elseif ($this->dbGetSchema()) {
$SCHEMA = $this->dbGetSchema();
} elseif (defined('PUBLIC_SCHEMA')) {
$SCHEMA = PUBLIC_SCHEMA;
} else {
$SCHEMA = 'public';
}
$q = "INSERT INTO ".$SCHEMA.".live_queue (";
$q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file"; $q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file";
$q .= ") VALUES ("; $q .= ") VALUES (";
$q .= "'".$this->dbEscapeString($queue_key)."', '".$this->dbEscapeString($key_value)."', "; $q .= "'".$this->dbEscapeString($queue_key)."', '".$this->dbEscapeString($key_value)."', ";
@@ -365,21 +402,24 @@ class Backend extends \CoreLibs\DB\IO
$q .= "'".$this->dbEscapeString($target)."', '".$this->dbEscapeString($data)."', "; $q .= "'".$this->dbEscapeString($target)."', '".$this->dbEscapeString($data)."', ";
$q .= "'".$this->queue_key."', '".$this->action."', '".$this->dbEscapeString($associate)."', "; $q .= "'".$this->queue_key."', '".$this->action."', '".$this->dbEscapeString($associate)."', ";
$q .= "'".$this->dbEscapeString($file)."')"; $q .= "'".$this->dbEscapeString($file)."')";
$this->db_exec($q); $this->dbExec($q);
} }
// METHOD: adbPrintDateTime /**
// PARAMS: year, month, day, hour, min: the date and time values * Basic class holds exact the same, except the Year/Month/Day/etc strings
// suffix: additional info printed after the date time variable in the drop down, * are translated in this call
// also used for ID in the on change JS call * @param int $year year YYYY
// minute steps: can be 1 (default), 5, 10, etc, if invalid (outside 1h range, * @param int $month month m
// it falls back to 1min) * @param int $day day d
// name pos back: default false, if set to true, the name will be printend * @param int $hour hour H
// after the drop down and not before the drop down * @param int $min min i
// RETURN: HTML formated strings for drop down lists of date and time * @param string $suffix additional info printed after the date time variable in the drop down
// DESC : print the date/time drop downs, used in any queue/send/insert at date/time place * also used for ID in the on change JS call
// NOTE : Basic class holds exact the same, except the Year/Month/Day/etc strings * @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
// are translated in this call * @param bool $name_pos_back default false, if set to true, the name will be printend
* after the drop down and not before the drop down
* @return string HTML formated strings for drop down lists of date and time
*/
public function adbPrintDateTime( public function adbPrintDateTime(
$year, $year,
$month, $month,

File diff suppressed because it is too large Load Diff

View File

@@ -48,14 +48,14 @@ class ArrayIO extends \CoreLibs\DB\IO
public $pk_name; // the primary key from this table public $pk_name; // the primary key from this table
public $pk_id; // the PK id public $pk_id; // the PK id
// METHOD: db_array_io /**
// PARAMS: db_config -> db_io class init vars * constructor for the array io class, set the
// table_array -> the array from the table * primary key name automatically (from array)
// table_name -> name of the table (for the array) * @param array $db_config db connection config
// set_control_flag -> set basic class set/get variable error flags * @param array $table_array table array config
// RETURN: none * @param string $table_name table name string
// DESC : constructor for the array io class, set the * @param int|integer $set_control_flag set basic class set/get variable error flags
// primary key name automatically (from array) */
public function __construct(array $db_config, array $table_array, string $table_name, int $set_control_flag = 0) public function __construct(array $db_config, array $table_array, string $table_name, int $set_control_flag = 0)
{ {
// instance db_io class // instance db_io class
@@ -77,21 +77,23 @@ class ArrayIO extends \CoreLibs\DB\IO
} // set pk_name IF table_array was given } // set pk_name IF table_array was given
} }
// deconstruktor /**
* class deconstructor
*/
public function __destruct() public function __destruct()
{ {
parent::__destruct(); parent::__destruct();
} }
// METHOD: convertData /**
// WAS : convert_data * changes all previously alterd HTML code into visible one,
// PARAMS: string -> the string that should be changed * works for <b>,<i>, and <a> (thought <a> can be / or should
// RETURN: string -> the altered string * be handled with the magic links functions
// DESC : changes all previously alterd HTML code into visible one, * used with the read function
// works for <b>,<i>, and <a> (thought <a> can be / or should * @param string $text any html encoded string
// be handled with the magic links functions * @return string decoded html string
// used with the read function */
public function convertData($text) public function convertData($text): string
{ {
$text = str_replace('&lt;b&gt;', '<b>', $text); $text = str_replace('&lt;b&gt;', '<b>', $text);
$text = str_replace('&lt;/b&gt;', '</b>', $text); $text = str_replace('&lt;/b&gt;', '</b>', $text);
@@ -109,7 +111,12 @@ class ArrayIO extends \CoreLibs\DB\IO
// PARAMS: string -> string to be changed // PARAMS: string -> string to be changed
// RETURN: string -> altered string // RETURN: string -> altered string
// DESC : changeds all HTML entities into non HTML ones // DESC : changeds all HTML entities into non HTML ones
public function convertEntities($text) /**
* changeds all HTML entities into non HTML ones
* @param string $text encoded html string
* @return string decoded html string
*/
public function convertEntities($text): string
{ {
$text = str_replace('&lt;', '<', $text); $text = str_replace('&lt;', '<', $text);
$text = str_replace('&gt;', '>', $text); $text = str_replace('&gt;', '>', $text);
@@ -119,12 +126,12 @@ class ArrayIO extends \CoreLibs\DB\IO
return $text; return $text;
} }
// METHOD: dbDumpArray /**
// WAS : db_dump_array * dumps the current data
// PARAMS: none * @param bool $write write to error message, default false
// RETURN: returns the current array * @return string the array data as html string entry
// DESC : dumps the current data */
public function dbDumpArray($write = 0) public function dbDumpArray($write = false): string
{ {
reset($this->table_array); reset($this->table_array);
$string = ''; $string = '';
@@ -132,17 +139,16 @@ class ArrayIO extends \CoreLibs\DB\IO
$string .= '<b>'.$column.'</b> -> '.$data_array['value'].'<br>'; $string .= '<b>'.$column.'</b> -> '.$data_array['value'].'<br>';
} }
// add output to internal error_msg // add output to internal error_msg
if ($write) { if ($write === true) {
$this->error_msg['db'] .= $string; $this->error_msg['db'] .= $string;
} }
return $string; return $string;
} }
// METHOD: dbCheckPkSet /**
// WAS : db_check_pk_set * checks if pk is set and if not, set from pk_id and if this also not set return 0
// PARAMS: none * @return bool true if pk value is set, else false
// RETURN: none */
// DESC : checks if pk is set and if not, set from pk_id and if this also not set return 0
public function dbCheckPkSet() public function dbCheckPkSet()
{ {
// if pk_id is set, overrule ... // if pk_id is set, overrule ...
@@ -154,18 +160,18 @@ class ArrayIO extends \CoreLibs\DB\IO
// if no PK found, error ... // if no PK found, error ...
$this->error_id = 91; $this->error_id = 91;
$this->__dbError(); $this->__dbError();
return 0; return false;
} else { } else {
return 1; return true;
} }
} }
// METHOD: dbResetArray /**
// WAS : db_reset_array * resets the whole array values
// PARAMS: reset_pk -> if set reset the pk too * @param boolean $reset_pk true if we want to reset the pk too
// RETURN: none * @return void has no return
// DESC : resets the whole array */
public function dbResetArray($reset_pk = 0) public function dbResetArray($reset_pk = false): void
{ {
reset($this->table_array); reset($this->table_array);
foreach ($this->table_array as $column => $data_array) { foreach ($this->table_array as $column => $data_array) {
@@ -177,14 +183,16 @@ class ArrayIO extends \CoreLibs\DB\IO
} }
} }
// METHOD: dbDelete /**
// WAS : db_delete * deletes one dataset
// PARAMS: optional the table_array, if not given uses class var * @param array $table_array optional override for table array set
// RETURN: 1 for successfull delete or 0 for error * set this as new table array too
// DESC : deletes one dataset * @return array returns the table array that was deleted
public function dbDelete($table_array = 0) */
public function dbDelete($table_array = array ())
{ {
if (is_array($table_array)) { // is array and has values, override set and set new
if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array; $this->table_array = $table_array;
} }
if (!$this->dbCheckPkSet()) { if (!$this->dbCheckPkSet()) {
@@ -234,15 +242,16 @@ class ArrayIO extends \CoreLibs\DB\IO
return $this->table_array; return $this->table_array;
} }
// METHOD: dbRead /**
// WAS : db_read * reads one row into the array
// PARAMS: edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var * @param boolean $edit on true convert data, else as is
// RETURN: true or false for reading * @param array $table_array optional table array, overwrites internal set array
// DESC : reads one row into the array * @return array set table array with values
public function dbRead($edit = 0, $table_array = 0) */
public function dbRead($edit = false, $table_array = array ())
{ {
// if array give, overrules internal array // if array give, overrules internal array
if (is_array($table_array)) { if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array; $this->table_array = $table_array;
} }
if (!$this->dbCheckPkSet()) { if (!$this->dbCheckPkSet()) {
@@ -280,7 +289,7 @@ class ArrayIO extends \CoreLibs\DB\IO
if ($res = $this->dbFetchArray()) { if ($res = $this->dbFetchArray()) {
reset($this->table_array); reset($this->table_array);
foreach ($this->table_array as $column => $data_array) { foreach ($this->table_array as $column => $data_array) {
// wenn "edit" dann gib daten wie in DB zurck, ansonten aufbereiten fr ausgabe // wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten fr ausgabe
// ?? sollte das nicht drauen ??? man weis ja net was da drin steht --> is noch zu berlegen // ?? sollte das nicht drauen ??? man weis ja net was da drin steht --> is noch zu berlegen
// echo 'EDIT: $edit | Spalte: $column | type: '.$this->table_array[$column]['type'].' | Res: '.$res[$column].'<br>'; // echo 'EDIT: $edit | Spalte: $column | type: '.$this->table_array[$column]['type'].' | Res: '.$res[$column].'<br>';
if ($edit) { if ($edit) {
@@ -306,14 +315,15 @@ class ArrayIO extends \CoreLibs\DB\IO
return $this->table_array; return $this->table_array;
} }
// METHOD: dbWrite /**
// WAS : db_write * writes one set into DB or updates one set (if PK exists)
// PARAMS: addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var * @param boolean $addslashes old convert entities and set set escape
// RETURN: true or false on write * @param array $table_array optional table array, overwrites internal one
// DESC : writes on set into DB or updates one set (if PK exists) * @return array table array or null
public function dbWrite($addslashes = 0, $table_array = 0) */
public function dbWrite($addslashes = false, $table_array = array ())
{ {
if (is_array($table_array)) { if (is_array($table_array) && count($table_array)) {
$this->table_array = $table_array; $this->table_array = $table_array;
} }
// PK ID check // PK ID check
@@ -524,68 +534,6 @@ class ArrayIO extends \CoreLibs\DB\IO
// return the table if needed // return the table if needed
return $this->table_array; return $this->table_array;
} }
// *************************************************************
// COMPATIBILITY METHODS
// those methods are deprecated function call names
// they exist for backwards compatibility only
// *************************************************************
public function convert_data($text)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->convertData($text);
}
public function convert_entities($text)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->convertEntities($text);
}
public function db_dump_array($write = 0)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbDumpArray($write);
}
public function db_check_pk_set()
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbCheckPkSet();
}
public function db_reset_array($reset_pk = 0)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbResetArray($reset_pk);
}
public function db_delete($table_array = 0)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbDelete($table_array);
}
public function db_read($edit = 0, $table_array = 0)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbRead($edit, $table_array);
}
public function db_write($addslashes = 0, $table_array = 0)
{
error_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->dbWrite($addslashes, $table_array);
}
} // end of class } // end of class
// __END__ // __END__

File diff suppressed because it is too large Load Diff

View File

@@ -48,19 +48,17 @@ class PgSQL
private $last_error_query; private $last_error_query;
private $dbh; private $dbh;
// METHOD: __construct /**
// PARAMS: none * class constructor, empty does nothing
// RETURN: none */
// DESC : class constructor
public function __construct() public function __construct()
{ {
} }
// METHOD: __dbLastErrorQuery /**
// WAS : _db_last_error_query * queries last error query and returns true or false if error was set
// PARAMS: none * @return bool true/false if last error is set
// RETURN: true/false if last error is set */
// DESC : queries last error query and returns true or false if error was set
public function __dbLastErrorQuery() public function __dbLastErrorQuery()
{ {
if ($this->last_error_query) { if ($this->last_error_query) {
@@ -70,12 +68,12 @@ class PgSQL
} }
} }
// METHOD: __dbQuery /**
// WAS : _db_query * wrapper for gp_query, catches error and stores it in class var
// PARAMS: query * @param string $query query string
// RETURN: query result * @return resource|bool query result
// DESC : wrapper for gp_query, catches error and stores it in class var */
public function __dbQuery($query) public function __dbQuery(string $query)
{ {
$this->last_error_query = ''; $this->last_error_query = '';
// read out the query status and save the query if needed // read out the query status and save the query if needed
@@ -86,21 +84,20 @@ class PgSQL
return $result; return $result;
} }
// METHOD: __dbSendQuery /**
// WAS : _db_send_query * sends an async query to the server
// PARAMS: query * @param string $query query string
// RETURN: true/false if query was sent successful * @return bool true/false if query was sent successful
// DESC : sends an async query to the server */
public function __dbSendQuery($query) public function __dbSendQuery(string $query): bool
{ {
return pg_send_query($this->dbh, $query); return pg_send_query($this->dbh, $query);
} }
// METHOD: __dbGetResult /**
// WAS : _db_get_result * wrapper for pg_get_result
// PARAMS: none * @return resource|bool resource handler or false for error
// RETURN: resource handler */
// DESC : wrapper for pg_get_result
public function __dbGetResult() public function __dbGetResult()
{ {
$this->last_error_query = ''; $this->last_error_query = '';
@@ -111,12 +108,11 @@ class PgSQL
return $result; return $result;
} }
// METHOD: __dbClose /**
// WAS : _db_close * wrapper for pg_close
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : wrapper for pg_close public function __dbClose(): void
public function __dbClose()
{ {
if (is_resource($this->dbh)) { if (is_resource($this->dbh)) {
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) { if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
@@ -125,12 +121,13 @@ class PgSQL
} }
} }
// METHOD: __dbPrepare /**
// WAS : _db_prepare * wrapper for pg_prepare
// PARAMS: prepare name, query * @param string $name statement name
// RETURN: prepared statement handler * @param string $query query string
// DESC : wrapper for pg_prepare * @return resource|bool prepare statement handler or false for error
public function __dbPrepare($name, $query) */
public function __dbPrepare(string $name, string $query)
{ {
$result = pg_prepare($this->dbh, $name, $query); $result = pg_prepare($this->dbh, $name, $query);
if (!$result) { if (!$result) {
@@ -139,12 +136,13 @@ class PgSQL
return $result; return $result;
} }
// METHOD: __dbExecute /**
// WAS : _db_execute * wrapper for pg_execute for running a prepared statement
// PARAMS: prepare name, data for query * @param string $name statement name
// RETURN: returns status * @param array $data data array
// DESC : wrapper for pg_execute for running a prepared statement * @return resource|bool returns status or false for error
public function __dbExecute($name, $data) */
public function __dbExecute(string $name, array $data)
{ {
$result = pg_execute($this->dbh, $name, $data); $result = pg_execute($this->dbh, $name, $data);
if (!$result) { if (!$result) {
@@ -153,95 +151,94 @@ class PgSQL
return $result; return $result;
} }
// METHOD: __dbNumRows /**
// WAS : _db_num_rows * wrapper for pg_num_rows
// PARAMS: cursor * @param resource $cursor cursor resource
// RETURN: rows * @return int number of rows, -1 on error
// DESC : wrapper for pg_num_rows */
public function __dbNumRows($cursor) public function __dbNumRows($cursor): int
{ {
return pg_num_rows($cursor); return pg_num_rows($cursor);
} }
// METHOD: __dbNumFields /**
// WAS : _db_num_fields * wrapper for pg_num_fields
// PARAMS: cursor * @param resource $cursor cursor resource
// RETURN: number for fields in query * @return int number for fields in result, -1 on error
// DESC : wrapper for pg_num_fields */
public function __dbNumFields($cursor) public function __dbNumFields($cursor): int
{ {
return pg_num_fields($cursor); return pg_num_fields($cursor);
} }
// METHOD: __dbFieldName /**
// WAS : _db_field_name * wrapper for pg_field_name
// PARAMS: cursor, field position * @param resource $cursor cursor resource
// RETURN: name of field * @param int $i field position
// DESC : wrapper for pg_field_name * @return string|bool name or false on error
*/
public function __dbFieldName($cursor, $i) public function __dbFieldName($cursor, $i)
{ {
return pg_field_name($cursor, $i); return pg_field_name($cursor, $i);
} }
// METHOD: __dbFetchArray /**
// WAS : _db_fetch_array * wrapper for pg_fetch_array
// PARAMS: cursor, opt result type * if through/true false, use __dbResultType(true)
// RETURN: row * @param resource $cursor cursor resource
// DESC : wrapper for pg_fetch_array * @param int $result_type result type as int number
public function __dbFetchArray($cursor, $result_type = '') * @return array|bool array result data or false on end/error
*/
public function __dbFetchArray($cursor, int $result_type = PGSQL_BOTH)
{ {
if ($result_type == true) {
$result_type = PGSQL_ASSOC;
}
// result type is passed on as is [should be checked] // result type is passed on as is [should be checked]
if ($result_type) { return pg_fetch_array($cursor, null, $result_type);
return pg_fetch_array($cursor, null, $result_type);
} else {
return pg_fetch_array($cursor);
}
} }
// METHOD: __dbResultType /**
// PARAMS: true/false for ASSOC only or BOTH * simple match up between assoc true/false
// RETURN: PGSQL assoc type * @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
// DESC : simple match up between assoc true/false * @return int valid result type for fetch array
public function __dbResultType($assoc_type) */
public function __dbResultType(bool $assoc_type = true): int
{ {
if ($assoc_type == true) { if ($assoc_type == true) {
return PGSQL_ASSOC; return PGSQL_ASSOC;
} }
return ''; // fallback to default // fallback to default
return PGSQL_BOTH;
} }
// METHOD: __dbFetchAll /**
// WAS : _db_fetch_all * wrapper for pg_fetch_all
// PARAMS: cursor * @param resource $cursor cursor resource
// RETURN: all rows as array * @return array|bool data array or false for end/error
// DESC : wrapper for pg_fetch_array */
public function __dbFetchAll($cursor) public function __dbFetchAll($cursor)
{ {
return pg_fetch_all($cursor); return pg_fetch_all($cursor);
} }
// METHOD: __dbAffectedRows /**
// WAS : _db_affected_rows * wrapper for pg_affected_rows
// PARAMS: cursor * @param resource $cursor cursor resource
// RETURN: number for rows * @return int affected rows, 0 for none
// DESC : wrapper for pg_affected_rows */
public function __dbAffectedRows($cursor) public function __dbAffectedRows($cursor): int
{ {
return pg_affected_rows($cursor); return pg_affected_rows($cursor);
} }
// METHOD: __dbInsertId /**
// WAS : _db_insert_id * reads the last inserted primary key for the query
// PARAMS: query, primary key name * if there is no pk_name tries to auto built it from the table name
// RETURN: last insert primary key * this only works if db schema is after "no plural names. and pk name is table name + _id
// DESC : reads the last inserted primary key for the query * detects schema prefix in table name
// if ther is no pk_name tries to auto built it from the table name * @param string $query query string
// this only works if db schema is after "no plural names. and pk name is table name + _id * @param string $pk_name primary key name, if '' then auto detect
// detects schema prefix in table name * @return string|int primary key value
public function __dbInsertId($query, $pk_name) */
public function __dbInsertId(string $query, string $pk_name)
{ {
// only if an insert has been done // only if an insert has been done
if (preg_match("/^insert /i", $query)) { if (preg_match("/^insert /i", $query)) {
@@ -275,12 +272,13 @@ class PgSQL
} }
} }
// METHOD: __dbPrimaryKey /**
// WAS : _db_primary_key * queries database for the primary key name to this table in the selected schema
// PARAMS: table and optional schema * @param string $table table name
// RETURN: primary key name OR false if not possible * @param string $schema optional schema name, '' for default
// DESC : queries database for the primary key name to this table in the selected schema * @return string|bool primary key name or false if not found
public function __dbPrimaryKey($table, $schema = '') */
public function __dbPrimaryKey(string $table, string $schema = '')
{ {
if ($table) { if ($table) {
// check if schema set is different from schema given, only needed if schema is not empty // check if schema set is different from schema given, only needed if schema is not empty
@@ -322,12 +320,17 @@ class PgSQL
} }
} }
// METHOD: __dbConnect /**
// WAS : _db_connect * wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow) * @param string $db_host host name
// RETURN: database handler * @param string $db_user user name
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var) * @param string $db_pass password
public function __dbConnect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow') * @param string $db_name databse name
* @param integer $db_port port (int, 5432 is default)
* @param string $db_ssl SSL (allow is default)
* @return ?resource db handler resource or null on error
*/
public function __dbConnect(string $db_host, string $db_user, string $db_pass, string $db_name, int $db_port = 5432, string $db_ssl = 'allow')
{ {
// to avoid empty db_port // to avoid empty db_port
if (!$db_port) { if (!$db_port) {
@@ -336,16 +339,18 @@ class PgSQL
$this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl); $this->dbh = pg_connect("host=".$db_host." port=".$db_port." user=".$db_user." password=".$db_pass." dbname=".$db_name." sslmode=".$db_ssl);
if (!$this->dbh) { if (!$this->dbh) {
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->"); die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."] //-->");
return null;
} }
return $this->dbh; return $this->dbh;
} }
// METHOD: __dbPrintError /**
// WAS : _db_print_error * reads the last error for this cursor and returns
// PARAMS: database handler, cursor * html formatted string with error name
// RETURN: error string (HTML) * @param ?resource $cursor cursor resource or null
// DESC : reads the last error for this cursor * @return string error string
public function __dbPrintError($cursor = '') */
public function __dbPrintError($cursor = null): string
{ {
// run the query again for the error result here // run the query again for the error result here
if (!$cursor && $this->last_error_query) { if (!$cursor && $this->last_error_query) {
@@ -355,56 +360,71 @@ class PgSQL
} }
if (pg_result_error($cursor)) { if (pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>"; return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
} else {
return '';
} }
} }
// METHOD: __dbMetaData /**
// WAS : _db_meta_data * wrapper for pg_meta_data
// PARAMS: table name * @param string $table table name
// RETURN: array with table data * @param bool $extended show extended info (default false)
// DESC : wrapper for pg_emta_data * @return array|bool array data for the table info or false on error
public function __dbMetaData($table) */
public function __dbMetaData(string $table, $extended = false)
{ {
// needs to prefixed with @ or it throws a warning on not existing table // needs to prefixed with @ or it throws a warning on not existing table
return @pg_meta_data($this->dbh, $table); return @pg_meta_data($this->dbh, $table, $extended);
} }
// METHOD: __dbEscapeString /**
// WAS : _db_escape_string * wrapper for pg_escape_string
// PARAMS: string * @param string|int|float|bool $string any string/int/float/bool
// RETURN: escaped string for postgres * @return string excaped string
// DESC : wrapper for pg_escape_string */
public function __dbEscapeString($string) public function __dbEscapeString($string): string
{ {
return pg_escape_string($this->dbh, (string)$string); return pg_escape_string($this->dbh, (string)$string);
} }
// METHOD: __dbEscapeBytea /**
// WAS : _db_escape_bytea * wrapper for pg_escape_literal
// PARAMS: string * difference to escape string is that this one adds quotes ('') around
// RETURN: escape bytes for postgres * the string too
// DESC : wrapper for pg_escape_bytea * @param string|int|float|bool $string any string/int/float/bool
public function __dbEscapeBytea($bytea) * @return string excaped string including quites
*/
public function __dbEscapeLiteral($string): string
{
return pg_escape_string($this->dbh, (string)$string);
}
/**
* wrapper for pg_escape_byte
* @param string $bytea bytea data stream
* @return string escaped bytea string
*/
public function __dbEscapeBytea($bytea): string
{ {
return pg_escape_bytea($this->dbh, $bytea); return pg_escape_bytea($this->dbh, $bytea);
} }
// METHOD: __dbConnectionBusy /**
// WAS : _db_connection_busy * wrapper for pg_connection_busy
// PARAMS: none * @return bool true/false for busy connection
// RETURN: true/false for busy connection */
// DESC : wrapper for pg_connection_busy public function __dbConnectionBusy(): bool
public function __dbConnectionBusy()
{ {
return pg_connection_busy($this->dbh); return pg_connection_busy($this->dbh);
} }
// METHOD: __dbVersion /**
// WAS : _db_version * wrapper for pg_version
// PARAMS: none * Note: this only returns server version
// RETURN: databse version * not connection version OR client version
// DESC : wrapper for pg_version * @return string version string
public function __dbVersion() */
public function __dbVersion(): string
{ {
// array has client, protocol, server // array has client, protocol, server
// we just need the server // we just need the server
@@ -412,13 +432,14 @@ class PgSQL
return $v['server']; return $v['server'];
} }
// METHOD: __dbArrayParse /**
// WAS : _db_array_parse * postgresql array to php array
// PARAMS: input text, output array [needed] * @param string $text array text from PostgreSQL
// [internal] limit: are we at the end of the parse * @param array &$output (internal) recursive pass on for nested arrays
// [internal] offset: shift for {} * @param bool|int $limit (internal) max limit to not overshoot the end, start with false
// RETURN: array with the elements * @param integer $offset (internal) shift offset for {}
// DESC : postgresql array to php array * @return array|int converted PHP array, interal recusrive int position
*/
public function __dbArrayParse($text, &$output, $limit = false, $offset = 1) public function __dbArrayParse($text, &$output, $limit = false, $offset = 1)
{ {
if (false === $limit) { if (false === $limit) {

View File

@@ -29,6 +29,10 @@ class FileReader
public $fr_length; public $fr_length;
public $error = 0; public $error = 0;
/**
* file read constructor
* @param string $filename file name to load
*/
public function __construct($filename) public function __construct($filename)
{ {
if (file_exists($filename)) { if (file_exists($filename)) {
@@ -43,6 +47,11 @@ class FileReader
} }
} }
/**
* read byte data length
* @param int $bytes how many bytes to read
* @return string read data as string
*/
public function read($bytes) public function read($bytes)
{ {
if ($bytes) { if ($bytes) {
@@ -64,6 +73,11 @@ class FileReader
} }
} }
/**
* seek to a position in the file
* @param int $pos position where to go to
* @return int file position after seek done
*/
public function seekto($pos) public function seekto($pos)
{ {
fseek($this->fr_fd, $pos); fseek($this->fr_fd, $pos);
@@ -71,17 +85,29 @@ class FileReader
return $this->fr_pos; return $this->fr_pos;
} }
/**
* get current position in file
* @return int current position in bytes
*/
public function currentpos() public function currentpos()
{ {
return $this->fr_pos; return $this->fr_pos;
} }
/**
* file length/size
* @return int file size in bytes
*/
public function length() public function length()
{ {
return $this->fr_length; return $this->fr_length;
} }
public function close() /**
* close open file handler
* @return void has no return
*/
public function close(): void
{ {
fclose($this->fr_fd); fclose($this->fr_fd);
} }

View File

@@ -26,29 +26,47 @@ namespace CoreLibs\Language\Core;
// seek is essential, and it should be byte stream // seek is essential, and it should be byte stream
class StreamReader class StreamReader
{ {
/**
* constructor, empty
*/
public function __construct() public function __construct()
{ {
// empty // empty
} }
// should return a string [FIXME: perhaps return array of bytes?]
/**
* should return a string [FIXME: perhaps return array of bytes?]
* @param int $bytes bytes to read
* @return bool dummy false
*/
public function read($bytes) public function read($bytes)
{ {
return false; return false;
} }
// should return new position /**
* should return new position
* @param int $position seek to position
* @return bool dummy false
*/
public function seekto($position) public function seekto($position)
{ {
return false; return false;
} }
// returns current position /**
* returns current position
* @return bool dummy false
*/
public function currentpos() public function currentpos()
{ {
return false; return false;
} }
// returns length of entire stream (limit for seekto()s) /**
* returns length of entire stream (limit for seekto()s)
* @return bool dummy false
*/
public function length() public function length()
{ {
return false; return false;

View File

@@ -27,12 +27,21 @@ class StringReader
public $sr_pos; public $sr_pos;
public $sr_str; public $sr_str;
/**
* constructor for string reader
* @param string $str basic string
*/
public function __construct($str = '') public function __construct($str = '')
{ {
$this->sr_str = $str; $this->sr_str = $str;
$this->sr_pos = 0; $this->sr_pos = 0;
} }
/**
* read bytes in string
* @param int $bytes bytes to read in string
* @return string data read in length of bytes as string
*/
public function read($bytes) public function read($bytes)
{ {
$data = substr($this->sr_str, $this->sr_pos, $bytes); $data = substr($this->sr_str, $this->sr_pos, $bytes);
@@ -44,6 +53,11 @@ class StringReader
return $data; return $data;
} }
/**
* go to position in string
* @param int $pos position in string
* @return int new position in string after seek
*/
public function seekto($pos) public function seekto($pos)
{ {
$this->sr_pos = $pos; $this->sr_pos = $pos;
@@ -53,11 +67,19 @@ class StringReader
return $this->sr_pos; return $this->sr_pos;
} }
/**
* get current position in string
* @return int position in string
*/
public function currentpos() public function currentpos()
{ {
return $this->sr_pos; return $this->sr_pos;
} }
/**
* get length of string
* @return int return length of assigned string
*/
public function length() public function length()
{ {
return strlen($this->sr_str); return strlen($this->sr_str);

View File

@@ -35,6 +35,12 @@ class L10n extends \CoreLibs\Basic
private $input; private $input;
private $l10n; private $l10n;
/**
* class constructor call for language getstring
* @param string $lang language name (optional), fallback is en
* @param string $path path, if empty fallback on default internal path
* @param int|integer $set_control_flag control flags for Basic class set/get checks
*/
public function __construct(string $lang = '', string $path = '', int $set_control_flag = 0) public function __construct(string $lang = '', string $path = '', int $set_control_flag = 0)
{ {
parent::__construct($set_control_flag); parent::__construct($set_control_flag);
@@ -60,7 +66,12 @@ class L10n extends \CoreLibs\Basic
$this->l10n = new GetTextReader($this->input); $this->l10n = new GetTextReader($this->input);
} }
// reloads the mofile, if the location of the lang file changes /**
* reloads the mofile, if the location of the lang file changes
* @param string $lang language to reload data
* @param string $path optional path, if not set fallback on internal
* @return bool successfull reload true/false
*/
public function l10nReloadMOfile(string $lang, string $path = ''): bool public function l10nReloadMOfile(string $lang, string $path = ''): bool
{ {
$success = false; $success = false;
@@ -90,27 +101,52 @@ class L10n extends \CoreLibs\Basic
return $success; return $success;
} }
public function __($text) /**
* translates a string and returns translated text
* @param string $text text to translate
* @return string translated text
*/
public function __($text): string
{ {
return $this->l10n->translate($text); return $this->l10n->translate($text);
} }
public function __e($text) /**
* prints translated string out to the screen
* @param string $text text to translate
* @return void has no return
*/
public function __e($text): void
{ {
echo $this->l10n->translate($text); echo $this->l10n->translate($text);
} }
// Return the plural form. // Return the plural form.
/**
* Return the plural form.
* @param string $single string for single word
* @param string $plural string for plural word
* @param string $number number value
* @return string translated plural string
*/
public function __ngettext($single, $plural, $number) public function __ngettext($single, $plural, $number)
{ {
return $this->l10n->ngettext($single, $plural, $number); return $this->l10n->ngettext($single, $plural, $number);
} }
/**
* get current set language
* @return string current set language string
*/
public function __getLang() public function __getLang()
{ {
return $this->lang; return $this->lang;
} }
/**
* get current set mo file
* @return string current set mo language file
*/
public function __getMoFile() public function __getMoFile()
{ {
return $this->mofile; return $this->mofile;

View File

@@ -248,11 +248,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// now some default error msgs (english) // now some default error msgs (english)
public $language_array = array (); public $language_array = array ();
// METHOD: constructor /**
// PARAMS: $db_config -> connect to DB * construct form generator
// $lang -> language code ('en', 'ja', etc) * @param array $db_config db config array
// $table_width -> width of table * @param string $lang interface language
// $set_control_flag -> basic class set/get variable error flags * @param int|integer $table_width table/div width (default 750)
* @param int|integer $set_control_flag basic class set/get variable error flags
*/
public function __construct(array $db_config, string $lang, int $table_width = 750, int $set_control_flag = 0) public function __construct(array $db_config, string $lang, int $table_width = 750, int $set_control_flag = 0)
{ {
$this->my_page_name = $this->getPageName(1); $this->my_page_name = $this->getPageName(1);
@@ -335,7 +337,21 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->security_level = $config_array['security_level']; $this->security_level = $config_array['security_level'];
} }
// dumps all values into output (for error msg) /**
* deconstructor
* writes out error msg to global var
* closes db connectio
*/
public function __destruct()
{
// close DB connection
parent::__destruct();
}
/**
* dumps all values into output (for error msg)
* @return string full table array data output as string html formatted
*/
public function formDumpTableArray() public function formDumpTableArray()
{ {
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
@@ -349,45 +365,38 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $string; return $string;
} }
// dekonstruktor /**
// writes out error msg to global var * the value of the $want_key array field
// closes db connection * works only with fields that appear only ONCE
public function __destruct() * if multiple gets only FIRST
{ * @param string $want_key key to search for
// close DB connection * @param string|null $key_value value to match to (optional)
parent::__destruct(); * @return string|null returns key found or empty string
} */
public function formGetColNameFromKey(string $want_key, ?string $key_value = null): ?string
// METHOD: formGetColNameFromKey
// WAS : form_get_col_name_from_key
// PARAMS: $want_key: the key where you want the data from
// $key_value: if set searches for special right value
// RETURN: the value of the $want_key array field
// works only with fields that appear only ONCE
// if multiple gets only FIRST
public function formGetColNameFromKey($want_key, $key_value = '')
{ {
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
$this->table_array = array (); $this->table_array = array ();
} }
reset($this->table_array); reset($this->table_array);
foreach ($this->table_array as $key => $value) { foreach ($this->table_array as $key => $value) {
if (isset($value[$want_key]) && !isset($key_value)) { if (isset($value[$want_key]) && !$key_value) {
return $key; return $key;
} elseif (isset($value[$want_key]) && $value[$want_key] == $key_value && isset($key_value)) { } elseif (isset($value[$want_key]) && $value[$want_key] == $key_value && $key_value) {
return $key; return $key;
} }
} }
// return nothing on nothing // return nothing on nothing
return ''; return null;
} }
// METHOD: formGetColNameArrayFromKey /**
// WAS : form_get_col_name_array_from_key * array of fields
// PARAMS: $want_key: the key where u want the data from * @param string $want_key the key where you want the data from
// $key_value: if set searches for special right value * @param string|null $key_value if set searches for special right value
// RETURN: array of fields * @return array found key fields
public function formGetColNameArrayFromKey($want_key, $key_value = '') */
public function formGetColNameArrayFromKey(string $want_key, ?string $key_value = null): array
{ {
$key_array = array(); $key_array = array();
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
@@ -405,11 +414,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $key_array; return $key_array;
} }
// METHOD: formPrintMsg /**
// WAS : form_print_msg * formated output for the error && warning msg
// PARAMS: none * @return array error message with msg, width, clas
// RETURN: formated output for the error && warning msg */
public function formPrintMsg() public function formPrintMsg(): array
{ {
$class = ''; $class = '';
if ($this->error) { if ($this->error) {
@@ -426,12 +435,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
// next for functions are pre_test fkts for easier default new,load, etc handling // next for functions are pre_test fkts for easier default new,load, etc handling
// METHOD: formProcedureLoad /**
// WAS : form_procedure_load * default load procedure
// PARAMS: archive_id - which ID should be loaded * @param int $archive_id archive id to load
// RETURN: none * @return void has no return
// DESC : default load procedure */
public function formProcedureLoad($archive_id) public function formProcedureLoad(int $archive_id): void
{ {
if ($this->archive && $archive_id && $this->base_acl_level >= $this->security_level['load']) { if ($this->archive && $archive_id && $this->base_acl_level >= $this->security_level['load']) {
$this->formLoadTableArray($archive_id); $this->formLoadTableArray($archive_id);
@@ -439,12 +448,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formProcedureNew /**
// WAS : form_procedure_new * default new procedure
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : default new procedure public function formProcedureNew(): void
public function formProcedureNew()
{ {
if ($this->new && $this->base_acl_level >= $this->security_level['new']) { if ($this->new && $this->base_acl_level >= $this->security_level['new']) {
if ($this->really_new == 'yes') { if ($this->really_new == 'yes') {
@@ -457,12 +465,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formProcedureSave /**
// WAS : form_procedure_save * default save procedure
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : default save procedure public function formProcedureSave(): void
public function formProcedureSave()
{ {
if ($this->save && $this->base_acl_level >= $this->security_level['save']) { if ($this->save && $this->base_acl_level >= $this->security_level['save']) {
$this->formErrorCheck(); $this->formErrorCheck();
@@ -473,12 +480,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formProcedureDelete /**
// WAS : form_procedure_delete * default delete procedure
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : default delete procedure public function formProcedureDelete(): void
public function formProcedureDelete()
{ {
// delete is also by 'protected' // delete is also by 'protected'
if ($this->delete && $this->base_acl_level >= $this->security_level['delete']) { if ($this->delete && $this->base_acl_level >= $this->security_level['delete']) {
@@ -496,12 +502,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formProcedureDeleteFromElementList /**
// WAS : form_procedure_delete_from_element_list * default delete procedure
// PARAMS: none * @param array $element_list element array that should be removed
// RETURN: none * @param array $remove_name key names that should be removed
// DESC : default delete procedure * @return void has no return
public function formProcedureDeleteFromElementList($element_list, $remove_name) */
public function formProcedureDeleteFromElementList(array $element_list, array $remove_name): void
{ {
$this->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: '.$this->base_acl_level.' >= '.$this->security_level['delete']); $this->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: '.$this->base_acl_level.' >= '.$this->security_level['delete']);
$this->debug('REMOVE ELEMENT', 'Protected Value set: '.(string)isset($this->table_array['protected']['value'])); $this->debug('REMOVE ELEMENT', 'Protected Value set: '.(string)isset($this->table_array['protected']['value']));
@@ -579,11 +586,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formCreateLoad /**
// WAS : form_create_load * create the load list and return it as an array
// PARAMS: none * @return array load list array with primary key, name and selected entry
// RETURN: string from 'load' part of form ... */
public function formCreateLoad() public function formCreateLoad(): array
{ {
$pk_selected = ''; $pk_selected = '';
$t_pk_name = ''; $t_pk_name = '';
@@ -627,11 +634,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
); );
} }
// METHOD: formCreateNew /**
// WAS : form_create_new * Create new entry element for HTML output
// PARAMS: none * @param bool $hide_new_checkbox show or hide the new checkbox, default is false
// RETURN: part for new * @return array return the new create array with name & checkbox show flag
public function formCreateNew($hide_new_checkbox = 0) */
public function formCreateNew($hide_new_checkbox = false): array
{ {
$show_checkbox = 0; $show_checkbox = 0;
$new_name = ''; $new_name = '';
@@ -653,11 +661,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
); );
} }
// METHOD: formCreateSaveDelete /**
// WAS : form_create_save_delete * create the save and delete element html group data
// PARAMS: none * @param bool $hide_delete hide the delete button (default false)
// RETURN: string for delete / save part * @param bool $hide_delete_checkbox hide the delete checkbox (default false)
public function formCreateSaveDelete($hide_delete = 0, $hide_delete_checkbox = 0) * @return array return the hide/show delete framework for html creation
*/
public function formCreateSaveDelete($hide_delete = false, $hide_delete_checkbox = false): array
{ {
$seclevel_okay = 0; $seclevel_okay = 0;
$save = ''; $save = '';
@@ -699,14 +709,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
); );
} // end of function } // end of function
// METHOD: formCreateElement /**
// WAS : form_create_element * create a form element based on the settings in the element array entry
// PARAMS: $element_name: the name from the array, you want to have build * @param string $element_name the name from the array, you want to have build
// $query: can overrule internal query data, * @param string|null $query can overrule internal query data,
// for drop down, as data comes from a reference table * for drop down, as data comes from a reference table
// for drop_down_text it has to be an array with $key->$value * for drop_down_text it has to be an array with $key->$valu
// RETURN: element in HTML * @return array html settings array
public function formCreateElement($element_name, $query = '') */
public function formCreateElement(string $element_name, ?string $query = null): array
{ {
// special 2nd color for 'binary' attribut // special 2nd color for 'binary' attribut
if ($this->table_array[$element_name]['type'] == 'binary' && !isset($this->table_array[$element_name]['value'])) { if ($this->table_array[$element_name]['type'] == 'binary' && !isset($this->table_array[$element_name]['value'])) {
@@ -897,17 +908,23 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$data['value'] = $this->table_array[$element_name]['value']; $data['value'] = $this->table_array[$element_name]['value'];
} }
} }
return array('output_name' => $output_name, 'color' => $EDIT_FGCOLOR_T, 'type' => $type, 'data' => $data); return array(
'output_name' => $output_name,
'color' => $EDIT_FGCOLOR_T,
'type' => $type,
'data' => $data
);
} }
// METHOD: formErrorCheck /**
// WAS : form_error_check * full error message string for output
// PARAMS: none * checks each filled entry to the table array defined error checks
// RETURN: full error message string for output * should be cought like this ...
// should be cought like this ... * if ($msg = $form->form_error_check())
// if ($msg=$form->form_error_check()) * $error=1;
// $error=1; * @return void has no return
public function formErrorCheck() */
public function formErrorCheck(): void
{ {
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
$this->table_array = array (); $this->table_array = array ();
@@ -1170,12 +1187,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
} }
} }
// METHOD: formSetOrder /**
// WAS: form_set_order * sets the order to the maximum, if order flag is set in array
// PARAMS: none * @return array table array with set order number
// RETURN: the table array */
// DESC : sets the order to the maximum, if order flag is set in array public function formSetOrder(): array
public function formSetOrder()
{ {
// get order name // get order name
$order_name = $this->formGetColNameFromKey('order'); $order_name = $this->formGetColNameFromKey('order');
@@ -1198,12 +1214,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return $this->table_array; return $this->table_array;
} }
// METHOD: formUnsetTableArray /**
// WAS : form_unsert_table_array * resets all values in table_array and in the reference tables
// PARAMS: none * @return void has no return
// RETURN: none */
// DESC : resets all values in table_array and in the reference tables public function formUnsetTableArray(): void
public function formUnsetTableArray()
{ {
unset($this->pk_id); unset($this->pk_id);
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
@@ -1231,17 +1246,17 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Cleared for new Dataset!'); $this->msg = $this->l->__('Cleared for new Dataset!');
} }
// METHOD: formLoadTableArray /**
// WAS : form_load_table_array * load a table & reference
// PARAMS: pk_id - overrule pk_id * @param int|null $pk_id overrule pk_id
// RETURN: none * @return void has no return
// DESC : load a table & reference */
public function formLoadTableArray($pk_id = 0) public function formLoadTableArray(?int $pk_id = null): void
{ {
if ($pk_id) { if ($pk_id) {
$this->pk_id = $pk_id; $this->pk_id = $pk_id;
} }
$this->table_array = $this->dbRead(1); $this->table_array = $this->dbRead(true);
// reset all temp fields // reset all temp fields
if (!is_array($this->table_array)) { if (!is_array($this->table_array)) {
@@ -1270,12 +1285,14 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->msg = $this->l->__('Dataset has been loaded!<br>'); $this->msg = $this->l->__('Dataset has been loaded!<br>');
} }
// METHOD: formSaveTableArray /**
// WAS : form_save_table_array * save a table, reference and all input fields
// PARAMS: addslashes - if one, passes 1 to the db_write function * note that the addslashes flag here is passed on to the dbWrite method
// RETURN: none * it only does html conversion, add slashes for DB is done automatically
// DESC : save a table, reference and all input fields * @param bool $addslashes override internal addslasahes flag (default false)
public function formSaveTableArray($addslashes = 0) * @return void has no return
*/
public function formSaveTableArray($addslashes = false)
{ {
// for drop_down_db_input check if text field is filled and if, if not yet in db ... // for drop_down_db_input check if text field is filled and if, if not yet in db ...
// and upload files // and upload files
@@ -1670,14 +1687,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
return array('output_name' => $output_name, 'type' => $type, 'color' => 'edit_fgcolor', 'data' => $data); return array('output_name' => $output_name, 'type' => $type, 'color' => 'edit_fgcolor', 'data' => $data);
} }
// METHOD: formCreateElementListTable /**
// WAS : form_create_element_list_table * create list of elements next to each other for a group of data in an input field
// PARAMS: show which element list * this currently only works for a list that is filled from a sub table and creates
// RETURN: array for output * only a connection to this one new version will allow a sub list with free input
// DESC : create list of elements next to each other for a group of data in an input field * fields to directly fill a sub table to a master table
// this currently only works for a list that is filled from a sub table and creates only a connection to this one * @param string $table_name which element entry to create
// new version will allow a sub list with free input fields to directly fill a sub table to a master table * @return array element for html creation
public function formCreateElementListTable($table_name) */
public function formCreateElementListTable(string $table_name): array
{ {
// output name for the viewable left table td box, prefixed with * if mandatory // output name for the viewable left table td box, prefixed with * if mandatory
$output_name = $this->element_list[$table_name]['output_name']; $output_name = $this->element_list[$table_name]['output_name'];
@@ -1737,7 +1755,7 @@ 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 // 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 // only two elements are allowed: pos 0 is key, pso 1 is visible output name
if ($data_array['type'] == 'drop_down_db') { if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') {
$md_q = md5($data_array['query']); $md_q = md5($data_array['query']);
while ($res = $this->dbReturn($data_array['query'])) { while ($res = $this->dbReturn($data_array['query'])) {
$this->debug('edit', 'Q['.$md_q.'] pos: '.$this->cursor_ext[$md_q]['pos'].' | want: '.(isset($data_array['preset']) ? $data_array['preset'] : '-').' | set: '.(isset($data['preset'][$el_name]) ? $data['preset'][$el_name] : '-')); $this->debug('edit', 'Q['.$md_q.'] pos: '.$this->cursor_ext[$md_q]['pos'].' | want: '.(isset($data_array['preset']) ? $data_array['preset'] : '-').' | set: '.(isset($data['preset'][$el_name]) ? $data['preset'][$el_name] : '-'));

View File

@@ -73,8 +73,12 @@ class ProgressBar
) )
*/ */
// constructor /**
public function __construct($width = 0, $height = 0) * progress bar constructor
* @param integer $width progress bar width, default 0
* @param integer $height progress bar height, default 0
*/
public function __construct(int $width = 0, int $height = 0)
{ {
$this->code = substr(md5(microtime()), 0, 6); $this->code = substr(md5(microtime()), 0, 6);
if ($width > 0) { if ($width > 0) {
@@ -90,7 +94,12 @@ class ProgressBar
// private functions // private functions
private function __flushCache($clear_buffer_size = 0) /**
* flush cache hack for IE and others
* @param integer $clear_buffer_size buffer size override
* @return void has not return
*/
private function __flushCache(int $clear_buffer_size = 0): void
{ {
if (!$clear_buffer_size) { if (!$clear_buffer_size) {
$clear_buffer_size = $this->clear_buffer_size; $clear_buffer_size = $this->clear_buffer_size;
@@ -100,7 +109,12 @@ class ProgressBar
flush(); flush();
} }
private function __calculatePercent($step) /**
* [__calculatePercent description]
* @param float $step percent step to do
* @return float percent step done
*/
private function __calculatePercent(float $step): float
{ {
// avoid divison through 0 // avoid divison through 0
if ($this->max - $this->min == 0) { if ($this->max - $this->min == 0) {
@@ -113,7 +127,12 @@ class ProgressBar
return $percent; return $percent;
} }
private function __calculatePosition($step) /**
* calculate position in bar step
* @param float $step percent step to do
* @return array bar position as array
*/
private function __calculatePosition(float $step): array
{ {
$bar = 0; $bar = 0;
switch ($this->direction) { switch ($this->direction) {
@@ -168,7 +187,12 @@ class ProgressBar
return $position; return $position;
} }
private function __setStep($step) /**
* set the step
* @param float $step percent step to do
* @return void has no return
*/
private function __setStep(float $step): void
{ {
if ($step > $this->max) { if ($step > $this->max) {
$step = $this->max; $step = $this->max;
@@ -180,7 +204,13 @@ class ProgressBar
} }
// public functions // public functions
public function setFrame($width = 0, $height = 0) /**
* set frame layout
* @param integer $width bar width
* @param integer $height bar height
* @return void has no return
*/
public function setFrame(int $width = 0, int $height = 0): void
{ {
$this->frame = array ( $this->frame = array (
'show' => true, 'show' => true,
@@ -201,7 +231,15 @@ class ProgressBar
} }
} }
public function addLabel($type, $name, $value = '&nbsp;') /**
* set bar label text
* allowed types are: text, button, step, percent, percentlbl, crossbar
* @param string $type label type
* @param string $name label name (internal)
* @param string $value label output name (optional)
* @return void has no return
*/
public function addLabel(string $type, string $name, string $value = '&nbsp;'): void
{ {
switch ($type) { switch ($type) {
case 'text': case 'text':
@@ -276,7 +314,6 @@ class ProgressBar
'color' => '#000000', 'color' => '#000000',
'bgr_color' => '' 'bgr_color' => ''
); );
// print "THIS[$name]: ".$this->label[$name]['left']." | ".$this->label[$name]['width']."<br>";
break; break;
case 'crossbar': case 'crossbar':
$this->label[$name] = array( $this->label[$name] = array(
@@ -297,14 +334,32 @@ class ProgressBar
} }
} }
public function addButton($name, $value, $action, $target = 'self') /**
* add a button to the progress bar
* @param string $name button name (internal)
* @param string $value button text (output)
* @param string $action button action (link)
* @param string $target button action target (default self)
* @return void has no return
*/
public function addButton(string $name, string $value, string $action, string $target = 'self'): void
{ {
$this->addLabel('button', $name, $value); $this->addLabel('button', $name, $value);
$this->label[$name]['action'] = $action; $this->label[$name]['action'] = $action;
$this->label[$name]['target'] = $target; $this->label[$name]['target'] = $target;
} }
public function setLabelPosition($name, $left, $top, $width, $height, $align = '') /**
* set the label position
* @param string $name label name to set
* @param int $left left px
* @param int $top top px
* @param int $width width px
* @param int $height height px
* @param string $align alignment (left/right/etc), default empty
* @return void has no return
*/
public function setLabelPosition(string $name, int $left, int $top, int $width, int $height, string $align = ''): void
{ {
// print "SET POSITION[$name]: $left<br>"; // print "SET POSITION[$name]: $left<br>";
// if this is percent, we ignore anything, it is auto positioned // if this is percent, we ignore anything, it is auto positioned
@@ -333,7 +388,13 @@ class ProgressBar
} }
} }
public function setLabelColor($name, $color) /**
* set label color
* @param string $name label name to set
* @param string $color color value in rgb html hex
* @return void has no return
*/
public function setLabelColor(string $name, string $color): void
{ {
$this->label[$name]['color'] = $color; $this->label[$name]['color'] = $color;
if ($this->status != 'new') { if ($this->status != 'new') {
@@ -342,7 +403,13 @@ class ProgressBar
} }
} }
public function setLabelBackground($name, $color) /**
* set the label background color
* @param string $name label name to set
* @param string $color background color to set in rgb html hex
* @return void has no return
*/
public function setLabelBackground(string $name, string $color): void
{ {
$this->label[$name]['bgr_color'] = $color; $this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new') { if ($this->status != 'new') {
@@ -351,7 +418,15 @@ class ProgressBar
} }
} }
public function setLabelFont($name, $size, $family = '', $weight = '') /**
* [setLabelFont description]
* @param string $name label name to set
* @param int $size font size in px
* @param string $family font family (default empty)
* @param string $weight font weight (default empty)
* @return void has no return
*/
public function setLabelFont(string $name, int $size, string $family = '', string $weight = ''): void
{ {
// just in case if it is too small // just in case if it is too small
if (intval($size) < 0) { if (intval($size) < 0) {
@@ -386,7 +461,13 @@ class ProgressBar
} }
} }
public function setLabelValue($name, $value) /**
* set the label valeu
* @param string $name label name to set
* @param string $value label value (output)
* @return void has no return
*/
public function setLabelValue(string $name, string $value): void
{ {
$this->label[$name]['value'] = $value; $this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>"; // print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
@@ -396,7 +477,12 @@ class ProgressBar
} }
} }
public function setBarColor($color) /**
* set the bar color
* @param string $color color for the progress bar in rgb html hex
* @return void has no return
*/
public function setBarColor(string $color): void
{ {
$this->color = $color; $this->color = $color;
if ($this->status != 'new') { if ($this->status != 'new') {
@@ -405,7 +491,12 @@ class ProgressBar
} }
} }
public function setBarBackground($color) /**
* set the progress bar background color
* @param string $color background color in rgb html hex
* @return void has no return
*/
public function setBarBackground(string $color): void
{ {
$this->bgr_color = $color; $this->bgr_color = $color;
if ($this->status != 'new') { if ($this->status != 'new') {
@@ -414,7 +505,12 @@ class ProgressBar
} }
} }
public function setBarDirection($direction) /**
* progress bar direct (left/right)
* @param string $direction set direction as left/right
* @return void has no return
*/
public function setBarDirection(string $direction): void
{ {
$this->direction = $direction; $this->direction = $direction;
@@ -431,7 +527,11 @@ class ProgressBar
} }
} }
public function getHtml() /**
* get the progress bar base HTML
* @return string progress bar HTML code
*/
public function getHtml(): string
{ {
$html = ''; $html = '';
$js = ''; $js = '';
@@ -582,14 +682,24 @@ class ProgressBar
return $html; return $html;
} }
public function show() /**
* show the progress bar after initialize
* @return void has no return
*/
public function show(): void
{ {
$this->status = 'show'; $this->status = 'show';
echo $this->getHtml(); echo $this->getHtml();
$this->__flushCache(); $this->__flushCache();
} }
public function moveStep($step) /**
* move the progress bar by one step
* prints out javascript to move progress bar
* @param float $step percent step
* @return void has no return
*/
public function moveStep(float $step): void
{ {
$last_step = $this->step; $last_step = $this->step;
$this->__setStep($step); $this->__setStep($step);
@@ -636,17 +746,29 @@ class ProgressBar
} }
} }
public function moveNext() /**
* moves progress bar by one step (1)
* @return void has no return
*/
public function moveNext(): void
{ {
$this->moveStep($this->step + 1); $this->moveStep($this->step + 1);
} }
public function moveMin() /**
* moves the progress bar back to the beginning
* @return void has no return
*/
public function moveMin(): void
{ {
$this->moveStep($this->min); $this->moveStep($this->min);
} }
public function hide() /**
* hide the progress bar if it is visible
* @return void has no return
*/
public function hide(): void
{ {
if ($this->status == 'show') { if ($this->status == 'show') {
$this->status = 'hide'; $this->status = 'hide';
@@ -659,7 +781,11 @@ class ProgressBar
} }
} }
public function unhide() /**
* show progress bar again after it was hidden with hide()
* @return void has no return
*/
public function unhide(): void
{ {
if ($this->status == 'hide') { if ($this->status == 'hide') {
$this->status = 'show'; $this->status = 'show';

View File

@@ -1,4 +1,9 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
// because smarty is symlinked folder
/**
* @phan-file-suppress PhanRedefinedExtendedClass
*/
/******************************************************************** /********************************************************************
* AUTHOR: Clemens Schwaighofer * AUTHOR: Clemens Schwaighofer
* CREATED: 2004/12/21 * CREATED: 2004/12/21
@@ -20,6 +25,12 @@ class SmartyExtend extends SmartyBC
public $l10n; public $l10n;
// constructor class, just sets the language stuff // constructor class, just sets the language stuff
/**
* constructor class, just sets the language stuff
* calls L10 for pass on internaly in smarty
* also registers the getvar caller pliugin
* @param string $lang language string to set
*/
public function __construct(string $lang) public function __construct(string $lang)
{ {
parent::__construct(); parent::__construct();