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:
@@ -1,4 +1,7 @@
|
||||
<?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 = 1;
|
||||
@@ -27,7 +30,7 @@ $lang = 'en_utf8';
|
||||
// init login & backend class
|
||||
$login = new CoreLibs\ACL\Login(DB_CONFIG, $lang);
|
||||
$basic = new CoreLibs\Admin\Backend(DB_CONFIG, $lang);
|
||||
$basic->dbInfo(1);
|
||||
$basic->dbInfo(true);
|
||||
ob_end_flush();
|
||||
|
||||
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 "TIMED [hr]: ".$basic->hrRunningTime()."<br>";
|
||||
echo "TIMED [def]: ".$basic->runningTime()."<br>";
|
||||
echo "TIMED [string]: ".$basic->runningtime_string."<br>";
|
||||
$basic->hrRunningTime();
|
||||
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
|
||||
$edit_access_id = 3;
|
||||
if (is_object($login) && isset($login->acl['unit'])) {
|
||||
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)) {
|
||||
$basic->edit_access_id = $edit_access_id;
|
||||
} else {
|
||||
|
||||
@@ -21,19 +21,19 @@ ob_end_flush();
|
||||
print "Start time: ".$base->runningTime()."<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 "DB Info: ".$base->dbInfo(1)."<br>";
|
||||
print "DB Info: ".$base->dbInfo(true)."<br>";
|
||||
|
||||
|
||||
print "End Time: ".$base->runningTime()."<br>";
|
||||
print "Run Time: ".$base->runningTime()."<br>";
|
||||
$base->resetRunningtime();
|
||||
print "Start Time: ".$base->runningTime()."<br>";
|
||||
|
||||
print "Lang: ".$base->l->__getLang().", MO File: ".$base->l->__getMoFile()."<br>";
|
||||
print "Translate test: Year -> ".$base->l->__('Year')."<br>";
|
||||
|
||||
print "End Time: ".$base->runningTime()."<br>";
|
||||
// end error print
|
||||
print $base->printErrorMsg();
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
namespace CoreLibs;
|
||||
|
||||
@@ -16,7 +19,7 @@ print "THIS HOST: ".HOST_NAME.", with PROTOCOL: ".HOST_PROTOCOL." is running SSL
|
||||
print "DIR: ".DIR."<br>";
|
||||
print "BASE: ".BASE."<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
|
||||
with some
|
||||
|
||||
@@ -14,7 +14,7 @@ $DB_CONFIG = array (
|
||||
'db_user' => 'gullevek',
|
||||
'db_pass' => 'gullevek',
|
||||
'db_host' => 'db.tokyo.tequila.jp',
|
||||
'db_port' => '5432',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
|
||||
@@ -13,21 +13,21 @@
|
||||
*********************************************************************/
|
||||
|
||||
// each host has a different db_host
|
||||
// development host
|
||||
$DB_HOST['soba.tokyo.tequila.jp'] = 'test';
|
||||
// target host (live)
|
||||
// $DB_TARGET_HOST['soba'] = '<DB ID>';
|
||||
// url redirect database
|
||||
// $DB_URL_REDIRECT_HOST['soba'] = '<DB ID>';
|
||||
// location flagging
|
||||
// test/dev/live
|
||||
$LOCATION['soba.tokyo.tequila.jp'] = 'test';
|
||||
// show DEBUG override
|
||||
// true/false
|
||||
$DEBUG_FLAG['soba.tokyo.tequila.jp'] = true;
|
||||
// set postgresql paths (schemas)
|
||||
$DB_PATH['soba.tokyo.tequila.jp'] = PUBLIC_SCHEMA;
|
||||
// site language
|
||||
$SITE_LANG['soba.tokyo.tequila.jp'] = 'en_utf8';
|
||||
$SITE_CONFIG = array (
|
||||
// development host
|
||||
'soba.tokyo.tequila.jp' => array (
|
||||
// db config selection
|
||||
'db_host' => 'test',
|
||||
// other db connections
|
||||
// 'db_host_target' => '',
|
||||
// 'db_host_other' => '',
|
||||
// location flagging (test/dev/live) for debug output
|
||||
'location' => 'test',
|
||||
// show DEBUG override
|
||||
'debug_flag' => true,
|
||||
// site language
|
||||
'site_lang' => 'en_utf8',
|
||||
)
|
||||
);
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -171,20 +171,8 @@ DEFINE('LIVE_SCHEMA', 'public');
|
||||
if (file_exists(BASE.CONFIGS.'config.host.php')) {
|
||||
require BASE.CONFIGS.'config.host.php';
|
||||
}
|
||||
if (!isset($DB_HOST)) {
|
||||
$DB_HOST = 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 ();
|
||||
if (!isset($SITE_CONFIG)) {
|
||||
$SITE_CONFIG = array ();
|
||||
}
|
||||
/************* DB ACCESS *****************/
|
||||
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';
|
||||
}
|
||||
|
||||
// set the USE_DATABASE var, if there is nothing set, we assume TRUE
|
||||
$USE_DATABASE = defined('USE_DATABASE') ? USE_DATABASE : true;
|
||||
|
||||
// live frontend pages
|
||||
// ** missing live domains **
|
||||
// get the name without the port
|
||||
list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null);
|
||||
if (!isset($DB_HOST[$HOST_NAME]) && $USE_DATABASE) {
|
||||
echo 'No matching DB config found. Contact Admin<br>';
|
||||
// BAIL ON:
|
||||
// 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;
|
||||
}
|
||||
// set HOST name
|
||||
@@ -221,25 +219,24 @@ if ((array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVE
|
||||
DEFINE('HOST_PROTOCOL', 'http://');
|
||||
}
|
||||
// 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_SCHEMA', $DB_PATH[$HOST_NAME]);
|
||||
// DEFINE('TARGET_DB', $DB_TARGET_HOST[$HOST_NAME]);
|
||||
// DEFINE('URL_REDIRECT_DB', $DB_URL_REDIRECT_HOST[$HOST_NAME]);
|
||||
// next three if top is not set
|
||||
// DEFINE('TEST_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
|
||||
// DEFINE('DEV_SCHEMA', $DB_CONFIG[MAIN_DB]['db_schema']);
|
||||
// DEFINE('PUBLIC_SCHEMA', $DB_CONFIG[TARGET_DB]['db_schema']);
|
||||
DEFINE('LOGIN_DB_SCHEMA', PUBLIC_SCHEMA); // where the edit* tables are
|
||||
DEFINE('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA); // where global tables are that are used by all schemas (eg queue tables for online, etc)
|
||||
DEFINE('TARGET', $LOCATION[$HOST_NAME]);
|
||||
// DEFINE('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
|
||||
// DEFINE('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
|
||||
// override for login and global schemas
|
||||
// DEFINE('LOGIN_DB_SCHEMA', PUBLIC_SCHEMA); // where the edit* tables are
|
||||
// DEFINE('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA); // where global tables are that are used by all schemas (eg queue tables for online, etc)
|
||||
// debug settings, site lang, etc
|
||||
DEFINE('TARGET', $SITE_CONFIG[$HOST_NAME]['location']);
|
||||
DEFINE('DEBUG', $SITE_CONFIG[$HOST_NAME]['debug_flag']);
|
||||
DEFINE('SITE_LANG', $SITE_CONFIG[$HOST_NAME]['site_lang']);
|
||||
// paths
|
||||
// DEFINE('CSV_PATH', $PATHS[TARGET]['csv_path']);
|
||||
// DEFINE('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
|
||||
// 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 ********/
|
||||
DEFINE('G_TITLE', '<OVERALL FALLBACK PAGE TITLE>');
|
||||
|
||||
@@ -120,6 +120,7 @@ if (isset($AJAX_PAGE) && !$AJAX_PAGE) {
|
||||
|
||||
// if the lang folder is different to the default one
|
||||
// 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) ||
|
||||
strcasecmp(defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG, $lang)
|
||||
) {
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace CoreLibs\ACL;
|
||||
class Login extends \CoreLibs\DB\IO
|
||||
{
|
||||
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
|
||||
private $action; // master action command
|
||||
private $username; // login name
|
||||
@@ -109,11 +109,12 @@ class Login extends \CoreLibs\DB\IO
|
||||
// language
|
||||
public $l;
|
||||
|
||||
// METHOD: login
|
||||
// PARAMS: db_config -> array for logging in to DB where edit_users tables are
|
||||
// db_debug -> sets debug output for db_io (can be overruled with DB_DEBUG)
|
||||
// RETURN: none
|
||||
// DESC : cunstroctuor, does ALL, opens db, works through connection checks, closes itself
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||
* @param array $db_config db config array
|
||||
* @param string $lang language string (default en_utf8)
|
||||
* @param int $set_control_flag class variable check flags
|
||||
*/
|
||||
public function __construct(array $db_config, string $lang = 'en_utf8', int $set_control_flag = 0)
|
||||
{
|
||||
// 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
|
||||
// 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')) {
|
||||
/** @phan-suppress-next-line PhanUndeclaredConstant */
|
||||
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||
} elseif ($db_config['db_schema']) {
|
||||
$SCHEMA = $db_config['db_schema'];
|
||||
} elseif (defined('DB_SCHEMA')) {
|
||||
$SCHEMA = DB_SCHEMA;
|
||||
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||
$SCHEMA = PUBLIC_SCHEMA;
|
||||
} else {
|
||||
$SCHEMA = 'public';
|
||||
}
|
||||
@@ -269,19 +271,20 @@ class Login extends \CoreLibs\DB\IO
|
||||
$this->loginSetAcl();
|
||||
}
|
||||
|
||||
// METHOD: _login
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : deconstructory, called with the last function to close DB connection
|
||||
/**
|
||||
* deconstructory, called with the last function to close DB connection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// METHOD: loginPasswordCheck
|
||||
// PARAMS: hash, optional password, to override
|
||||
// RETURN: true or false
|
||||
// DESC : checks if password is valid, sets internal error login variable
|
||||
/**
|
||||
* checks if password is valid, sets internal error login variable
|
||||
* @param string $hash password hash
|
||||
* @param string $password submitted password
|
||||
* @return bool true or false on password ok or not
|
||||
*/
|
||||
private function loginPasswordCheck(string $hash, string $password = ''): bool
|
||||
{
|
||||
// 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("/^\\$1\\$/", $hash) ||
|
||||
preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash)) &&
|
||||
/** @phan-suppress-next-line PhanDeprecatedFunction */
|
||||
!$this->verifyCryptString($password, $hash)
|
||||
) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// METHOD: loginLoginUser
|
||||
// WAS : login_login_user
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : if user pressed login button this script is called, but only if there is no preview euid set
|
||||
/**
|
||||
* if user pressed login button this script is called, but only if there is no preview euid set]
|
||||
* @return void has not return
|
||||
*/
|
||||
private function loginLoginUser()
|
||||
{
|
||||
// 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 ($this->login_error) {
|
||||
// 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
|
||||
}
|
||||
|
||||
// METHOD: loginCheckPermissions
|
||||
// WAS : login_check_permission
|
||||
// PARAMS: none
|
||||
// RETUNR none
|
||||
// DESC : for every page the user access this script checks if he is allowed to do so
|
||||
/**
|
||||
* for every page the user access this script checks if he is allowed to do so
|
||||
* @return bool permission okay as true/false
|
||||
*/
|
||||
public function loginCheckPermissions()
|
||||
{
|
||||
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)
|
||||
// ini_set('memory_limit', -1);
|
||||
if ($res['filename'] == $this->page_name) {
|
||||
$this->permission_okay = 1;
|
||||
$this->permission_okay = true;
|
||||
} else {
|
||||
$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
|
||||
return $this->permission_okay;
|
||||
}
|
||||
|
||||
// METHOD: loginLogoutUser
|
||||
// WAS : login_logout_user
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : if a user pressed on logout, destroyes session and unsets all global vars
|
||||
/**
|
||||
* if a user pressed on logout, destroyes session and unsets all global vars
|
||||
* @return void has no return
|
||||
*/
|
||||
public function loginLogoutUser()
|
||||
{
|
||||
if ($this->logout || $this->login_error) {
|
||||
@@ -626,7 +627,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
unset($_SESSION['HEADER_COLOR']);
|
||||
session_destroy();
|
||||
// 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 edit access ACL level is set, use this, else use page
|
||||
// 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()
|
||||
{
|
||||
// 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
|
||||
// PARAMS: edit_access_id to check
|
||||
// RETURN: true/false: if the edit access is not in the valid list: false
|
||||
// DESC : checks if this edit access id is valid
|
||||
/**
|
||||
* checks if this edit access id is valid
|
||||
* @param int $edit_access_id access id pk to check
|
||||
* @return bool true/false: if the edit access is not in the valid list: false
|
||||
*/
|
||||
public function loginCheckEditAccess($edit_access_id): bool
|
||||
{
|
||||
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
|
||||
// RETURN: true or false
|
||||
// DESC : checks if the password is in a valid format
|
||||
/**
|
||||
* checks if the password is in a valid format
|
||||
* @param string $password the new password
|
||||
* @return bool true or false if valid password or not
|
||||
*/
|
||||
private function loginPasswordChangeValidPassword($password)
|
||||
{
|
||||
$is_valid_password = true;
|
||||
@@ -772,19 +791,20 @@ class Login extends \CoreLibs\DB\IO
|
||||
return $is_valid_password;
|
||||
}
|
||||
|
||||
// METHOD: loginPasswordForgot
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : dummy declare for password forget
|
||||
/**
|
||||
* dummy declare for password forget
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginPasswordForgot()
|
||||
{
|
||||
// will do some password recovert, eg send email
|
||||
}
|
||||
|
||||
// METHOD: loginSetPasswordMinLength
|
||||
// PARAMS: set the minimum length
|
||||
// RETURN: true/false on success
|
||||
// DESC : sets the minium length and checks on valid
|
||||
/**
|
||||
* sets the minium length and checks on valid
|
||||
* @param int $length set the minimum length
|
||||
* @return bool true/false on success
|
||||
*/
|
||||
public function loginSetPasswordMinLength(int $length): bool
|
||||
{
|
||||
// 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
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : changes a user password
|
||||
/**
|
||||
* changes a user password
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginPasswordChange()
|
||||
{
|
||||
if ($this->change_password) {
|
||||
@@ -867,7 +886,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
}
|
||||
} else {
|
||||
// illegal user error
|
||||
$this->login_error = '220';
|
||||
$this->login_error = 220;
|
||||
$data = 'Illegal user for password change: '.$this->pw_username;
|
||||
}
|
||||
// log this password change attempt
|
||||
@@ -875,13 +894,13 @@ class Login extends \CoreLibs\DB\IO
|
||||
} // button pressed
|
||||
}
|
||||
|
||||
// METHOD: loginPrintLogin
|
||||
// WAS : login_print_login
|
||||
// PARAMS: none
|
||||
// RETURN: html data for login page
|
||||
// DESC : prints out login html part if no permission (error) is set
|
||||
/**
|
||||
* prints out login html part if no permission (error) is set
|
||||
* @return ?string html data for login page, or null for nothing
|
||||
*/
|
||||
private function loginPrintLogin()
|
||||
{
|
||||
$html_string = null;
|
||||
if (!$this->permission_okay) {
|
||||
// get global AJAX page trigger
|
||||
// if true, return error ajax
|
||||
@@ -954,17 +973,17 @@ class Login extends \CoreLibs\DB\IO
|
||||
$html_string = str_replace('{'.$string.'}', $data, $html_string);
|
||||
}
|
||||
}
|
||||
// return the created HTML here
|
||||
return $html_string;
|
||||
} // 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
|
||||
// PARAMS: none
|
||||
// RETURN: 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()
|
||||
/**
|
||||
* last function called, writes log and prints out error msg and
|
||||
* exists script if permission 0
|
||||
* @return bool true on permission ok, false on permission wrong
|
||||
*/
|
||||
private function loginCloseClass(): bool
|
||||
{
|
||||
// write to LOG table ...
|
||||
if ($this->login_error || $this->login || $this->logout) {
|
||||
@@ -995,11 +1014,10 @@ class Login extends \CoreLibs\DB\IO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: loginSetTemplates
|
||||
// WAS : login_set_templates
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : checks if there are external templates, if not uses internal fallback ones
|
||||
/**
|
||||
* checks if there are external templates, if not uses internal fallback ones
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginSetTemplates()
|
||||
{
|
||||
$strings = array (
|
||||
@@ -1151,14 +1169,15 @@ EOM;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: writeLog
|
||||
// WAS : write_log
|
||||
// PARAMS: event -> string of what has been done
|
||||
// data -> data information (id, etc)
|
||||
// error -> if error, write error string (not enougth data, etc)
|
||||
// RETURN: none
|
||||
// DESC : writes detailed data into the edit user log table (keep log what user does)
|
||||
private function writeLog($event, $data, $error = '', $username = '')
|
||||
/**
|
||||
* writes detailed data into the edit user log table (keep log what user does)
|
||||
* @param string $event string of what has been done
|
||||
* @param string $data data information (id, etc)
|
||||
* @param string|int $error error id (mostly an int)
|
||||
* @param string $username login user username
|
||||
* @return void has no return
|
||||
*/
|
||||
private function writeLog(string $event, string $data, $error = '', string $username = '')
|
||||
{
|
||||
if ($this->login) {
|
||||
$this->action = 'Login';
|
||||
@@ -1202,12 +1221,12 @@ EOM;
|
||||
$this->dbExec($q, 'NULL');
|
||||
}
|
||||
|
||||
// METHOD: loginCheckEditAccessId
|
||||
// WAS : login_check_edit_access_id
|
||||
// PARAMS: edit access id to check
|
||||
// RETURN: same edit access id if ok, or the default edit access id if given one is not valud
|
||||
// DESC : checks that the given edit access id is valid for this user
|
||||
public function loginCheckEditAccessId($edit_access_id)
|
||||
/**
|
||||
*checks that the given edit access id is valid for this user
|
||||
* @param int $edit_access_id edit access id to check
|
||||
* @return int same edit access id if ok, or the default edit access id if given one is not valid
|
||||
*/
|
||||
public function loginCheckEditAccessId(int $edit_access_id)
|
||||
{
|
||||
if (!array_key_exists($edit_access_id, $_SESSION["UNIT"])) {
|
||||
return $_SESSION["UNIT_DEFAULT"];
|
||||
@@ -1216,12 +1235,13 @@ EOM;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: loginSetEditAccessData
|
||||
// WAS : login_set_edit_access_data
|
||||
// PARAMS: edit access id, key value to search for
|
||||
// RETURN: false for not found or string for found data
|
||||
// DESC : searchs in the data set for the unit for the data key and returns the value asociated with it
|
||||
public function loginSetEditAccessData($edit_access_id, $data_key)
|
||||
/**
|
||||
* [loginSetEditAccessData description]
|
||||
* @param int $edit_access_id edit access id
|
||||
* @param string|int $data_key key value to search for
|
||||
* @return bool|string false for not found or string for found data
|
||||
*/
|
||||
public function loginSetEditAccessData(int $edit_access_id, $data_key)
|
||||
{
|
||||
if (!$_SESSION['UNIT'][$edit_access_id]['data'][$data_key]) {
|
||||
return false;
|
||||
|
||||
@@ -81,10 +81,12 @@ class Backend extends \CoreLibs\DB\IO
|
||||
public $l;
|
||||
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
// METHOD: __construct
|
||||
// PARAMS: array db config
|
||||
// string for language set
|
||||
// int set control flag (for core basic set/get var error control)
|
||||
/**
|
||||
* main class constructor
|
||||
* @param array $db_config db config array
|
||||
* @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)
|
||||
{
|
||||
// get the language sub class & init it
|
||||
@@ -106,7 +108,9 @@ class Backend extends \CoreLibs\DB\IO
|
||||
}
|
||||
}
|
||||
|
||||
// deconstructor
|
||||
/**
|
||||
* class deconstructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
@@ -117,12 +121,14 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
// METHOD: adbEditLog()
|
||||
// PARAMS: event -> any kind of event description,
|
||||
// data -> any kind of data related to that event
|
||||
// RETURN: none
|
||||
// DESC : writes all action vars plus other info into edit_log table
|
||||
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING')
|
||||
/**
|
||||
* writes all action vars plus other info into edit_log tabl
|
||||
* @param string $event any kind of event description,
|
||||
* @param string|array $data any kind of data related to that event
|
||||
* @param string $write_type write type can bei STRING or BINARY
|
||||
* @return void has no return
|
||||
*/
|
||||
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING'): void
|
||||
{
|
||||
$data_binary = '';
|
||||
if ($write_type == 'BINARY') {
|
||||
@@ -134,7 +140,19 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$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 .= "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) ";
|
||||
@@ -163,10 +181,11 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$this->dbExec($q, 'NULL');
|
||||
}
|
||||
|
||||
// METHOD: adbTopMenu
|
||||
// PARAMS: level
|
||||
// RETURN: returns an array for the top menu with all correct settings
|
||||
// DESC : menu creater
|
||||
/**
|
||||
* menu creater (from login menu session pages)
|
||||
* @param int $flag visible flag trigger
|
||||
* @return array menu array for output on page (smarty)
|
||||
*/
|
||||
public function adbTopMenu(int $flag = 0): array
|
||||
{
|
||||
if ($this->menu_show_flag) {
|
||||
@@ -255,10 +274,11 @@ class Backend extends \CoreLibs\DB\IO
|
||||
return $this->menu;
|
||||
}
|
||||
|
||||
// METHOD: adbShowMenuPoint
|
||||
// PARAMS: filename
|
||||
// RETURN: returns boolean true/false
|
||||
// DESC : checks if this filename is in the current situation (user id, etc) available
|
||||
/**
|
||||
* checks if this filename is in the current situation (user id, etc) available
|
||||
* @param string $filename filename
|
||||
* @return bool true for visible/accessable menu point, false for not
|
||||
*/
|
||||
public function adbShowMenuPoint(string $filename): bool
|
||||
{
|
||||
$enabled = false;
|
||||
@@ -270,50 +290,56 @@ class Backend extends \CoreLibs\DB\IO
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbAssocArray
|
||||
// PARAMS: db array, key, value part
|
||||
// RETURN: returns and associative array
|
||||
// DESC : creates out of a normal db_return array an assoc array
|
||||
/**
|
||||
* @deprecated
|
||||
* creates out of a normal db_return array an assoc array
|
||||
* @param array $db_array input 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
|
||||
{
|
||||
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
|
||||
return $this->genAssocArray($db_array, $key, $value);
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbByteStringFormat
|
||||
// PARAMS: int
|
||||
// RETURN: string
|
||||
// DESC : converts bytes into formated string with KB, MB, etc
|
||||
/**
|
||||
* @deprecated
|
||||
* converts bytes into formated string with KB, MB, etc
|
||||
* @param string|int|float $number string or int or number
|
||||
* @return string formatted string
|
||||
*/
|
||||
public function adbByteStringFormat($number): string
|
||||
{
|
||||
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
|
||||
return $this->byteStringFormat($number);
|
||||
}
|
||||
|
||||
// REMARK: below function has moved to "Class.Basic"
|
||||
// METHOD: adbCreateThumbnail
|
||||
// PARAMS: id from picture where from we create a thumbnail
|
||||
// x -> max x size of thumbnail
|
||||
// y -> max y size of thumbnail
|
||||
// dummy -> if set to true, then if no images was found we show a dummy image
|
||||
// path -> if source start is not ROOT path, if empty ROOT is choosen
|
||||
// cache -> cache path, if not given TMP is used
|
||||
// RETURN: thumbnail name
|
||||
// DESC : converts picture to a thumbnail with max x and max y size
|
||||
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = false, $path = "", $cache = "")
|
||||
/**
|
||||
* @deprecated
|
||||
* converts picture to a thumbnail with max x and max y size
|
||||
* @param string $pic source image file with or without path
|
||||
* @param int $size_x maximum size width
|
||||
* @param int $size_y maximum size height
|
||||
* @param string $dummy empty, or file_type to show an icon instead of nothing if file is not found
|
||||
* @param string $path if source start is not ROOT path, if empty ROOT is choosen
|
||||
* @param string $cache_source cache path, if not given TMP is used
|
||||
* @return string|bool thumbnail name, or false for error
|
||||
*/
|
||||
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = '', $path = "", $cache = "")
|
||||
{
|
||||
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
|
||||
return $this->createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
|
||||
}
|
||||
|
||||
// METHOD: adbMsg
|
||||
// PARAMS: level -> info/warning/error
|
||||
// msg -> string, can be printf formated
|
||||
// var array -> optional data for a possible printf formated msg
|
||||
// RETURN: none
|
||||
// DESC : wrapper function to fill up the mssages array
|
||||
/**
|
||||
* wrapper function to fill up the mssages array
|
||||
* @param string $level info/warning/error
|
||||
* @param string $msg string, can be printf formated
|
||||
* @param array $vars optional data for a possible printf formated msg
|
||||
* @return void has no return
|
||||
*/
|
||||
public function adbMsg(string $level, string $msg, array $vars = array ()): void
|
||||
{
|
||||
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
|
||||
// type -> INSERT/UPDATE/DELETE
|
||||
// target -> target table to write to
|
||||
// data -> SQL part to write, this can include #KEY_VALUE#, #KEY_NAME# for delete sub queries
|
||||
// key_name -> key name, mostly used for update search
|
||||
// key_value -> data for the key
|
||||
// associate -> NULL for free, LOCK for first insert, group key for reference to first entry
|
||||
// file -> string for special file copy actions; mostyle "test#live;..."
|
||||
// RETURN: none
|
||||
// DESC : writes live queue
|
||||
/**
|
||||
* writes live queue
|
||||
* @param string $queue_key string to identfy the queue
|
||||
* @param string $type [description]
|
||||
* @param string $target [description]
|
||||
* @param string $data [description]
|
||||
* @param string $key_name [description]
|
||||
* @param string $key_value [description]
|
||||
* @param ?string $associate [description]
|
||||
* @param ?string $file [description]
|
||||
* @return void has no return
|
||||
*/
|
||||
public function adbLiveQueue(
|
||||
$queue_key,
|
||||
$type,
|
||||
$target,
|
||||
$data,
|
||||
$key_name,
|
||||
$key_value,
|
||||
$associate = null,
|
||||
$file = null
|
||||
) {
|
||||
$q = "INSERT INTO ".GLOBAL_DB_SCHEMA.".live_queue (";
|
||||
string $queue_key,
|
||||
string $type,
|
||||
string $target,
|
||||
string $data,
|
||||
string $key_name,
|
||||
string $key_value,
|
||||
string $associate = null,
|
||||
string $file = null
|
||||
): void {
|
||||
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 .= ") VALUES (";
|
||||
$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->queue_key."', '".$this->action."', '".$this->dbEscapeString($associate)."', ";
|
||||
$q .= "'".$this->dbEscapeString($file)."')";
|
||||
$this->db_exec($q);
|
||||
$this->dbExec($q);
|
||||
}
|
||||
|
||||
// METHOD: adbPrintDateTime
|
||||
// PARAMS: year, month, day, hour, min: the date and time values
|
||||
// suffix: additional info printed after the date time variable in the drop down,
|
||||
// also used for ID in the on change JS call
|
||||
// minute steps: can be 1 (default), 5, 10, etc, if invalid (outside 1h range,
|
||||
// it falls back to 1min)
|
||||
// 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: HTML formated strings for drop down lists of date and time
|
||||
// DESC : print the date/time drop downs, used in any queue/send/insert at date/time place
|
||||
// NOTE : Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||
// are translated in this call
|
||||
/**
|
||||
* Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||
* are translated in this call
|
||||
* @param int $year year YYYY
|
||||
* @param int $month month m
|
||||
* @param int $day day d
|
||||
* @param int $hour hour H
|
||||
* @param int $min min i
|
||||
* @param string $suffix additional info printed after the date time variable in the drop down
|
||||
* also used for ID in the on change JS call
|
||||
* @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
|
||||
* @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(
|
||||
$year,
|
||||
$month,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,14 +48,14 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
public $pk_name; // the primary key from this table
|
||||
public $pk_id; // the PK id
|
||||
|
||||
// METHOD: db_array_io
|
||||
// PARAMS: db_config -> db_io class init vars
|
||||
// table_array -> the array from the table
|
||||
// table_name -> name of the table (for the array)
|
||||
// set_control_flag -> set basic class set/get variable error flags
|
||||
// RETURN: none
|
||||
// DESC : constructor for the array io class, set the
|
||||
// primary key name automatically (from array)
|
||||
/**
|
||||
* constructor for the array io class, set the
|
||||
* primary key name automatically (from array)
|
||||
* @param array $db_config db connection config
|
||||
* @param array $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param int|integer $set_control_flag set basic class set/get variable error flags
|
||||
*/
|
||||
public function __construct(array $db_config, array $table_array, string $table_name, int $set_control_flag = 0)
|
||||
{
|
||||
// instance db_io class
|
||||
@@ -77,21 +77,23 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
} // set pk_name IF table_array was given
|
||||
}
|
||||
|
||||
// deconstruktor
|
||||
/**
|
||||
* class deconstructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// METHOD: convertData
|
||||
// WAS : convert_data
|
||||
// PARAMS: string -> the string that should be changed
|
||||
// RETURN: string -> the altered string
|
||||
// DESC : changes all previously alterd HTML code into visible one,
|
||||
// works for <b>,<i>, and <a> (thought <a> can be / or should
|
||||
// be handled with the magic links functions
|
||||
// used with the read function
|
||||
public function convertData($text)
|
||||
/**
|
||||
* changes all previously alterd HTML code into visible one,
|
||||
* works for <b>,<i>, and <a> (thought <a> can be / or should
|
||||
* be handled with the magic links functions
|
||||
* used with the read function
|
||||
* @param string $text any html encoded string
|
||||
* @return string decoded html string
|
||||
*/
|
||||
public function convertData($text): string
|
||||
{
|
||||
$text = str_replace('<b>', '<b>', $text);
|
||||
$text = str_replace('</b>', '</b>', $text);
|
||||
@@ -109,7 +111,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// PARAMS: string -> string to be changed
|
||||
// RETURN: string -> altered string
|
||||
// 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('<', '<', $text);
|
||||
$text = str_replace('>', '>', $text);
|
||||
@@ -119,12 +126,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
return $text;
|
||||
}
|
||||
|
||||
// METHOD: dbDumpArray
|
||||
// WAS : db_dump_array
|
||||
// PARAMS: none
|
||||
// RETURN: returns the current array
|
||||
// DESC : dumps the current data
|
||||
public function dbDumpArray($write = 0)
|
||||
/**
|
||||
* dumps the current data
|
||||
* @param bool $write write to error message, default false
|
||||
* @return string the array data as html string entry
|
||||
*/
|
||||
public function dbDumpArray($write = false): string
|
||||
{
|
||||
reset($this->table_array);
|
||||
$string = '';
|
||||
@@ -132,17 +139,16 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
$string .= '<b>'.$column.'</b> -> '.$data_array['value'].'<br>';
|
||||
}
|
||||
// add output to internal error_msg
|
||||
if ($write) {
|
||||
if ($write === true) {
|
||||
$this->error_msg['db'] .= $string;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
// METHOD: dbCheckPkSet
|
||||
// WAS : db_check_pk_set
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : checks if pk is set and if not, set from pk_id and if this also not set return 0
|
||||
/**
|
||||
* checks if pk is set and if not, set from pk_id and if this also not set return 0
|
||||
* @return bool true if pk value is set, else false
|
||||
*/
|
||||
public function dbCheckPkSet()
|
||||
{
|
||||
// if pk_id is set, overrule ...
|
||||
@@ -154,18 +160,18 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// if no PK found, error ...
|
||||
$this->error_id = 91;
|
||||
$this->__dbError();
|
||||
return 0;
|
||||
return false;
|
||||
} else {
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: dbResetArray
|
||||
// WAS : db_reset_array
|
||||
// PARAMS: reset_pk -> if set reset the pk too
|
||||
// RETURN: none
|
||||
// DESC : resets the whole array
|
||||
public function dbResetArray($reset_pk = 0)
|
||||
/**
|
||||
* resets the whole array values
|
||||
* @param boolean $reset_pk true if we want to reset the pk too
|
||||
* @return void has no return
|
||||
*/
|
||||
public function dbResetArray($reset_pk = false): void
|
||||
{
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
@@ -177,14 +183,16 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: dbDelete
|
||||
// WAS : db_delete
|
||||
// PARAMS: optional the table_array, if not given uses class var
|
||||
// RETURN: 1 for successfull delete or 0 for error
|
||||
// DESC : deletes one dataset
|
||||
public function dbDelete($table_array = 0)
|
||||
/**
|
||||
* deletes one dataset
|
||||
* @param array $table_array optional override for table array set
|
||||
* set this as new table array too
|
||||
* @return array returns the table array that was deleted
|
||||
*/
|
||||
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;
|
||||
}
|
||||
if (!$this->dbCheckPkSet()) {
|
||||
@@ -234,15 +242,16 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// METHOD: dbRead
|
||||
// WAS : db_read
|
||||
// PARAMS: edit -> if 1 data will not be altered for output, optional the table_array, if not given uses class var
|
||||
// RETURN: true or false for reading
|
||||
// DESC : reads one row into the array
|
||||
public function dbRead($edit = 0, $table_array = 0)
|
||||
/**
|
||||
* reads one row into the array
|
||||
* @param boolean $edit on true convert data, else as is
|
||||
* @param array $table_array optional table array, overwrites internal set array
|
||||
* @return array set table array with values
|
||||
*/
|
||||
public function dbRead($edit = false, $table_array = 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;
|
||||
}
|
||||
if (!$this->dbCheckPkSet()) {
|
||||
@@ -280,7 +289,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
if ($res = $this->dbFetchArray()) {
|
||||
reset($this->table_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
|
||||
// echo 'EDIT: $edit | Spalte: $column | type: '.$this->table_array[$column]['type'].' | Res: '.$res[$column].'<br>';
|
||||
if ($edit) {
|
||||
@@ -306,14 +315,15 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// METHOD: dbWrite
|
||||
// WAS : db_write
|
||||
// PARAMS: addslashes -> if 1 will make an addslashes for each array field, optional the table_array, if not given uses class var
|
||||
// RETURN: true or false on write
|
||||
// DESC : writes on set into DB or updates one set (if PK exists)
|
||||
public function dbWrite($addslashes = 0, $table_array = 0)
|
||||
/**
|
||||
* writes one set into DB or updates one set (if PK exists)
|
||||
* @param boolean $addslashes old convert entities and set set escape
|
||||
* @param array $table_array optional table array, overwrites internal one
|
||||
* @return array table array or null
|
||||
*/
|
||||
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;
|
||||
}
|
||||
// PK ID check
|
||||
@@ -524,68 +534,6 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// return the table if needed
|
||||
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__
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,19 +48,17 @@ class PgSQL
|
||||
private $last_error_query;
|
||||
private $dbh;
|
||||
|
||||
// METHOD: __construct
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : class constructor
|
||||
/**
|
||||
* class constructor, empty does nothing
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
// METHOD: __dbLastErrorQuery
|
||||
// WAS : _db_last_error_query
|
||||
// PARAMS: none
|
||||
// RETURN: true/false if last error is set
|
||||
// DESC : queries last error query and returns true or false if error was set
|
||||
/**
|
||||
* queries last error query and returns true or false if error was set
|
||||
* @return bool true/false if last error is set
|
||||
*/
|
||||
public function __dbLastErrorQuery()
|
||||
{
|
||||
if ($this->last_error_query) {
|
||||
@@ -70,12 +68,12 @@ class PgSQL
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbQuery
|
||||
// WAS : _db_query
|
||||
// PARAMS: query
|
||||
// RETURN: query result
|
||||
// DESC : wrapper for gp_query, catches error and stores it in class var
|
||||
public function __dbQuery($query)
|
||||
/**
|
||||
* wrapper for gp_query, catches error and stores it in class var
|
||||
* @param string $query query string
|
||||
* @return resource|bool query result
|
||||
*/
|
||||
public function __dbQuery(string $query)
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
// read out the query status and save the query if needed
|
||||
@@ -86,21 +84,20 @@ class PgSQL
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbSendQuery
|
||||
// WAS : _db_send_query
|
||||
// PARAMS: query
|
||||
// RETURN: true/false if query was sent successful
|
||||
// DESC : sends an async query to the server
|
||||
public function __dbSendQuery($query)
|
||||
/**
|
||||
* sends an async query to the server
|
||||
* @param string $query query string
|
||||
* @return bool true/false if query was sent successful
|
||||
*/
|
||||
public function __dbSendQuery(string $query): bool
|
||||
{
|
||||
return pg_send_query($this->dbh, $query);
|
||||
}
|
||||
|
||||
// METHOD: __dbGetResult
|
||||
// WAS : _db_get_result
|
||||
// PARAMS: none
|
||||
// RETURN: resource handler
|
||||
// DESC : wrapper for pg_get_result
|
||||
/**
|
||||
* wrapper for pg_get_result
|
||||
* @return resource|bool resource handler or false for error
|
||||
*/
|
||||
public function __dbGetResult()
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
@@ -111,12 +108,11 @@ class PgSQL
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbClose
|
||||
// WAS : _db_close
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : wrapper for pg_close
|
||||
public function __dbClose()
|
||||
/**
|
||||
* wrapper for pg_close
|
||||
* @return void has no return
|
||||
*/
|
||||
public function __dbClose(): void
|
||||
{
|
||||
if (is_resource($this->dbh)) {
|
||||
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
|
||||
@@ -125,12 +121,13 @@ class PgSQL
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbPrepare
|
||||
// WAS : _db_prepare
|
||||
// PARAMS: prepare name, query
|
||||
// RETURN: prepared statement handler
|
||||
// DESC : wrapper for pg_prepare
|
||||
public function __dbPrepare($name, $query)
|
||||
/**
|
||||
* wrapper for pg_prepare
|
||||
* @param string $name statement name
|
||||
* @param string $query query string
|
||||
* @return resource|bool prepare statement handler or false for error
|
||||
*/
|
||||
public function __dbPrepare(string $name, string $query)
|
||||
{
|
||||
$result = pg_prepare($this->dbh, $name, $query);
|
||||
if (!$result) {
|
||||
@@ -139,12 +136,13 @@ class PgSQL
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbExecute
|
||||
// WAS : _db_execute
|
||||
// PARAMS: prepare name, data for query
|
||||
// RETURN: returns status
|
||||
// DESC : wrapper for pg_execute for running a prepared statement
|
||||
public function __dbExecute($name, $data)
|
||||
/**
|
||||
* wrapper for pg_execute for running a prepared statement
|
||||
* @param string $name statement name
|
||||
* @param array $data data array
|
||||
* @return resource|bool returns status or false for error
|
||||
*/
|
||||
public function __dbExecute(string $name, array $data)
|
||||
{
|
||||
$result = pg_execute($this->dbh, $name, $data);
|
||||
if (!$result) {
|
||||
@@ -153,95 +151,94 @@ class PgSQL
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: __dbNumRows
|
||||
// WAS : _db_num_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: rows
|
||||
// DESC : wrapper for pg_num_rows
|
||||
public function __dbNumRows($cursor)
|
||||
/**
|
||||
* wrapper for pg_num_rows
|
||||
* @param resource $cursor cursor resource
|
||||
* @return int number of rows, -1 on error
|
||||
*/
|
||||
public function __dbNumRows($cursor): int
|
||||
{
|
||||
return pg_num_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbNumFields
|
||||
// WAS : _db_num_fields
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for fields in query
|
||||
// DESC : wrapper for pg_num_fields
|
||||
public function __dbNumFields($cursor)
|
||||
/**
|
||||
* wrapper for pg_num_fields
|
||||
* @param resource $cursor cursor resource
|
||||
* @return int number for fields in result, -1 on error
|
||||
*/
|
||||
public function __dbNumFields($cursor): int
|
||||
{
|
||||
return pg_num_fields($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbFieldName
|
||||
// WAS : _db_field_name
|
||||
// PARAMS: cursor, field position
|
||||
// RETURN: name of field
|
||||
// DESC : wrapper for pg_field_name
|
||||
/**
|
||||
* wrapper for pg_field_name
|
||||
* @param resource $cursor cursor resource
|
||||
* @param int $i field position
|
||||
* @return string|bool name or false on error
|
||||
*/
|
||||
public function __dbFieldName($cursor, $i)
|
||||
{
|
||||
return pg_field_name($cursor, $i);
|
||||
}
|
||||
|
||||
// METHOD: __dbFetchArray
|
||||
// WAS : _db_fetch_array
|
||||
// PARAMS: cursor, opt result type
|
||||
// RETURN: row
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
public function __dbFetchArray($cursor, $result_type = '')
|
||||
/**
|
||||
* wrapper for pg_fetch_array
|
||||
* if through/true false, use __dbResultType(true)
|
||||
* @param resource $cursor cursor resource
|
||||
* @param int $result_type result type as int number
|
||||
* @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]
|
||||
if ($result_type) {
|
||||
return pg_fetch_array($cursor, null, $result_type);
|
||||
} else {
|
||||
return pg_fetch_array($cursor);
|
||||
}
|
||||
return pg_fetch_array($cursor, null, $result_type);
|
||||
}
|
||||
|
||||
// METHOD: __dbResultType
|
||||
// PARAMS: true/false for ASSOC only or BOTH
|
||||
// RETURN: PGSQL assoc type
|
||||
// DESC : simple match up between assoc true/false
|
||||
public function __dbResultType($assoc_type)
|
||||
/**
|
||||
* simple match up between assoc true/false
|
||||
* @param bool $assoc_type true (default) for PGSQL_ASSOC, false for PGSQL_BOTH
|
||||
* @return int valid result type for fetch array
|
||||
*/
|
||||
public function __dbResultType(bool $assoc_type = true): int
|
||||
{
|
||||
if ($assoc_type == true) {
|
||||
return PGSQL_ASSOC;
|
||||
}
|
||||
return ''; // fallback to default
|
||||
// fallback to default
|
||||
return PGSQL_BOTH;
|
||||
}
|
||||
|
||||
// METHOD: __dbFetchAll
|
||||
// WAS : _db_fetch_all
|
||||
// PARAMS: cursor
|
||||
// RETURN: all rows as array
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
/**
|
||||
* wrapper for pg_fetch_all
|
||||
* @param resource $cursor cursor resource
|
||||
* @return array|bool data array or false for end/error
|
||||
*/
|
||||
public function __dbFetchAll($cursor)
|
||||
{
|
||||
return pg_fetch_all($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbAffectedRows
|
||||
// WAS : _db_affected_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for rows
|
||||
// DESC : wrapper for pg_affected_rows
|
||||
public function __dbAffectedRows($cursor)
|
||||
/**
|
||||
* wrapper for pg_affected_rows
|
||||
* @param resource $cursor cursor resource
|
||||
* @return int affected rows, 0 for none
|
||||
*/
|
||||
public function __dbAffectedRows($cursor): int
|
||||
{
|
||||
return pg_affected_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: __dbInsertId
|
||||
// WAS : _db_insert_id
|
||||
// PARAMS: query, primary key name
|
||||
// RETURN: last insert primary key
|
||||
// DESC : reads the last inserted primary key for the query
|
||||
// if ther is no pk_name tries to auto built it from the table name
|
||||
// this only works if db schema is after "no plural names. and pk name is table name + _id
|
||||
// detects schema prefix in table name
|
||||
public function __dbInsertId($query, $pk_name)
|
||||
/**
|
||||
* reads the last inserted primary key for the query
|
||||
* if there is no pk_name tries to auto built it from the table name
|
||||
* this only works if db schema is after "no plural names. and pk name is table name + _id
|
||||
* detects schema prefix in table name
|
||||
* @param string $query query string
|
||||
* @param string $pk_name primary key name, if '' then auto detect
|
||||
* @return string|int primary key value
|
||||
*/
|
||||
public function __dbInsertId(string $query, string $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
@@ -275,12 +272,13 @@ class PgSQL
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbPrimaryKey
|
||||
// WAS : _db_primary_key
|
||||
// PARAMS: table and optional schema
|
||||
// RETURN: primary key name OR false if not possible
|
||||
// DESC : queries database for the primary key name to this table in the selected schema
|
||||
public function __dbPrimaryKey($table, $schema = '')
|
||||
/**
|
||||
* queries database for the primary key name to this table in the selected schema
|
||||
* @param string $table table name
|
||||
* @param string $schema optional schema name, '' for default
|
||||
* @return string|bool primary key name or false if not found
|
||||
*/
|
||||
public function __dbPrimaryKey(string $table, string $schema = '')
|
||||
{
|
||||
if ($table) {
|
||||
// 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
|
||||
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
|
||||
// RETURN: database handler
|
||||
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
public function __dbConnect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
|
||||
/**
|
||||
* wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
* @param string $db_host host name
|
||||
* @param string $db_user user name
|
||||
* @param string $db_pass password
|
||||
* @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
|
||||
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);
|
||||
if (!$this->dbh) {
|
||||
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;
|
||||
}
|
||||
|
||||
// METHOD: __dbPrintError
|
||||
// WAS : _db_print_error
|
||||
// PARAMS: database handler, cursor
|
||||
// RETURN: error string (HTML)
|
||||
// DESC : reads the last error for this cursor
|
||||
public function __dbPrintError($cursor = '')
|
||||
/**
|
||||
* reads the last error for this cursor and returns
|
||||
* html formatted string with error name
|
||||
* @param ?resource $cursor cursor resource or null
|
||||
* @return string error string
|
||||
*/
|
||||
public function __dbPrintError($cursor = null): string
|
||||
{
|
||||
// run the query again for the error result here
|
||||
if (!$cursor && $this->last_error_query) {
|
||||
@@ -355,56 +360,71 @@ class PgSQL
|
||||
}
|
||||
if (pg_result_error($cursor)) {
|
||||
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: __dbMetaData
|
||||
// WAS : _db_meta_data
|
||||
// PARAMS: table name
|
||||
// RETURN: array with table data
|
||||
// DESC : wrapper for pg_emta_data
|
||||
public function __dbMetaData($table)
|
||||
/**
|
||||
* wrapper for pg_meta_data
|
||||
* @param string $table table name
|
||||
* @param bool $extended show extended info (default false)
|
||||
* @return array|bool array data for the table info or false on error
|
||||
*/
|
||||
public function __dbMetaData(string $table, $extended = false)
|
||||
{
|
||||
// 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
|
||||
// PARAMS: string
|
||||
// RETURN: escaped string for postgres
|
||||
// DESC : wrapper for pg_escape_string
|
||||
public function __dbEscapeString($string)
|
||||
/**
|
||||
* wrapper for pg_escape_string
|
||||
* @param string|int|float|bool $string any string/int/float/bool
|
||||
* @return string excaped string
|
||||
*/
|
||||
public function __dbEscapeString($string): string
|
||||
{
|
||||
return pg_escape_string($this->dbh, (string)$string);
|
||||
}
|
||||
|
||||
// METHOD: __dbEscapeBytea
|
||||
// WAS : _db_escape_bytea
|
||||
// PARAMS: string
|
||||
// RETURN: escape bytes for postgres
|
||||
// DESC : wrapper for pg_escape_bytea
|
||||
public function __dbEscapeBytea($bytea)
|
||||
/**
|
||||
* wrapper for pg_escape_literal
|
||||
* difference to escape string is that this one adds quotes ('') around
|
||||
* the string too
|
||||
* @param string|int|float|bool $string any string/int/float/bool
|
||||
* @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);
|
||||
}
|
||||
|
||||
// METHOD: __dbConnectionBusy
|
||||
// WAS : _db_connection_busy
|
||||
// PARAMS: none
|
||||
// RETURN: true/false for busy connection
|
||||
// DESC : wrapper for pg_connection_busy
|
||||
public function __dbConnectionBusy()
|
||||
/**
|
||||
* wrapper for pg_connection_busy
|
||||
* @return bool true/false for busy connection
|
||||
*/
|
||||
public function __dbConnectionBusy(): bool
|
||||
{
|
||||
return pg_connection_busy($this->dbh);
|
||||
}
|
||||
|
||||
// METHOD: __dbVersion
|
||||
// WAS : _db_version
|
||||
// PARAMS: none
|
||||
// RETURN: databse version
|
||||
// DESC : wrapper for pg_version
|
||||
public function __dbVersion()
|
||||
/**
|
||||
* wrapper for pg_version
|
||||
* Note: this only returns server version
|
||||
* not connection version OR client version
|
||||
* @return string version string
|
||||
*/
|
||||
public function __dbVersion(): string
|
||||
{
|
||||
// array has client, protocol, server
|
||||
// we just need the server
|
||||
@@ -412,13 +432,14 @@ class PgSQL
|
||||
return $v['server'];
|
||||
}
|
||||
|
||||
// METHOD: __dbArrayParse
|
||||
// WAS : _db_array_parse
|
||||
// PARAMS: input text, output array [needed]
|
||||
// [internal] limit: are we at the end of the parse
|
||||
// [internal] offset: shift for {}
|
||||
// RETURN: array with the elements
|
||||
// DESC : postgresql array to php array
|
||||
/**
|
||||
* postgresql array to php array
|
||||
* @param string $text array text from PostgreSQL
|
||||
* @param array &$output (internal) recursive pass on for nested arrays
|
||||
* @param bool|int $limit (internal) max limit to not overshoot the end, start with false
|
||||
* @param integer $offset (internal) shift offset for {}
|
||||
* @return array|int converted PHP array, interal recusrive int position
|
||||
*/
|
||||
public function __dbArrayParse($text, &$output, $limit = false, $offset = 1)
|
||||
{
|
||||
if (false === $limit) {
|
||||
|
||||
@@ -29,6 +29,10 @@ class FileReader
|
||||
public $fr_length;
|
||||
public $error = 0;
|
||||
|
||||
/**
|
||||
* file read constructor
|
||||
* @param string $filename file name to load
|
||||
*/
|
||||
public function __construct($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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
fseek($this->fr_fd, $pos);
|
||||
@@ -71,17 +85,29 @@ class FileReader
|
||||
return $this->fr_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current position in file
|
||||
* @return int current position in bytes
|
||||
*/
|
||||
public function currentpos()
|
||||
{
|
||||
return $this->fr_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* file length/size
|
||||
* @return int file size in bytes
|
||||
*/
|
||||
public function 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);
|
||||
}
|
||||
|
||||
@@ -26,29 +26,47 @@ namespace CoreLibs\Language\Core;
|
||||
// seek is essential, and it should be byte stream
|
||||
class StreamReader
|
||||
{
|
||||
/**
|
||||
* constructor, empty
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// should return new position
|
||||
/**
|
||||
* should return new position
|
||||
* @param int $position seek to position
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function seekto($position)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// returns current position
|
||||
/**
|
||||
* returns current position
|
||||
* @return bool dummy false
|
||||
*/
|
||||
public function currentpos()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -27,12 +27,21 @@ class StringReader
|
||||
public $sr_pos;
|
||||
public $sr_str;
|
||||
|
||||
/**
|
||||
* constructor for string reader
|
||||
* @param string $str basic string
|
||||
*/
|
||||
public function __construct($str = '')
|
||||
{
|
||||
$this->sr_str = $str;
|
||||
$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)
|
||||
{
|
||||
$data = substr($this->sr_str, $this->sr_pos, $bytes);
|
||||
@@ -44,6 +53,11 @@ class StringReader
|
||||
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)
|
||||
{
|
||||
$this->sr_pos = $pos;
|
||||
@@ -53,11 +67,19 @@ class StringReader
|
||||
return $this->sr_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current position in string
|
||||
* @return int position in string
|
||||
*/
|
||||
public function currentpos()
|
||||
{
|
||||
return $this->sr_pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* get length of string
|
||||
* @return int return length of assigned string
|
||||
*/
|
||||
public function length()
|
||||
{
|
||||
return strlen($this->sr_str);
|
||||
|
||||
@@ -35,6 +35,12 @@ class L10n extends \CoreLibs\Basic
|
||||
private $input;
|
||||
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)
|
||||
{
|
||||
parent::__construct($set_control_flag);
|
||||
@@ -60,7 +66,12 @@ class L10n extends \CoreLibs\Basic
|
||||
$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
|
||||
{
|
||||
$success = false;
|
||||
@@ -90,27 +101,52 @@ class L10n extends \CoreLibs\Basic
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
return $this->l10n->ngettext($single, $plural, $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set language
|
||||
* @return string current set language string
|
||||
*/
|
||||
public function __getLang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set mo file
|
||||
* @return string current set mo language file
|
||||
*/
|
||||
public function __getMoFile()
|
||||
{
|
||||
return $this->mofile;
|
||||
|
||||
@@ -248,11 +248,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// now some default error msgs (english)
|
||||
public $language_array = array ();
|
||||
|
||||
// METHOD: constructor
|
||||
// PARAMS: $db_config -> connect to DB
|
||||
// $lang -> language code ('en', 'ja', etc)
|
||||
// $table_width -> width of table
|
||||
// $set_control_flag -> basic class set/get variable error flags
|
||||
/**
|
||||
* construct form generator
|
||||
* @param array $db_config db config array
|
||||
* @param string $lang interface language
|
||||
* @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)
|
||||
{
|
||||
$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'];
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
if (!is_array($this->table_array)) {
|
||||
@@ -349,45 +365,38 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
return $string;
|
||||
}
|
||||
|
||||
// dekonstruktor
|
||||
// writes out error msg to global var
|
||||
// closes db connection
|
||||
public function __destruct()
|
||||
{
|
||||
// close DB connection
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// 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 = '')
|
||||
/**
|
||||
* the value of the $want_key array field
|
||||
* works only with fields that appear only ONCE
|
||||
* if multiple gets only FIRST
|
||||
* @param string $want_key key to search for
|
||||
* @param string|null $key_value value to match to (optional)
|
||||
* @return string|null returns key found or empty string
|
||||
*/
|
||||
public function formGetColNameFromKey(string $want_key, ?string $key_value = null): ?string
|
||||
{
|
||||
if (!is_array($this->table_array)) {
|
||||
$this->table_array = array ();
|
||||
}
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $key => $value) {
|
||||
if (isset($value[$want_key]) && !isset($key_value)) {
|
||||
if (isset($value[$want_key]) && !$key_value) {
|
||||
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 nothing on nothing
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
// METHOD: formGetColNameArrayFromKey
|
||||
// WAS : form_get_col_name_array_from_key
|
||||
// PARAMS: $want_key: the key where u want the data from
|
||||
// $key_value: if set searches for special right value
|
||||
// RETURN: array of fields
|
||||
public function formGetColNameArrayFromKey($want_key, $key_value = '')
|
||||
/**
|
||||
* array of fields
|
||||
* @param string $want_key the key where you want the data from
|
||||
* @param string|null $key_value if set searches for special right value
|
||||
* @return array found key fields
|
||||
*/
|
||||
public function formGetColNameArrayFromKey(string $want_key, ?string $key_value = null): array
|
||||
{
|
||||
$key_array = array();
|
||||
if (!is_array($this->table_array)) {
|
||||
@@ -405,11 +414,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
return $key_array;
|
||||
}
|
||||
|
||||
// METHOD: formPrintMsg
|
||||
// WAS : form_print_msg
|
||||
// PARAMS: none
|
||||
// RETURN: formated output for the error && warning msg
|
||||
public function formPrintMsg()
|
||||
/**
|
||||
* formated output for the error && warning msg
|
||||
* @return array error message with msg, width, clas
|
||||
*/
|
||||
public function formPrintMsg(): array
|
||||
{
|
||||
$class = '';
|
||||
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
|
||||
// METHOD: formProcedureLoad
|
||||
// WAS : form_procedure_load
|
||||
// PARAMS: archive_id - which ID should be loaded
|
||||
// RETURN: none
|
||||
// DESC : default load procedure
|
||||
public function formProcedureLoad($archive_id)
|
||||
/**
|
||||
* default load procedure
|
||||
* @param int $archive_id archive id to load
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formProcedureLoad(int $archive_id): void
|
||||
{
|
||||
if ($this->archive && $archive_id && $this->base_acl_level >= $this->security_level['load']) {
|
||||
$this->formLoadTableArray($archive_id);
|
||||
@@ -439,12 +448,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: formProcedureNew
|
||||
// WAS : form_procedure_new
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : default new procedure
|
||||
public function formProcedureNew()
|
||||
/**
|
||||
* default new procedure
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formProcedureNew(): void
|
||||
{
|
||||
if ($this->new && $this->base_acl_level >= $this->security_level['new']) {
|
||||
if ($this->really_new == 'yes') {
|
||||
@@ -457,12 +465,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: formProcedureSave
|
||||
// WAS : form_procedure_save
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : default save procedure
|
||||
public function formProcedureSave()
|
||||
/**
|
||||
* default save procedure
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formProcedureSave(): void
|
||||
{
|
||||
if ($this->save && $this->base_acl_level >= $this->security_level['save']) {
|
||||
$this->formErrorCheck();
|
||||
@@ -473,12 +480,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: formProcedureDelete
|
||||
// WAS : form_procedure_delete
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : default delete procedure
|
||||
public function formProcedureDelete()
|
||||
/**
|
||||
* default delete procedure
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formProcedureDelete(): void
|
||||
{
|
||||
// delete is also by 'protected'
|
||||
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
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : default delete procedure
|
||||
public function formProcedureDeleteFromElementList($element_list, $remove_name)
|
||||
/**
|
||||
* default delete procedure
|
||||
* @param array $element_list element array that should be removed
|
||||
* @param array $remove_name key names that should be removed
|
||||
* @return void has no return
|
||||
*/
|
||||
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', '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
|
||||
// PARAMS: none
|
||||
// RETURN: string from 'load' part of form ...
|
||||
public function formCreateLoad()
|
||||
/**
|
||||
* create the load list and return it as an array
|
||||
* @return array load list array with primary key, name and selected entry
|
||||
*/
|
||||
public function formCreateLoad(): array
|
||||
{
|
||||
$pk_selected = '';
|
||||
$t_pk_name = '';
|
||||
@@ -627,11 +634,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
);
|
||||
}
|
||||
|
||||
// METHOD: formCreateNew
|
||||
// WAS : form_create_new
|
||||
// PARAMS: none
|
||||
// RETURN: part for new
|
||||
public function formCreateNew($hide_new_checkbox = 0)
|
||||
/**
|
||||
* Create new entry element for HTML output
|
||||
* @param bool $hide_new_checkbox show or hide the new checkbox, default is false
|
||||
* @return array return the new create array with name & checkbox show flag
|
||||
*/
|
||||
public function formCreateNew($hide_new_checkbox = false): array
|
||||
{
|
||||
$show_checkbox = 0;
|
||||
$new_name = '';
|
||||
@@ -653,11 +661,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
);
|
||||
}
|
||||
|
||||
// METHOD: formCreateSaveDelete
|
||||
// WAS : form_create_save_delete
|
||||
// PARAMS: none
|
||||
// RETURN: string for delete / save part
|
||||
public function formCreateSaveDelete($hide_delete = 0, $hide_delete_checkbox = 0)
|
||||
/**
|
||||
* create the save and delete element html group data
|
||||
* @param bool $hide_delete hide the delete button (default false)
|
||||
* @param bool $hide_delete_checkbox hide the delete checkbox (default false)
|
||||
* @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;
|
||||
$save = '';
|
||||
@@ -699,14 +709,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
);
|
||||
} // end of function
|
||||
|
||||
// METHOD: formCreateElement
|
||||
// WAS : form_create_element
|
||||
// PARAMS: $element_name: the name from the array, you want to have build
|
||||
// $query: can overrule internal query data,
|
||||
// for drop down, as data comes from a reference table
|
||||
// for drop_down_text it has to be an array with $key->$value
|
||||
// RETURN: element in HTML
|
||||
public function formCreateElement($element_name, $query = '')
|
||||
/**
|
||||
* create a form element based on the settings in the element array entry
|
||||
* @param string $element_name the name from the array, you want to have build
|
||||
* @param string|null $query can overrule internal query data,
|
||||
* for drop down, as data comes from a reference table
|
||||
* for drop_down_text it has to be an array with $key->$valu
|
||||
* @return array html settings array
|
||||
*/
|
||||
public function formCreateElement(string $element_name, ?string $query = null): array
|
||||
{
|
||||
// special 2nd color for 'binary' attribut
|
||||
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'];
|
||||
}
|
||||
}
|
||||
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
|
||||
// PARAMS: none
|
||||
// RETURN: full error message string for output
|
||||
// should be cought like this ...
|
||||
// if ($msg=$form->form_error_check())
|
||||
// $error=1;
|
||||
public function formErrorCheck()
|
||||
/**
|
||||
* full error message string for output
|
||||
* checks each filled entry to the table array defined error checks
|
||||
* should be cought like this ...
|
||||
* if ($msg = $form->form_error_check())
|
||||
* $error=1;
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formErrorCheck(): void
|
||||
{
|
||||
if (!is_array($this->table_array)) {
|
||||
$this->table_array = array ();
|
||||
@@ -1170,12 +1187,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: formSetOrder
|
||||
// WAS: form_set_order
|
||||
// PARAMS: none
|
||||
// RETURN: the table array
|
||||
// DESC : sets the order to the maximum, if order flag is set in array
|
||||
public function formSetOrder()
|
||||
/**
|
||||
* sets the order to the maximum, if order flag is set in array
|
||||
* @return array table array with set order number
|
||||
*/
|
||||
public function formSetOrder(): array
|
||||
{
|
||||
// get order name
|
||||
$order_name = $this->formGetColNameFromKey('order');
|
||||
@@ -1198,12 +1214,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
return $this->table_array;
|
||||
}
|
||||
|
||||
// METHOD: formUnsetTableArray
|
||||
// WAS : form_unsert_table_array
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : resets all values in table_array and in the reference tables
|
||||
public function formUnsetTableArray()
|
||||
/**
|
||||
* resets all values in table_array and in the reference tables
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formUnsetTableArray(): void
|
||||
{
|
||||
unset($this->pk_id);
|
||||
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!');
|
||||
}
|
||||
|
||||
// METHOD: formLoadTableArray
|
||||
// WAS : form_load_table_array
|
||||
// PARAMS: pk_id - overrule pk_id
|
||||
// RETURN: none
|
||||
// DESC : load a table & reference
|
||||
public function formLoadTableArray($pk_id = 0)
|
||||
/**
|
||||
* load a table & reference
|
||||
* @param int|null $pk_id overrule pk_id
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formLoadTableArray(?int $pk_id = null): void
|
||||
{
|
||||
if ($pk_id) {
|
||||
$this->pk_id = $pk_id;
|
||||
}
|
||||
$this->table_array = $this->dbRead(1);
|
||||
$this->table_array = $this->dbRead(true);
|
||||
|
||||
// reset all temp fields
|
||||
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>');
|
||||
}
|
||||
|
||||
// METHOD: formSaveTableArray
|
||||
// WAS : form_save_table_array
|
||||
// PARAMS: addslashes - if one, passes 1 to the db_write function
|
||||
// RETURN: none
|
||||
// DESC : save a table, reference and all input fields
|
||||
public function formSaveTableArray($addslashes = 0)
|
||||
/**
|
||||
* save a table, reference and all input fields
|
||||
* note that the addslashes flag here is passed on to the dbWrite method
|
||||
* it only does html conversion, add slashes for DB is done automatically
|
||||
* @param bool $addslashes override internal addslasahes flag (default false)
|
||||
* @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 ...
|
||||
// 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);
|
||||
}
|
||||
|
||||
// METHOD: formCreateElementListTable
|
||||
// WAS : form_create_element_list_table
|
||||
// PARAMS: show which element list
|
||||
// RETURN: array for output
|
||||
// DESC : create list of elements next to each other for a group of data in an input field
|
||||
// this currently only works for a list that is filled from a sub table and creates only a connection to this one
|
||||
// new version will allow a sub list with free input fields to directly fill a sub table to a master table
|
||||
public function formCreateElementListTable($table_name)
|
||||
/**
|
||||
* create list of elements next to each other for a group of data in an input field
|
||||
* this currently only works for a list that is filled from a sub table and creates
|
||||
* only a connection to this one new version will allow a sub list with free input
|
||||
* fields to directly fill a sub table to a master table
|
||||
* @param string $table_name which element entry to create
|
||||
* @return array element for html creation
|
||||
*/
|
||||
public function formCreateElementListTable(string $table_name): array
|
||||
{
|
||||
// output name for the viewable left table td box, prefixed with * if mandatory
|
||||
$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
|
||||
// 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']);
|
||||
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] : '-'));
|
||||
|
||||
@@ -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);
|
||||
if ($width > 0) {
|
||||
@@ -90,7 +94,12 @@ class ProgressBar
|
||||
|
||||
// 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) {
|
||||
$clear_buffer_size = $this->clear_buffer_size;
|
||||
@@ -100,7 +109,12 @@ class ProgressBar
|
||||
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
|
||||
if ($this->max - $this->min == 0) {
|
||||
@@ -113,7 +127,12 @@ class ProgressBar
|
||||
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;
|
||||
switch ($this->direction) {
|
||||
@@ -168,7 +187,12 @@ class ProgressBar
|
||||
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) {
|
||||
$step = $this->max;
|
||||
@@ -180,7 +204,13 @@ class ProgressBar
|
||||
}
|
||||
|
||||
// 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 (
|
||||
'show' => true,
|
||||
@@ -201,7 +231,15 @@ class ProgressBar
|
||||
}
|
||||
}
|
||||
|
||||
public function addLabel($type, $name, $value = ' ')
|
||||
/**
|
||||
* 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 = ' '): void
|
||||
{
|
||||
switch ($type) {
|
||||
case 'text':
|
||||
@@ -276,7 +314,6 @@ class ProgressBar
|
||||
'color' => '#000000',
|
||||
'bgr_color' => ''
|
||||
);
|
||||
// print "THIS[$name]: ".$this->label[$name]['left']." | ".$this->label[$name]['width']."<br>";
|
||||
break;
|
||||
case 'crossbar':
|
||||
$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->label[$name]['action'] = $action;
|
||||
$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>";
|
||||
// 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;
|
||||
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;
|
||||
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
|
||||
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;
|
||||
// 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;
|
||||
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;
|
||||
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;
|
||||
|
||||
@@ -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 = '';
|
||||
$js = '';
|
||||
@@ -582,14 +682,24 @@ class ProgressBar
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function show()
|
||||
/**
|
||||
* show the progress bar after initialize
|
||||
* @return void has no return
|
||||
*/
|
||||
public function show(): void
|
||||
{
|
||||
$this->status = 'show';
|
||||
echo $this->getHtml();
|
||||
$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;
|
||||
$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);
|
||||
}
|
||||
|
||||
public function moveMin()
|
||||
/**
|
||||
* moves the progress bar back to the beginning
|
||||
* @return void has no return
|
||||
*/
|
||||
public function moveMin(): void
|
||||
{
|
||||
$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') {
|
||||
$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') {
|
||||
$this->status = 'show';
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
<?php declare(strict_types=1);
|
||||
// because smarty is symlinked folder
|
||||
/**
|
||||
* @phan-file-suppress PhanRedefinedExtendedClass
|
||||
*/
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2004/12/21
|
||||
@@ -20,6 +25,12 @@ class SmartyExtend extends SmartyBC
|
||||
public $l10n;
|
||||
|
||||
// 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)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
Reference in New Issue
Block a user