phpan/phpstan clean up runs, minor update to DB\IO
DB\IO dbReturn method has a third parameter to set read only assoc and not number data from the query Install basic composer for trying out psalm setting phpan/phpstan for basic static checking and do basic clean up on all of the files
This commit is contained in:
@@ -120,7 +120,8 @@ class Login extends \CoreLibs\DB\IO
|
||||
$this->log_per_class = 1;
|
||||
|
||||
// create db connection and init base class
|
||||
if (!parent::__construct($db_config, $set_control_flag)) {
|
||||
parent::__construct($db_config, $set_control_flag);
|
||||
if ($this->db_init_error === false) {
|
||||
echo 'Could not connect to DB<br>';
|
||||
// if I can't connect to the DB to auth exit hard. No access allowed
|
||||
exit;
|
||||
@@ -365,7 +366,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$q .= "(LOWER(username) = '".$this->dbEscapeString(strtolower($this->username))."') ";
|
||||
$res = $this->dbReturn($q);
|
||||
// username is wrong, but we throw for wrong username and wrong password the same error
|
||||
if (!$this->cursor_ext[md5($q)]["num_rows"]) {
|
||||
if (!$this->cursor_ext[md5($q)]['num_rows']) {
|
||||
$this->login_error = 1010;
|
||||
} else {
|
||||
// if login errors is half of max errors and the last login error was less than 10s ago, forbid any new login try
|
||||
@@ -422,8 +423,9 @@ class Login extends \CoreLibs\DB\IO
|
||||
$q .= "WHERE edit_user_id = ".$res['edit_user_id'];
|
||||
$this->dbExec($q);
|
||||
}
|
||||
$pages = array();
|
||||
$edit_page_ids = array();
|
||||
$pages = array();
|
||||
$pages_acl = array ();
|
||||
// set pages access
|
||||
$q = "SELECT ep.edit_page_id, ep.cuid, epca.cuid AS content_alias_uid, ep.filename, ep.name AS edit_page_name, ep.order_number AS edit_page_order, ep.menu, ";
|
||||
$q .= "ep.popup, ep.popup_x, ep.popup_y, ep.online, ear.level, ear.type ";
|
||||
@@ -804,8 +806,12 @@ class Login extends \CoreLibs\DB\IO
|
||||
{
|
||||
if ($this->change_password) {
|
||||
$event = 'Password Change';
|
||||
$data = '';
|
||||
// check that given username is NOT in the deny list, else silent skip (with error log)
|
||||
if (!in_array($this->pw_username, $this->pw_change_deny_users)) {
|
||||
// init the edit user id variable
|
||||
$edit_user_id = '';
|
||||
// cehck if either username or old password is not set
|
||||
if (!$this->pw_username || !$this->pw_old_password) {
|
||||
$this->login_error = 200;
|
||||
$data = 'Missing username or old password.';
|
||||
@@ -852,7 +858,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
}
|
||||
}
|
||||
// no error change this users password
|
||||
if (!$this->login_error) {
|
||||
if (!$this->login_error && $edit_user_id) {
|
||||
// update the user (edit_user_id) with the new password
|
||||
$q = "UPDATE edit_user SET password = '".$this->dbEscapeString($this->passwordSet($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id;
|
||||
$this->dbExec($q);
|
||||
@@ -883,7 +889,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
if ($AJAX_PAGE === true) {
|
||||
$data = array (
|
||||
'status' => 'error',
|
||||
'error_code' => $this->loging_error,
|
||||
'error_code' => $this->login_error,
|
||||
'msg' => array (
|
||||
'level' => 'error',
|
||||
'str' => $this->l->__('Login necessary')
|
||||
|
||||
@@ -67,7 +67,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
public $COMPILE_ID;
|
||||
public $includes;
|
||||
public $template_path;
|
||||
public $lang_dir;
|
||||
public $lang_dir = '';
|
||||
public $javascript;
|
||||
public $css;
|
||||
public $pictures;
|
||||
@@ -124,6 +124,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
// DESC : writes all action vars plus other info into edit_log table
|
||||
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING')
|
||||
{
|
||||
$data_binary = '';
|
||||
if ($write_type == 'BINARY') {
|
||||
$data_binary = $this->dbEscapeBytea(bzcompress(serialize($data)));
|
||||
$data = 'see bzip compressed data_binary field';
|
||||
@@ -140,7 +141,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$q .= "VALUES ";
|
||||
$q .= "(".$this->dbEscapeString(isset($_SESSION['EUID']) ? $_SESSION['EUID'] : '').", ";
|
||||
$q .= "NOW(), ";
|
||||
$q .= "'".$this->dbEscapeString($event)."', '".$data."', '".$data_binary."', '".$this->dbEscapeString($this->page_name)."', ";
|
||||
$q .= "'".$this->dbEscapeString((string)$event)."', '".$data."', '".$data_binary."', '".$this->dbEscapeString($this->page_name)."', ";
|
||||
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->dbEscapeString(@$_SERVER['HTTP_USER_AGENT'])."', ";
|
||||
$q .= "'".$this->dbEscapeString(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '')."', ";
|
||||
$q .= "'".$this->dbEscapeString(isset($_SERVER['SCRIPT_FILENAME']) ? $_SERVER['SCRIPT_FILENAME'] : '')."', ";
|
||||
@@ -177,6 +178,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
if (!isset($PAGES) || !is_array($PAGES)) {
|
||||
$PAGES = array ();
|
||||
}
|
||||
$pages = array ();
|
||||
foreach ($PAGES as $PAGE_CUID => $PAGE_DATA) {
|
||||
$pages[] = $PAGE_DATA;
|
||||
}
|
||||
@@ -209,7 +211,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$pages[$i]['popup'] = 0;
|
||||
}
|
||||
$query_string = '';
|
||||
if (count($pages[$i]['query'])) {
|
||||
if (isset($pages[$i]['query']) && count($pages[$i]['query'])) {
|
||||
for ($j = 0, $jMax = count($pages[$i]['query']); $j < $jMax; $j ++) {
|
||||
if (strlen($query_string)) {
|
||||
$query_string .= '&';
|
||||
@@ -318,7 +320,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$level = "info";
|
||||
}
|
||||
$this->messages[] = array (
|
||||
'msg' => sprintf($this->l->__($msg), $vars),
|
||||
'msg' => vsprintf($this->l->__($msg), $vars),
|
||||
'class' => $level
|
||||
);
|
||||
switch ($level) {
|
||||
|
||||
@@ -111,9 +111,9 @@ class Basic
|
||||
public $host_name;
|
||||
public $host_port;
|
||||
// internal error reporting vars
|
||||
private $error_id; // error ID for errors in classes
|
||||
private $error_string; // error strings in classes (for error_id)
|
||||
private $error_msg = array (); // the "connection" to the outside errors
|
||||
protected $error_id; // error ID for errors in classes
|
||||
protected $error_msg = array (); // the "connection" to the outside errors
|
||||
// debug output prefix
|
||||
public $error_msg_prefix = ''; // prefix to the error string (the class name)
|
||||
// debug flags
|
||||
public $debug_output; // if this is true, show debug on desconstructor
|
||||
@@ -126,7 +126,7 @@ class Basic
|
||||
public $print_output_not;
|
||||
public $print_output_all;
|
||||
// debug flags/settings
|
||||
public $debug_fp = ''; // filepointer for writing to file
|
||||
public $debug_fp; // filepointer for writing to file
|
||||
public $debug_filename = 'debug_file.log'; // where to write output
|
||||
public $hash_algo = 'crc32b'; // the hash algo used for the internal debug uid
|
||||
public $running_uid = ''; // unique ID set on class init and used in logging as prefix
|
||||
@@ -137,10 +137,10 @@ class Basic
|
||||
private $log_file_unique_id; // a unique ID set only once for call derived from this class
|
||||
public $log_print_file_date = 1; // if set add Y-m-d and do automatic daily rotation
|
||||
private $log_file_id = ''; // a alphanumeric name that has to be set as global definition
|
||||
public $log_per_level = 0; // set, it will split per level (first parameter in debug call)
|
||||
public $log_per_class = 0; // set, will split log per class
|
||||
public $log_per_page = 0; // set, will split log per called file
|
||||
public $log_per_run = 0; // create a new log file per run (time stamp + unique ID)
|
||||
public $log_per_level = false; // set, it will split per level (first parameter in debug call)
|
||||
public $log_per_class = false; // set, will split log per class
|
||||
public $log_per_page = false; // set, will split log per called file
|
||||
public $log_per_run = false; // create a new log file per run (time stamp + unique ID)
|
||||
// run time messurements
|
||||
private $starttime; // start time if time debug is used
|
||||
private $endtime; // end time if time debug is used
|
||||
@@ -200,7 +200,7 @@ class Basic
|
||||
'UPLOADS', 'CSV', 'JS', 'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES', 'TEMPLATES_C',
|
||||
'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
|
||||
'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE', 'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY',
|
||||
'PAGE_WIDTH', 'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA', 'LIVE_SCHEMA', 'LOGIN_DB', 'MAIN_DB', 'DB_SCHEMA',
|
||||
'PAGE_WIDTH', 'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA', 'LIVE_SCHEMA', 'DB_CONFIG_NAME', 'DB_CONFIG', 'DB_SCHEMA',
|
||||
'LOGIN_DB_SCHEMA', 'GLOBAL_DB_SCHEMA', 'TARGET', 'DEBUG', 'SHOW_ALL_ERRORS'
|
||||
) as $constant) {
|
||||
if (!defined($constant)) {
|
||||
@@ -237,27 +237,27 @@ class Basic
|
||||
|
||||
// if given via parameters, only for all
|
||||
$this->debug_output_all = false;
|
||||
$this->echo_output_all = true;
|
||||
$this->echo_output_all = false;
|
||||
$this->print_output_all = false;
|
||||
// globals overrule given settings, for one (array), eg $ECHO['db'] = 1;
|
||||
if (isset($GLOBALS['DEBUG'])) {
|
||||
if (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) {
|
||||
$this->debug_output = $GLOBALS['DEBUG'];
|
||||
}
|
||||
if (isset($GLOBALS['ECHO'])) {
|
||||
if (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) {
|
||||
$this->echo_output = $GLOBALS['ECHO'];
|
||||
}
|
||||
if (isset($GLOBALS['PRINT'])) {
|
||||
if (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) {
|
||||
$this->print_output = $GLOBALS['PRINT'];
|
||||
}
|
||||
|
||||
// exclude these ones from output
|
||||
if (isset($GLOBALS['DEBUG_NOT'])) {
|
||||
if (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) {
|
||||
$this->debug_output_not = $GLOBALS['DEBUG_NOT'];
|
||||
}
|
||||
if (isset($GLOBALS['ECHO_NOT'])) {
|
||||
if (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) {
|
||||
$this->echo_output_not = $GLOBALS['ECHO_NOT'];
|
||||
}
|
||||
if (isset($GLOBALS['PRINT_NOT'])) {
|
||||
if (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) {
|
||||
$this->print_output_not = $GLOBALS['PRINT_NOT'];
|
||||
}
|
||||
|
||||
@@ -374,6 +374,11 @@ class Basic
|
||||
// set the session name for possible later check
|
||||
$this->session_name = SET_SESSION_NAME;
|
||||
}
|
||||
// override with global if set
|
||||
if (isset($GLOBALS['SET_SESSION_NAME'])) {
|
||||
$this->session_name = $GLOBALS['SET_SESSION_NAME'];
|
||||
}
|
||||
// if set, set special session name
|
||||
if ($this->session_name) {
|
||||
session_name($this->session_name);
|
||||
}
|
||||
@@ -484,13 +489,10 @@ class Basic
|
||||
// must be alphanumeric only (\w)
|
||||
public function basicSetLogId(string $string): string
|
||||
{
|
||||
if (!isset($log_file_id)) {
|
||||
$log_file_id = '';
|
||||
}
|
||||
if (isset($string) && preg_match("/^\w+$/", $string)) {
|
||||
if (preg_match("/^\w+$/", $string)) {
|
||||
$this->log_file_id = $string;
|
||||
}
|
||||
return $log_file_id;
|
||||
return $this->log_file_id;
|
||||
}
|
||||
|
||||
// ****** DEBUG/ERROR FUNCTIONS ******
|
||||
@@ -595,7 +597,7 @@ class Basic
|
||||
$string .= substr($microtime, 1);
|
||||
} elseif ($set_microtime >= 1) {
|
||||
// in round case we run this through number format to always get the same amount of digits
|
||||
$string .= substr(number_format(round($microtime, $set_microtime), $set_microtime), 1);
|
||||
$string .= substr(number_format(round((float)$microtime, $set_microtime), $set_microtime), 1);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
@@ -888,8 +890,7 @@ class Basic
|
||||
// DESC : validates they key length
|
||||
private function validateRandomKeyLenght(int $key_length): bool
|
||||
{
|
||||
if (isset($key_length) &&
|
||||
is_numeric($key_length) &&
|
||||
if (is_numeric($key_length) &&
|
||||
$key_length > 0 &&
|
||||
$key_length <= $this->max_key_length
|
||||
) {
|
||||
@@ -1146,11 +1147,15 @@ class Basic
|
||||
// only returns the first one found
|
||||
public static function arraySearchRecursive($needle, array $haystack, $key_lookin = ''): ?array
|
||||
{
|
||||
$path = null;
|
||||
$path = array ();
|
||||
if (!is_array($haystack)) {
|
||||
$haystack = array();
|
||||
}
|
||||
if (!is_array($key_lookin) && !empty($key_lookin) && array_key_exists($key_lookin, $haystack) && $needle === $haystack[$key_lookin]) {
|
||||
if (!is_array($key_lookin) &&
|
||||
!empty($key_lookin) &&
|
||||
array_key_exists($key_lookin, $haystack) &&
|
||||
$needle === $haystack[$key_lookin]
|
||||
) {
|
||||
$path[] = $key_lookin;
|
||||
} else {
|
||||
foreach ($haystack as $key => $val) {
|
||||
@@ -1184,7 +1189,7 @@ class Basic
|
||||
if (!isset($path['work'])) {
|
||||
$path['work'] = array ();
|
||||
}
|
||||
if (!isset($haystack)) {
|
||||
if (!is_array($haystack)) {
|
||||
$haystack = array ();
|
||||
}
|
||||
|
||||
@@ -1461,7 +1466,7 @@ class Basic
|
||||
// labels in order of size
|
||||
$labels = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
|
||||
// calc file size, round down too two digits, add label based max change
|
||||
return round($number / pow(1024, ($i = floor(log($number, 1024)))), 2).($space ? ' ' : '').(isset($labels[$i]) ? $labels[$i] : '>EB');
|
||||
return round($number / pow(1024, ($i = floor(log($number, 1024)))), 2).($space ? ' ' : '').(isset($labels[(int)$i]) ? $labels[(int)$i] : '>EB');
|
||||
}
|
||||
return (string)$number;
|
||||
}
|
||||
@@ -1527,7 +1532,7 @@ class Basic
|
||||
public static function dateStringFormat($timestamp, bool $show_micro = true): string
|
||||
{
|
||||
list ($timestamp, $ms) = explode('.', (string)round($timestamp, 4));
|
||||
$string = date("Y-m-d H:i:s", $timestamp);
|
||||
$string = date("Y-m-d H:i:s", (int)$timestamp);
|
||||
if ($show_micro) {
|
||||
$string .= ' '.$ms.'ms';
|
||||
}
|
||||
@@ -1549,8 +1554,8 @@ class Basic
|
||||
$labels = array ('d', 'h', 'm', 's');
|
||||
$time_string = '';
|
||||
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i ++) {
|
||||
$output = floor($timestamp / $timegroups[$i]);
|
||||
$timestamp = $timestamp % $timegroups[$i];
|
||||
$output = floor((float)$timestamp / $timegroups[$i]);
|
||||
$timestamp = (float)$timestamp % $timegroups[$i];
|
||||
// output has days|hours|min|sec
|
||||
if ($output || $time_string) {
|
||||
$time_string .= $output.$labels[$i].(($i + 1) != count($timegroups) ? ' ' : '');
|
||||
@@ -1589,7 +1594,7 @@ class Basic
|
||||
// multiply the returned matches and sum them up. the last one (ms) is added with .
|
||||
foreach ($timegroups as $i => $time_multiply) {
|
||||
if (is_numeric($matches[$i])) {
|
||||
$timestamp += $matches[$i] * $time_multiply;
|
||||
$timestamp += (float)$matches[$i] * $time_multiply;
|
||||
}
|
||||
}
|
||||
if (is_numeric($matches[10])) {
|
||||
@@ -1612,7 +1617,7 @@ class Basic
|
||||
if (!$year || !$month || !$day) {
|
||||
return false;
|
||||
}
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
if (!checkdate((int)$month, (int)$day, (int)$year)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1629,15 +1634,15 @@ class Basic
|
||||
if (!$year || !$month || !$day) {
|
||||
return false;
|
||||
}
|
||||
if (!checkdate($month, $day, $year)) {
|
||||
if (!checkdate((int)$month, (int)$day, (int)$year)) {
|
||||
return false;
|
||||
}
|
||||
if (!$hour || !$min) {
|
||||
if (!is_numeric($hour) || !is_numeric($min)) {
|
||||
return false;
|
||||
}
|
||||
if (($hour < 0 || $hour > 24) ||
|
||||
($min < 0 || $min > 60) ||
|
||||
($sec && ($sec < 0 || $sec > 60))
|
||||
(is_numeric($sec) && ($sec < 0 || $sec > 60))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
@@ -1726,6 +1731,8 @@ class Basic
|
||||
$end->setTime(0, 0, 1);
|
||||
|
||||
$days[0] = $end->diff($start)->days;
|
||||
$days[1] = 0;
|
||||
$days[2] = 0;
|
||||
|
||||
$period = new \DatePeriod($start, new \DateInterval('P1D'), $end);
|
||||
|
||||
@@ -1767,7 +1774,7 @@ class Basic
|
||||
2 => 'jpg',
|
||||
3 => 'png'
|
||||
);
|
||||
|
||||
$return_data = false;
|
||||
if (!empty($cache_source)) {
|
||||
$tmp_src = $cache_source;
|
||||
} else {
|
||||
@@ -1790,6 +1797,7 @@ class Basic
|
||||
list($width, $height, $type) = getimagesize($filename);
|
||||
$convert_prefix = '';
|
||||
$create_file = false;
|
||||
$delete_filename = '';
|
||||
// check if we can skip the PDF creation: if we have size, if do not have type, we assume type png
|
||||
if (!$type && is_numeric($size_x) && is_numeric($size_y)) {
|
||||
$check_thumb = $tmp_src.'thumb_'.$pic.'_'.$size_x.'x'.$size_y.'.'.$image_types[3];
|
||||
@@ -1887,6 +1895,7 @@ class Basic
|
||||
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||
// if string does not match anymore we have a convert problem
|
||||
if ($string != $compare) {
|
||||
$failed = array ();
|
||||
// go through each character and find the ones that do not match
|
||||
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i ++) {
|
||||
$char = mb_substr($string, $i, 1, $from_encoding);
|
||||
@@ -1989,10 +1998,10 @@ class Basic
|
||||
}
|
||||
// split up the version strings to calc the compare number
|
||||
$version = explode('.', $min_version);
|
||||
$min_version = $version[0] * 10000 + $version[1] * 100 + $version[2];
|
||||
$min_version = (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2];
|
||||
if ($max_version) {
|
||||
$version = explode('.', $max_version);
|
||||
$max_version = $version[0] * 10000 + $version[1] * 100 + $version[2];
|
||||
$max_version = (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2];
|
||||
// drop out if min is bigger max, equal size is okay, that would be only THIS
|
||||
if ($min_version > $max_version) {
|
||||
return false;
|
||||
@@ -2002,7 +2011,7 @@ class Basic
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = explode('.', phpversion());
|
||||
// creates something like 50107
|
||||
define('PHP_VERSION_ID', $version[0] * 10000 + $version[1] * 100 + $version[2]);
|
||||
define('PHP_VERSION_ID', (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2]);
|
||||
}
|
||||
// check if matching for version
|
||||
if ($min_version && !$max_version) {
|
||||
@@ -2242,6 +2251,7 @@ class Basic
|
||||
|
||||
$MAX = max($r, $g, $b);
|
||||
$MIN = min($r, $g, $b);
|
||||
$HUE = 0;
|
||||
|
||||
if ($MAX == $MIN) {
|
||||
return array(0, 0, round($MAX * 100));
|
||||
@@ -2292,41 +2302,41 @@ class Basic
|
||||
switch ($Hi) {
|
||||
case 0:
|
||||
$red = $V;
|
||||
$gre = $t;
|
||||
$blu = $p;
|
||||
$green = $t;
|
||||
$blue = $p;
|
||||
break;
|
||||
case 1:
|
||||
$red = $q;
|
||||
$gre = $V;
|
||||
$blu = $p;
|
||||
$green = $V;
|
||||
$blue = $p;
|
||||
break;
|
||||
case 2:
|
||||
$red = $p;
|
||||
$gre = $V;
|
||||
$blu = $t;
|
||||
$green = $V;
|
||||
$blue = $t;
|
||||
break;
|
||||
case 3:
|
||||
$red = $p;
|
||||
$gre = $q;
|
||||
$blu = $V;
|
||||
$green = $q;
|
||||
$blue = $V;
|
||||
break;
|
||||
case 4:
|
||||
$red = $t;
|
||||
$gre = $p;
|
||||
$blu = $V;
|
||||
$green = $p;
|
||||
$blue = $V;
|
||||
break;
|
||||
case 5:
|
||||
$red = $V;
|
||||
$gre = $p;
|
||||
$blu = $q;
|
||||
$green = $p;
|
||||
$blue = $q;
|
||||
break;
|
||||
default:
|
||||
$red = 0;
|
||||
$gre = 0;
|
||||
$green = 0;
|
||||
$blue = 0;
|
||||
}
|
||||
|
||||
return array(round($red * 255), round($gre * 255), round($blu * 255));
|
||||
return array(round($red * 255), round($green * 255), round($blue * 255));
|
||||
}
|
||||
|
||||
// METHOD: rgb2hsl
|
||||
@@ -2345,6 +2355,7 @@ class Basic
|
||||
|
||||
$MIN = min($r, $g, $b);
|
||||
$MAX = max($r, $g, $b);
|
||||
$HUE = 0;
|
||||
// luminance
|
||||
$L = round((($MAX + $MIN) / 2) * 100);
|
||||
|
||||
@@ -2497,7 +2508,7 @@ class Basic
|
||||
$timestamp = time() + 3600; // in seconds
|
||||
|
||||
// the max year is this year + 1;
|
||||
$max_year = date("Y", $timestamp) + 1;
|
||||
$max_year = (int)date("Y", $timestamp) + 1;
|
||||
|
||||
// preset year, month, ...
|
||||
$year = (!$year) ? date("Y", $timestamp) : $year;
|
||||
@@ -2507,7 +2518,7 @@ class Basic
|
||||
$min = (!$min) ? date("i", $timestamp) : $min; // add to five min?
|
||||
// max days in selected month
|
||||
$days_in_month = date("t", strtotime($year."-".$month."-".$day." ".$hour.":".$min.":0"));
|
||||
|
||||
$string = '';
|
||||
// from now to ?
|
||||
if ($name_pos_back === false) {
|
||||
$string = 'Year ';
|
||||
@@ -2630,7 +2641,7 @@ class Basic
|
||||
public function setFormToken(string $name = 'form_token'): string
|
||||
{
|
||||
// current hard set to sha256
|
||||
$token = uniqid(hash('sha256', rand()));
|
||||
$token = uniqid(hash('sha256', (string)rand()));
|
||||
$_SESSION[$name] = $token;
|
||||
return $token;
|
||||
}
|
||||
@@ -2683,14 +2694,14 @@ class Basic
|
||||
{
|
||||
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->fdebugFP($flag);
|
||||
$this->fdebugFP($flag);
|
||||
}
|
||||
|
||||
public function debug_for($type, $flag)
|
||||
{
|
||||
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->debugFor($type, $flag);
|
||||
$this->debugFor($type, $flag);
|
||||
}
|
||||
|
||||
public function get_caller_method($level = 2)
|
||||
@@ -2704,7 +2715,7 @@ class Basic
|
||||
{
|
||||
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->mergeErrors($error_msg);
|
||||
$this->mergeErrors($error_msg);
|
||||
}
|
||||
|
||||
public function print_error_msg($string = '')
|
||||
@@ -2718,14 +2729,14 @@ class Basic
|
||||
{
|
||||
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->writeErrorMsg($level, $error_string);
|
||||
$this->writeErrorMsg($level, $error_string);
|
||||
}
|
||||
|
||||
public function reset_error_msg($level = '')
|
||||
{
|
||||
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->resetErrorMsg($level);
|
||||
$this->resetErrorMsg($level);
|
||||
}
|
||||
|
||||
public static function print_ar($array)
|
||||
|
||||
@@ -411,7 +411,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
}
|
||||
// integer is different
|
||||
if (isset($this->table_array[$column]['int']) || isset($this->table_array[$column]['int_null'])) {
|
||||
$this->debug('write_check', '['.$column.']['.$this->table_array[$column]['value'].']['.$this->table_array[$column]['type'].'] VALUE SET: '.isset($this->table_array[$column]['value']).' | INT NULL: '.isset($this->table_array[$column]['int_null']));
|
||||
$this->debug('write_check', '['.$column.']['.$this->table_array[$column]['value'].']['.$this->table_array[$column]['type'].'] '.
|
||||
'VALUE SET: '.(string)isset($this->table_array[$column]['value']).
|
||||
' | INT NULL: '.(string)isset($this->table_array[$column]['int_null']));
|
||||
if (isset($this->table_array[$column]['value']) &&
|
||||
!$this->table_array[$column]['value'] &&
|
||||
isset($this->table_array[$column]['int_null'])
|
||||
@@ -436,6 +438,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
$_value = 'NULL';
|
||||
} elseif (isset($this->table_array[$column]['value'])) {
|
||||
$_value = $this->table_array[$column]['value'];
|
||||
} else {
|
||||
// fallback
|
||||
$_value = 'NULL';
|
||||
}
|
||||
$q_data .= $_value;
|
||||
} else {
|
||||
@@ -514,7 +519,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// set primary key
|
||||
if ($insert) {
|
||||
$this->table_array[$this->pk_name]['value'] = $this->insert_id;
|
||||
$this->ok = $this->insert_id;
|
||||
$this->pk_id = $this->insert_id;
|
||||
}
|
||||
// return the table if needed
|
||||
return $this->table_array;
|
||||
|
||||
@@ -277,9 +277,12 @@ class IO extends \CoreLibs\Basic
|
||||
// other vars
|
||||
private $nbsp = ''; // used by print_array recursion function
|
||||
// error & warning id
|
||||
private $error_id;
|
||||
// not error_id is defined in \CoreLibs\Basic
|
||||
private $had_error;
|
||||
private $warning_id;
|
||||
private $had_warning;
|
||||
// error thrown on class init if we cannot connect to db
|
||||
protected $db_init_error = false;
|
||||
// sub include with the database functions
|
||||
private $db_functions;
|
||||
|
||||
@@ -305,6 +308,11 @@ class IO extends \CoreLibs\Basic
|
||||
// set_control_flag -> flags for core class get/set variable error handling
|
||||
// RETURN nothing
|
||||
// DESC constructor for db_clss
|
||||
/**
|
||||
* main DB concstructor with auto connection to DB and failure set on failed connection
|
||||
* @param array $db_config DB configuration array
|
||||
* @param int|integer $set_control_flag Class set control flag
|
||||
*/
|
||||
public function __construct(array $db_config, int $set_control_flag = 0)
|
||||
{
|
||||
// start basic class
|
||||
@@ -373,18 +381,18 @@ class IO extends \CoreLibs\Basic
|
||||
// abort error
|
||||
$this->error_id = 10;
|
||||
$this->__dbError();
|
||||
return false;
|
||||
$this->db_init_error = false;
|
||||
}
|
||||
|
||||
// connect to DB
|
||||
if (!$this->__connectToDB()) {
|
||||
$this->error_id = 16;
|
||||
$this->__dbError();
|
||||
return false;
|
||||
$this->db_init_error = false;
|
||||
}
|
||||
|
||||
// so we can check that we have a successful DB connection created
|
||||
return true;
|
||||
$this->db_init_error = true;
|
||||
}
|
||||
|
||||
// METHOD: __destruct
|
||||
@@ -980,7 +988,7 @@ class IO extends \CoreLibs\Basic
|
||||
}
|
||||
$string = '';
|
||||
if (is_array($array)) {
|
||||
$this->nbps = '';
|
||||
$this->nbsp = '';
|
||||
$string .= $this->__printArray($array);
|
||||
$this->__dbDebug('db', $string, 'dbDumpData');
|
||||
}
|
||||
@@ -991,15 +999,22 @@ class IO extends \CoreLibs\Basic
|
||||
// WAS : db_return
|
||||
// PARAMS: query -> the query ...
|
||||
// reset -> if set to 1, at the end of the query (last row returned), the stored array will be deleted ...
|
||||
// if set to 2, the data will be read new and cached (wheres 1 reads new AND destroys at end of read)
|
||||
// if set to 2, the data will be read new and cached (wheres 1 reads cache AND destroys at end of read)
|
||||
// -> if set to 3, after EACH row, the data will be reset, no caching is done except for basic (count, etc)
|
||||
// RETURN: res mixed (array/hash)
|
||||
// RETURN: res mixed (array/bool)
|
||||
// DESC : single running function, if called creates md5 from
|
||||
// query string and so can itself call exec/return calls
|
||||
// caches data, so next time called with IDENTICAL (!!!!)
|
||||
// [this means 1:1 bit to bit identical query] returns cached
|
||||
// data, or with reset flag set calls data from DB again
|
||||
public function dbReturn($query, $reset = 0)
|
||||
/**
|
||||
* returned array is database number/fieldname -> value element
|
||||
* @param string $query Query string
|
||||
* @param integer $reset reset status: 1: read cache, clean at the end, 2: read new, clean at end, 3: never cache
|
||||
* @param bool $assoc_only true to only returned the named and not index position ones
|
||||
* @return array|boolean return array data or false on error/end
|
||||
*/
|
||||
public function dbReturn($query, $reset = 0, bool $assoc_only = false)
|
||||
{
|
||||
if (!$query) {
|
||||
$this->error_id = 11;
|
||||
@@ -1028,7 +1043,8 @@ class IO extends \CoreLibs\Basic
|
||||
$this->__dbError('', $this->cursor_ext[$md5]['query']);
|
||||
return false;
|
||||
}
|
||||
|
||||
// init return als false
|
||||
$return = false;
|
||||
// if it is a call with reset in it we reset the cursor, so we get an uncached return
|
||||
// but only for the FIRST call (pos == 0)
|
||||
if ($reset && !$this->cursor_ext[$md5]['pos']) {
|
||||
@@ -1092,9 +1108,14 @@ class IO extends \CoreLibs\Basic
|
||||
}
|
||||
// read data for further work ... but only if necessarry
|
||||
if ($this->cursor_ext[$md5]['read_rows'] == $this->cursor_ext[$md5]['num_rows']) {
|
||||
$return = 0;
|
||||
$return = false;
|
||||
} else {
|
||||
$return = $this->__dbConvertEncoding($this->db_functions->__dbFetchArray($this->cursor_ext[$md5]['cursor']));
|
||||
$return = $this->__dbConvertEncoding(
|
||||
$this->db_functions->__dbFetchArray(
|
||||
$this->cursor_ext[$md5]['cursor'],
|
||||
$this->db_functions->__dbResultType($assoc_only)
|
||||
)
|
||||
);
|
||||
}
|
||||
// check if cached call or reset call ...
|
||||
if (!$return && !$reset) {
|
||||
@@ -1103,15 +1124,22 @@ class IO extends \CoreLibs\Basic
|
||||
$this->cursor_ext[$md5]['pos'] = 0;
|
||||
# if not reset given, set the cursor to true, so in a cached call on a different page we don't get problems from DB connection (as those will be LOST)
|
||||
$this->cursor_ext[$md5]['cursor'] = 1;
|
||||
$return = 0;
|
||||
$return = false;
|
||||
} else {
|
||||
// unset return value ...
|
||||
unset($return);
|
||||
$return = array ();
|
||||
for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i ++) {
|
||||
// create mixed return array
|
||||
$field_value = $this->cursor_ext[$md5][$this->cursor_ext[$md5]['pos']][$this->cursor_ext[$md5]['field_names'][$i]];
|
||||
$return[$i] = $field_value;
|
||||
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $field_value;
|
||||
if ($assoc_only === false && isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])) {
|
||||
$return[$i] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i];
|
||||
}
|
||||
// named part
|
||||
if (isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])) {
|
||||
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i];
|
||||
} else {
|
||||
// throws PhanTypeMismatchDimFetch error
|
||||
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$this->cursor_ext[$md5]['field_names'][$i]];
|
||||
}
|
||||
}
|
||||
$this->cursor_ext[$md5]['pos'] ++;
|
||||
}
|
||||
@@ -1125,7 +1153,7 @@ class IO extends \CoreLibs\Basic
|
||||
// at end of read reset pos & set cursor to 1 (so it does not get lost in session transfer)
|
||||
$this->cursor_ext[$md5]['pos'] = 0;
|
||||
$this->cursor_ext[$md5]['cursor'] = 1;
|
||||
$return = 0;
|
||||
$return = false;
|
||||
}
|
||||
// if something found, write data into hash array
|
||||
if ($return) {
|
||||
@@ -1134,10 +1162,11 @@ class IO extends \CoreLibs\Basic
|
||||
$this->cursor_ext[$md5]['read_rows'] ++;
|
||||
// if reset is <3 caching is done, else no
|
||||
if ($reset < 3) {
|
||||
$temp = array ();
|
||||
foreach ($return as $field_name => $data) {
|
||||
$temp[$field_name] = $data;
|
||||
}
|
||||
$this->cursor_ext[$md5][] = $temp;
|
||||
$this->cursor_ext[$md5]['data'][] = $temp;
|
||||
}
|
||||
} // cached data if
|
||||
} // cached or not if
|
||||
@@ -1325,7 +1354,9 @@ class IO extends \CoreLibs\Basic
|
||||
return false;
|
||||
}
|
||||
$cursor = $this->dbExec($query);
|
||||
$rows = array ();
|
||||
while ($res = $this->dbFetchArray($cursor, $assoc_only)) {
|
||||
$data = array ();
|
||||
for ($i = 0; $i < $this->num_fields; $i ++) {
|
||||
$data[$this->field_names[$i]] = $res[$this->field_names[$i]];
|
||||
}
|
||||
@@ -1746,7 +1777,7 @@ class IO extends \CoreLibs\Basic
|
||||
$has_default = $table_data[$field]['has default'];
|
||||
$not_null = $table_data[$field]['not null'];
|
||||
// if not null and string => '', if not null and int or numeric => 0, if bool => skip, all others skip
|
||||
if ($not_null && !isset($_data)) {
|
||||
if ($not_null && $_data == null) {
|
||||
if (strstr($table_data[$field]['type'], 'int') || strstr($table_data[$field]['type'], 'numeric')) {
|
||||
$_data = 0;
|
||||
} else {
|
||||
@@ -1756,7 +1787,12 @@ class IO extends \CoreLibs\Basic
|
||||
// we detect bool, so we can force a write on "false"
|
||||
$is_bool = $table_data[$field]['type'] == 'bool' ? true : false;
|
||||
// write if the field has to be not null, or if there is no data and the field has no default values or if there is data or if this is an update and there is no data (set null)
|
||||
if (($not_null && isset($_data)) || (!$has_default && !isset($_data)) || (is_numeric($_data) && isset($_data)) || ($primary_key['value'] && !isset($_data)) || isset($_data)) {
|
||||
if (($not_null && $_data) ||
|
||||
(!$has_default && !$_data) ||
|
||||
(is_numeric($_data) && $_data) ||
|
||||
($primary_key['value'] && !$_data) ||
|
||||
$_data
|
||||
) {
|
||||
if ($q_sub_value && !$primary_key['value']) {
|
||||
$q_sub_value .= ', ';
|
||||
}
|
||||
@@ -1774,7 +1810,7 @@ class IO extends \CoreLibs\Basic
|
||||
}
|
||||
// write data into sql string
|
||||
if (strstr($table_data[$field]['type'], 'int')) {
|
||||
$q_sub_data .= (is_numeric($_data) && isset($_data)) ? $_data : 'NULL';
|
||||
$q_sub_data .= (is_numeric($_data)) ? $_data : 'NULL';
|
||||
} else {
|
||||
// if bool -> set bool, else write data
|
||||
$q_sub_data .= isset($_data) ? "'".($is_bool ? $this->dbBoolean($_data, true) : $this->dbEscapeString($_data))."'" : 'NULL';
|
||||
@@ -1886,7 +1922,7 @@ class IO extends \CoreLibs\Basic
|
||||
{
|
||||
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->__closeDB();
|
||||
$this->__closeDB();
|
||||
}
|
||||
|
||||
private function _check_query_for_select($query)
|
||||
@@ -1914,14 +1950,14 @@ class IO extends \CoreLibs\Basic
|
||||
{
|
||||
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->__dbDebug($debug_id, $error_string, $id, $type);
|
||||
$this->__dbDebug($debug_id, $error_string, $id, $type);
|
||||
}
|
||||
|
||||
public function _db_error($cursor = '', $msg = '')
|
||||
{
|
||||
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->__dbError($cursor, $msg);
|
||||
$this->__dbError($cursor, $msg);
|
||||
}
|
||||
|
||||
private function _db_convert_encoding($row)
|
||||
|
||||
@@ -423,7 +423,7 @@ class PgSQL
|
||||
{
|
||||
if (false === $limit) {
|
||||
$limit = strlen($text) - 1;
|
||||
$output = array();
|
||||
$output = array ();
|
||||
}
|
||||
if ('{}' != $text) {
|
||||
do {
|
||||
@@ -435,7 +435,7 @@ class PgSQL
|
||||
return $offset;
|
||||
}
|
||||
} else {
|
||||
$offset = $this->__dbArrayParse($text, $output[], $limit, $offset + 1);
|
||||
$offset = $this->__dbArrayParse($text, $output, $limit, $offset + 1);
|
||||
}
|
||||
} while ($limit > $offset);
|
||||
}
|
||||
|
||||
@@ -26,21 +26,23 @@ namespace CoreLibs\Language\Core;
|
||||
// over it (it assumes knowledge of StringReader internals)
|
||||
class CachedFileReader extends \CoreLibs\Language\Core\StringReader
|
||||
{
|
||||
public $error = 0;
|
||||
public $_str = '';
|
||||
|
||||
public function __construct($filename)
|
||||
{
|
||||
parent::__construct();
|
||||
if (file_exists($filename)) {
|
||||
$length = filesize($filename);
|
||||
$fd = fopen($filename, 'rb');
|
||||
|
||||
if (!$fd) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
return false;
|
||||
}
|
||||
$this->_str = fread($fd, $length);
|
||||
fclose($fd);
|
||||
} else {
|
||||
$this->error = 2; // File doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class FileReader
|
||||
public $fr_pos;
|
||||
public $fr_fd;
|
||||
public $fr_length;
|
||||
public $error = 0;
|
||||
|
||||
public function __construct($filename)
|
||||
{
|
||||
@@ -36,11 +37,9 @@ class FileReader
|
||||
$this->fr_fd = fopen($filename, 'rb');
|
||||
if (!$this->fr_fd) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = 2; // File doesn't exist
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ class GetTextReader
|
||||
// public:
|
||||
public $error = 0; // public variable that holds error code (0 if no error)
|
||||
|
||||
//private:
|
||||
// private:
|
||||
private $BYTEORDER = 0; // 0: low endian, 1: big endian
|
||||
private $STREAM = null;
|
||||
private $short_circuit = false;
|
||||
@@ -125,7 +125,6 @@ class GetTextReader
|
||||
$this->BYTEORDER = 0;
|
||||
} else {
|
||||
$this->error = 1; // not MO file
|
||||
return false;
|
||||
}
|
||||
|
||||
// FIXME: Do we care about revision? We should.
|
||||
@@ -396,7 +395,7 @@ class GetTextReader
|
||||
* @param string single
|
||||
* @param string plural
|
||||
* @param string number
|
||||
* @return translated plural form
|
||||
* @return string plural form
|
||||
*/
|
||||
public function ngettext($single, $plural, $number)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,10 @@ namespace CoreLibs\Language\Core;
|
||||
// seek is essential, and it should be byte stream
|
||||
class StreamReader
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
// should return a string [FIXME: perhaps return array of bytes?]
|
||||
public function read($bytes)
|
||||
{
|
||||
|
||||
@@ -35,8 +35,9 @@ class L10n extends \CoreLibs\Basic
|
||||
private $input;
|
||||
private $l10n;
|
||||
|
||||
public function __construct(string $lang = '', string $path = '')
|
||||
public function __construct(string $lang = '', string $path = '', int $set_control_flag = 0)
|
||||
{
|
||||
parent::__construct($set_control_flag);
|
||||
if (!$lang) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
|
||||
@@ -226,6 +226,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
private $int_pk_name; // primary key, only internal usage
|
||||
public $reference_array = array (); // reference arrays -> stored in $this->reference_array[$table_name]=>array();
|
||||
public $element_list; // element list for elements next to each other as a special sub group
|
||||
public $table_array = array ();
|
||||
public $my_page_name; // the name of the page without .php extension
|
||||
public $mobile_phone = false;
|
||||
// buttons and checkboxes
|
||||
@@ -241,6 +242,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
public $security_level;
|
||||
// layout publics
|
||||
public $table_width;
|
||||
// language
|
||||
public $l;
|
||||
|
||||
// now some default error msgs (english)
|
||||
public $language_array = array ();
|
||||
@@ -501,7 +504,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
public function formProcedureDeleteFromElementList($element_list, $remove_name)
|
||||
{
|
||||
$this->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: '.$this->base_acl_level.' >= '.$this->security_level['delete']);
|
||||
$this->debug('REMOVE ELEMENT', 'Protected Value set: '.isset($this->table_array['protected']['value']));
|
||||
$this->debug('REMOVE ELEMENT', 'Protected Value set: '.(string)isset($this->table_array['protected']['value']));
|
||||
$this->debug('REMOVE ELEMENT', 'Error: '.$this->error);
|
||||
// only do if the user is allowed to delete
|
||||
if ($this->base_acl_level >= $this->security_level['delete'] &&
|
||||
@@ -517,9 +520,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// if prefix, set it
|
||||
$prfx = ($this->element_list[$element_list[$i]]['prefix']) ? $this->element_list[$element_list[$i]]['prefix'].'_' : '';
|
||||
// get the primary key
|
||||
$pk_name = '';
|
||||
foreach ($this->element_list[$element_list[$i]]['elements'] as $el_name => $data) {
|
||||
if (isset($data['pk_id'])) {
|
||||
$pk_name = $el_name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// which key should be deleted
|
||||
@@ -726,13 +731,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$data['value'][] = $i;
|
||||
$data['output'][] = $this->table_array[$element_name]['element_list'][$i];
|
||||
$data['name'] = $element_name;
|
||||
if ((isset($i) && isset($this->table_array[$element_name]['value'])) ||
|
||||
(!isset($i) && !isset($this->table_array[$element_name]['value']))
|
||||
if (($i && isset($this->table_array[$element_name]['value'])) ||
|
||||
(!$i && !isset($this->table_array[$element_name]['value']))
|
||||
) {
|
||||
$data['checked'] = $this->table_array[$element_name]['value'];
|
||||
}
|
||||
|
||||
if (isset($i)) {
|
||||
if ($i) {
|
||||
$data['separator'] = '';
|
||||
}
|
||||
}
|
||||
@@ -923,7 +928,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
break;
|
||||
case 'date': // YYYY-MM-DD
|
||||
if (!$this->checkDate($this->table_array[$key]['value'], 1)) {
|
||||
if (!$this->checkDate($this->table_array[$key]['value'])) {
|
||||
$this->msg .= sprintf($this->l->__('Please enter a vailid date (YYYY-MM-DD) for the <b>%s</b> Field!<br>'), $this->table_array[$key]['output_name']);
|
||||
}
|
||||
break;
|
||||
@@ -937,7 +942,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
break;
|
||||
case 'intervalshort': // ony interval n [Y/M/D] only
|
||||
if (preg_match("/^\d{1,3}\ ?[YMDymd]{1}$/", $this->table_array[$key]['value'])) {
|
||||
$this->msg .= sprintf($this->l->__('Please enter a valid time interval in the format <length> Y|M|D for the <b>%s</b> Field!<br>'), $this->table[$key]['output_name']);
|
||||
$this->msg .= sprintf($this->l->__('Please enter a valid time interval in the format <length> Y|M|D for the <b>%s</b> Field!<br>'), $this->table_array[$key]['output_name']);
|
||||
}
|
||||
break;
|
||||
case 'email':
|
||||
@@ -1037,24 +1042,28 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
} // while
|
||||
// do check for reference tables
|
||||
if (is_array($this->reference_array)) {
|
||||
// do check for reference tables
|
||||
if (!is_array($this->reference_array)) {
|
||||
$this->reference_array = array ();
|
||||
}
|
||||
reset($this->reference_array);
|
||||
foreach ($this->reference_array as $key => $value) {
|
||||
if ($this->reference_array[$key]['mandatory'] && !$this->reference_array[$key]['selected'][0]) {
|
||||
$this->msg .= sprintf($this->l->__('Please select at least one Element from field <b>%s</b>!<br>'), $this->reference_array[$key]['output_name']);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->reference_array = array ();
|
||||
}
|
||||
// $this->debug('edit_error', 'QS: <pre>'.print_r($_POST, true).'</pre>');
|
||||
if (is_array($this->element_list)) {
|
||||
// check the mandatory stuff
|
||||
// if mandatory, check that at least on pk exists or if at least the mandatory field is filled
|
||||
foreach ($this->element_list as $table_name => $reference_array) {
|
||||
if (!is_array($reference_array)) {
|
||||
$reference_array = array ();
|
||||
}
|
||||
// set pk/fk id for this
|
||||
$_pk_name = '';
|
||||
$_fk_name = '';
|
||||
foreach ($reference_array['elements'] as $_name => $_data) {
|
||||
if (isset($_data['pk_id'])) {
|
||||
$_pk_name = $_name;
|
||||
@@ -1081,6 +1090,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
$this->debug('POST ARRAY', $this->printAr($_POST));
|
||||
$mand_okay = 0;
|
||||
$mand_name = '';
|
||||
# check each row
|
||||
for ($i = 0; $i < $max; $i ++) {
|
||||
// either one of the post pks is set, or the mandatory
|
||||
@@ -1125,8 +1135,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if ($this->table_array[$this->int_pk_name]['value']) {
|
||||
$q .= ' AND '.$this->int_pk_name.' <> '.$this->table_array[$this->int_pk_name]['value'];
|
||||
}
|
||||
list($$key) = $this->dbReturnRow($q);
|
||||
if ($$key) {
|
||||
list($key) = $this->dbReturnRow($q);
|
||||
if ($key) {
|
||||
$this->msg .= sprintf($this->l->__('The field <b>%s</b> in row <b>%s</b> can be used only once!<br>'), $reference_array['output_name'], $i);
|
||||
}
|
||||
break;
|
||||
@@ -1142,7 +1152,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
|
||||
// main mandatory is met -> error msg
|
||||
if (!isset($mand_okay) && isset($reference_array['mandatory'])) {
|
||||
if (!$mand_okay && isset($reference_array['mandatory'])) {
|
||||
$this->msg .= sprintf($this->l->__('You need to enter at least one data set for field <b>%s</b>!<Br>'), $reference_array['output_name']);
|
||||
}
|
||||
for ($i = 0; $i < $max; $i ++) {
|
||||
@@ -1269,7 +1279,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
{
|
||||
// for drop_down_db_input check if text field is filled and if, if not yet in db ...
|
||||
// and upload files
|
||||
if (!isset($this->table_array)) {
|
||||
if (!is_array($this->table_array)) {
|
||||
$this->table_array = array ();
|
||||
}
|
||||
reset($this->table_array);
|
||||
@@ -1345,7 +1355,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
if (move_uploaded_file($GLOBALS['_FILES'][$key.'_file']['tmp_name'], $this->table_array[$key]['save_dir'].$GLOBALS['_FILES'][$key.'_file']['name'])) {
|
||||
// make it unique with a unique number at the beginning
|
||||
$this->table_array[$key]['value'] = uniqid(rand(), 1).'_'.$GLOBALS['_FILES'][$key.'_file']['name'];
|
||||
$this->table_array[$key]['value'] = uniqid((string)rand(), true).'_'.$GLOBALS['_FILES'][$key.'_file']['name'];
|
||||
} else {
|
||||
$this->msg .= $this->l->__('File could not be copied to target directory! Perhaps wrong directory permissions.');
|
||||
$this->error = 1;
|
||||
@@ -1400,6 +1410,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
reset($this->element_list);
|
||||
foreach ($this->element_list as $table_name => $reference_array) {
|
||||
// init arrays
|
||||
$q_begin = array ();
|
||||
$q_middle = array ();
|
||||
$q_end = array ();
|
||||
$q_names = array ();
|
||||
$q_data = array ();
|
||||
$q_values = array ();
|
||||
@@ -1702,6 +1715,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
reset($this->element_list[$table_name]['elements']);
|
||||
// generic data read in (counts for all rows)
|
||||
// visible list data output
|
||||
$q_select = array ();
|
||||
$proto = array ();
|
||||
foreach ($this->element_list[$table_name]['elements'] as $el_name => $data_array) {
|
||||
// $this->debug('CFG', 'El: '.$el_name.' -> '.$this->printAr($data_array));
|
||||
// if the element name matches the read array, then set the table as a name prefix
|
||||
@@ -1765,6 +1780,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if (isset($this->element_list[$table_name]['read_data'])) {
|
||||
// we need a second one for the query build only
|
||||
// prefix all elements with the $table name
|
||||
$_q_select = array ();
|
||||
foreach ($q_select as $_pos => $element) {
|
||||
$_q_select[$_pos] = $table_name.'.'.$element;
|
||||
}
|
||||
|
||||
@@ -115,6 +115,7 @@ class ProgressBar
|
||||
|
||||
private function __calculatePosition($step)
|
||||
{
|
||||
$bar = 0;
|
||||
switch ($this->direction) {
|
||||
case 'right':
|
||||
case 'left':
|
||||
@@ -137,6 +138,7 @@ class ProgressBar
|
||||
$pixel = $bar - ($this->pedding * 2);
|
||||
}
|
||||
|
||||
$position = array ();
|
||||
switch ($this->direction) {
|
||||
case 'right':
|
||||
$position['left'] = $this->pedding;
|
||||
@@ -438,6 +440,7 @@ class ProgressBar
|
||||
$this->__setStep($this->step);
|
||||
$this->position = $this->__calculatePosition($this->step);
|
||||
|
||||
$style_master = '';
|
||||
if ($this->top || $this->left) {
|
||||
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
|
||||
}
|
||||
@@ -459,6 +462,7 @@ class ProgressBar
|
||||
}
|
||||
|
||||
if ($this->frame['show'] == true) {
|
||||
$border = '';
|
||||
if ($this->frame['border'] > 0) {
|
||||
$border = 'border:'.$this->frame['border'].'px solid;border-color:'.$this->frame['brd_color'].';margin-top:2px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class SmartyExtend extends SmartyBC
|
||||
// constructor class, just sets the language stuff
|
||||
public function __construct(string $lang)
|
||||
{
|
||||
SmartyBC::__construct();
|
||||
parent::__construct();
|
||||
$this->l10n = new \CoreLibs\Language\L10n($lang);
|
||||
// variable variable register
|
||||
// $this->register_modifier('getvar', array(&$this, 'get_template_vars'));
|
||||
|
||||
@@ -60,7 +60,7 @@ function MyErrorHandler($type, $message, $file, $line, $context)
|
||||
// <> the line number in this file
|
||||
// [|] error name and error number
|
||||
// : the php error message
|
||||
$output = '['.date("Y-m-d H:i:s").'] {'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
|
||||
$output = '{'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
|
||||
# try to open file
|
||||
$ROOT = CURRENT_WORKING_DIR;
|
||||
$LOG = 'log/';
|
||||
@@ -76,7 +76,7 @@ function MyErrorHandler($type, $message, $file, $line, $context)
|
||||
$fp = @fopen($fn, 'a');
|
||||
// write if we have a file pointer, else set error flag
|
||||
if ($fp) {
|
||||
fwrite($fp, $output."\n");
|
||||
fwrite($fp, '['.date("Y-m-d H:i:s").'] '.$output."\n");
|
||||
fclose($fp);
|
||||
} else {
|
||||
$error = 1;
|
||||
@@ -92,13 +92,13 @@ function MyErrorHandler($type, $message, $file, $line, $context)
|
||||
if (ini_get("display_errors")) {
|
||||
echo "<div style='border: 1px dotted red; background-color: #ffffe5; color: #000000; padding: 5px; margin-bottom: 2px;'>";
|
||||
echo "<div style='color: orange; font-weight: bold;'>".$error_level[$type].":</div>";
|
||||
echo "<b>$message</b> on line <b>$line</b> in <b>$file</b>";
|
||||
echo "<b>".$message."</b> on line <b>".$line."</b> in <b>".$file."</b>";
|
||||
echo "</div>";
|
||||
}
|
||||
// if write to log is on
|
||||
// simplified, remove datetime for log file
|
||||
if (ini_get('log_errors')) {
|
||||
error_log('{'.$page_temp.'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message);
|
||||
error_log($output);
|
||||
}
|
||||
}
|
||||
// return true, to avoid that php calls its own error stuff
|
||||
|
||||
@@ -38,7 +38,7 @@ class qqUploadedFileXhr
|
||||
if (isset($_SERVER["CONTENT_LENGTH"])) {
|
||||
return (int)$_SERVER["CONTENT_LENGTH"];
|
||||
} else {
|
||||
throw new Exception('Getting content length is not supported.');
|
||||
throw new \Exception('Getting content length is not supported.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ class qqFileUploader
|
||||
private $allowedExtensions = array();
|
||||
private $sizeLimit = 10485760;
|
||||
private $file;
|
||||
public $uploadFileName;
|
||||
public $uploadFileExt;
|
||||
|
||||
public function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760)
|
||||
{
|
||||
@@ -41,7 +43,7 @@ class qqFileUploader
|
||||
|
||||
private function toBytes($str)
|
||||
{
|
||||
$val = trim($str);
|
||||
$val = (int)trim($str);
|
||||
$last = strtolower($str[strlen($str)-1]);
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
|
||||
@@ -15,12 +15,12 @@ if (class_exists('Autoload', false) === false) {
|
||||
{
|
||||
// print "(1) Class: $class / DIR: ".__DIR__."<br>";
|
||||
// set directory seperator (we need to replace from namespace)
|
||||
$ds = DS ?? DIRECTORY_SEPARATOR;
|
||||
$ds = defined('DS') ? DS : DIRECTORY_SEPARATOR;
|
||||
// base lib
|
||||
$LIB = LIB ?? 'lib';
|
||||
$LIB = defined('LIB') ? LIB : 'lib';
|
||||
// if lib is in path, do not add lib again
|
||||
if (strpos(__DIR__, $LIB) !== false) {
|
||||
$LIB .= DS;
|
||||
$LIB .= $ds;
|
||||
} else {
|
||||
$LIB = '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user