Compare commits

...

2 Commits

Author SHA1 Message Date
Clemens Schwaighofer
b6f6eeac9b Update byteStringFormat with si units and bitwise mask
The old method name byteStringFormat is currently deprecated and it is
recommended to move to the new humanReadableByteFormat method.
Difference is that the new version uses a bitfield settings mask
BYTE_FORMAT_NOSPACE, BYTE_FORMAT_ADJUST, BYTE_FORMAT_SI
2019-12-06 15:29:06 +09:00
Clemens Schwaighofer
beedf629e5 Fixups for phan 2.4.4 run checks
Lines with @phan HACK comment are added to supress phan warnings, but do
actually no additional work.
On newer phan version those lines should be checked and removed if
needed
2019-12-05 16:01:44 +09:00
7 changed files with 358 additions and 118 deletions

View File

@@ -254,6 +254,45 @@ echo "SOURCE ARRAY: ".$basic->printAr($test_array)."<br>";
echo "FOUND ELEMENTS [base]: ".$basic->printAr($basic->arraySearchRecursive('email', $test_array, 'type'))."<br>";
echo "FOUND ELEMENTS [input]: ".$basic->printAr($basic->arraySearchRecursive('email', $test_array['input'], 'type'))."<br>";
// *** BYTES TEST ***
$bytes = array(
-123123123,
999999, // KB-1
999999999, // MB-1
254779258, // MB-n
999999999999999, // TB-1
588795544887632, // TB-n
999999999999999999, // PB-1
9223372036854775807, // MAX INT
999999999999999999999, // EB-1
);
print "<b>BYTE FORMAT TESTS</b><br>";
foreach ($bytes as $byte) {
print '<div style="display: flex; border-bottom: 1px dashed gray;">';
//
print '<div style="width: 35%; text-align: right; padding-right: 2px;">';
print "(".number_format($byte)."/".$byte.") bytes :";
print '</div><div style="width: 40%;">';
print $basic->humanReadableByteFormat($byte);
print "</div>";
//
print "</div>";
//
print '<div style="display: flex; border-bottom: 1px dotted red;">';
//
print '<div style="width: 35%; text-align: right; padding-right: 2px;">';
print "bytes [si]:";
print '</div><div style="width: 40%;">';
// print $basic->byteStringFormat($byte, true, false, true);
print $basic->humanReadableByteFormat($byte, $basic::BYTE_FORMAT_SI);
print "</div>";
//
print "</div>";
}
// *** IMAGE TESTS ***
echo "<hr>";
// image thumbnail
$images = array(
// height bigger
@@ -272,7 +311,6 @@ $images = array(
// Photoshop
'photoshop_test.psd',
);
echo "<hr>";
$thumb_width = 250;
$thumb_height = 300;
// return mime type ala mimetype

View File

@@ -21,8 +21,8 @@ if ($base->getConnectionStatus()) {
}
print "Start time: ".$base->runningTime()."<br>";
print "ByteStringFormat: ".$base->ByteStringFormat(1234567.12)."<br>";
print "byteStringFormat: ".$base->byteStringFormat(1234567.12)."<br>";
print "HumanReadableByteFormat: ".$base->HumanReadableByteFormat(1234567.12)."<br>";
print "humanReadableByteFormat: ".$base->humanReadableByteFormat(1234567.12)."<br>";
// print "get_page_name [DEPRECATED]: ".$base->get_page_name()."<br>";
print "getPageName: ".$base->getPageName()."<br>";

View File

@@ -178,44 +178,17 @@ class Login extends \CoreLibs\DB\IO
$this->euid = array_key_exists('EUID', $_SESSION) ? $_SESSION['EUID'] : 0; // if there is none, there is none, saves me POST/GET check
// get login vars, are so, can't be changed
// prepare
if (!isset($_POST['login_login'])) {
$_POST['login_login'] = '';
}
if (!isset($_POST['login_username'])) {
$_POST['login_username'] = '';
}
if (!isset($_POST['login_password'])) {
$_POST['login_password'] = '';
}
if (!isset($_POST['login_logout'])) {
$_POST['login_logout'] = '';
}
if (!isset($_POST['change_password'])) {
$_POST['change_password'] = '';
}
if (!isset($_POST['pw_username'])) {
$_POST['pw_username'] = '';
}
if (!isset($_POST['pw_old_password'])) {
$_POST['pw_old_password'] = '';
}
if (!isset($_POST['pw_new_password'])) {
$_POST['pw_new_password'] = '';
}
if (!isset($_POST['pw_new_password_confirm'])) {
$_POST['pw_new_password_confirm'] = '';
}
// pass on vars to Object vars
$this->login = $_POST['login_login'];
$this->username = $_POST['login_username'];
$this->password = $_POST['login_password'];
$this->logout = $_POST['login_logout'];
$this->login = isset($_POST['login_login']) ? $_POST['login_login'] : '';
$this->username = isset($_POST['login_username']) ? $_POST['login_username'] : '';
$this->password = isset($_POST['login_password']) ? $_POST['login_password'] : '';
$this->logout = isset($_POST['login_logout']) ? $_POST['login_logout'] : '';
// password change vars
$this->change_password = $_POST['change_password'];
$this->pw_username = $_POST['pw_username'];
$this->pw_old_password = $_POST['pw_old_password'];
$this->pw_new_password = $_POST['pw_new_password'];
$this->pw_new_password_confirm = $_POST['pw_new_password_confirm'];
$this->change_password = isset($_POST['change_password']) ? $_POST['change_password'] : '';
$this->pw_username = isset($_POST['pw_username']) ? $_POST['pw_username'] : '';
$this->pw_old_password = isset($_POST['pw_old_password']) ? $_POST['pw_old_password'] : '';
$this->pw_new_password = isset($_POST['pw_new_password']) ? $_POST['pw_new_password'] : '';
$this->pw_new_password_confirm = isset($_POST['pw_new_password_confirm']) ? $_POST['pw_new_password_confirm'] : '';
// logout target (from config)
$this->logout_target = LOGOUT_TARGET;
// disallow user list for password change

View File

@@ -187,7 +187,7 @@ class Backend extends \CoreLibs\DB\IO
$q .= "VALUES ";
$q .= "(".$this->dbEscapeString(isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ? $_SESSION['EUID'] : 'NULL').", ";
$q .= "NOW(), ";
$q .= "'".$this->dbEscapeString((string)$event)."', '".$data."', '".$data_binary."', '".$this->dbEscapeString($this->page_name)."', ";
$q .= "'".$this->dbEscapeString((string)$event)."', '".$data."', '".$data_binary."', '".$this->dbEscapeString((string)$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'] : '')."', ";
@@ -233,13 +233,14 @@ class Backend extends \CoreLibs\DB\IO
// if flag is 0, then we show all, else, we show only the matching flagges array points
// array is already sorted after correct order
reset($pages);
for ($i = 0, $iMax = count($pages); $i < $iMax; $i ++) {
foreach ($pages as $i => $data) {
// for ($i = 0, $iMax = count($pages); $i < $iMax; $i ++) {
$show = 0;
// is it visible in the menu & is it online
if ($pages[$i]['menu'] && $pages[$i]['online']) {
if ($data['menu'] && $data['online']) {
// check if it falls into our flag if we have a flag
if ($flag) {
foreach ($pages[$i]['visible'] as $name => $key) {
foreach ($data['visible'] as $name => $key) {
if ($key == $flag) {
$show = 1;
}
@@ -251,40 +252,59 @@ class Backend extends \CoreLibs\DB\IO
if ($show) {
// if it is popup, write popup arrayound
if (isset($pages[$i]['popup']) && $pages[$i]['popup']) {
if (isset($data['popup']) && $data['popup']) {
$type = 'popup';
} else {
$type = 'normal';
$pages[$i]['popup'] = 0;
$data['popup'] = 0;
}
$query_string = '';
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 .= '&';
}
$query_string .= $pages[$i]['query'][$j]['name'].'=';
if (!$pages[$i]['query'][$j]['dynamic']) {
$query_string .= urlencode($pages[$i]['query'][$j]['value']);
} else {
$query_string .= $_GET[$pages[$i]['query'][$j]['value']] ? urlencode($_GET[$pages[$i]['query'][$j]['value']]) : urlencode($_POST[$pages[$i]['query'][$j]['value']]);
if (isset($data['query']) &&
is_array($data['query']) &&
count($data['query'])
) {
// for ($j = 0, $jMax = count($pages[$i]['query']); $j < $jMax; $j ++) {
foreach ($data['query'] as $j => $query) {
if (!empty($query['name']) &&
!empty($query['value'])
) {
if (strlen($query_string)) {
$query_string .= '&';
}
$query_string .= $query['name'].'=';
if (isset($query['dynamic']) &&
$query['dynamic']
) {
if (isset($_GET[$query['value']])) {
$query_string .= urlencode($_GET[$query['value']]);
} elseif (isset($_POST[$query['value']])) {
$query_string .= urlencode($_POST[$query['value']]);
}
} else {
$query_string .= urlencode($query['value']);
}
}
}
}
$url = $pages[$i]['filename'];
$url = isset($data['filename']) ? $data['filename'] : '';
if (strlen($query_string)) {
$url .= '?'.$query_string;
}
$name = $pages[$i]['page_name'];
$name = isset($data['page_name']) ? $data['page_name'] : '';
// if page name matchs -> set selected flag
$selected = 0;
if ($this->getPageName() == $pages[$i]['filename']) {
if (isset($data['filename']) &&
$this->getPageName() == $data['filename']
) {
$selected = 1;
$this->page_name = $name;
}
// last check, is this menu point okay to show
$enabled = 0;
if ($this->adbShowMenuPoint($pages[$i]['filename'])) {
if (isset($data['filename']) &&
$this->adbShowMenuPoint($data['filename'])
) {
$enabled = 1;
}
// write in to view menu array
@@ -304,12 +324,15 @@ class Backend extends \CoreLibs\DB\IO
/**
* 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
* @param string|null $filename filename
* @return bool true for visible/accessable menu point, false for not
*/
public function adbShowMenuPoint(string $filename): bool
public function adbShowMenuPoint(?string $filename): bool
{
$enabled = false;
if ($filename === null) {
return $enabled;
}
switch ($filename) {
default:
$enabled = true;
@@ -341,7 +364,7 @@ class Backend extends \CoreLibs\DB\IO
public function adbByteStringFormat($number): string
{
trigger_error('Method '.__METHOD__.' is deprecated', E_USER_DEPRECATED);
return $this->byteStringFormat($number);
return $this->humanReadableByteFormat($number);
}
/**

View File

@@ -100,6 +100,10 @@ class Basic
// define check vars for the flags we can have
const CLASS_STRICT_MODE = 1;
const CLASS_OFF_COMPATIBLE_MODE = 2;
// define byteFormat
const BYTE_FORMAT_NOSPACE = 1;
const BYTE_FORMAT_ADJUST = 2;
const BYTE_FORMAT_SI = 4;
// control vars
/** @var bool compatible mode sets variable even if it is not defined */
private $set_compatible = true;
@@ -1210,7 +1214,7 @@ class Basic
public static function getFilenameEnding(string $filename): string
{
$page_temp = pathinfo($filename);
return $page_temp['extension'];
return isset($page_temp['extension']) ? $page_temp['extension'] : '';
}
/**
@@ -1270,16 +1274,27 @@ class Basic
*/
public static function arraySearchRecursiveAll($needle, array $haystack, $key, $path = null): ?array
{
// init if not set on null
if ($path === null) {
$path = array(
'level' => 0,
'work' => array()
);
}
// init sub sets if not set
if (!isset($path['level'])) {
$path['level'] = 0;
}
if (!isset($path['work'])) {
$path['work'] = array();
}
// should not be needed because it would trigger a php mehtod error
if (!is_array($haystack)) {
$haystack = array();
}
// @phan HACK
$path['level'] = $path['level'] ?? 0;
// go through the array,
foreach ($haystack as $_key => $_value) {
if (is_scalar($_value) && $_value == $needle && !$key) {
@@ -1299,6 +1314,9 @@ class Basic
$path = Basic::arraySearchRecursiveAll($needle, $_value, $key, $path);
}
}
// @phan HACK
$path['level'] = $path['level'] ?? 0;
$path['work'] = $path['work'] ?? array();
// cut all that is >= level
array_splice($path['work'], $path['level']);
// step back a level
@@ -1578,20 +1596,117 @@ class Basic
}
/**
* WRAPPER call to new humanReadableByteFormat
* converts bytes into formated string with KB, MB, etc
* @param string|int|float $number bytes as string int or pure int
* @param bool $space true (default) to add space between number and suffix
* @param string|int|float $bytes bytes as string int or pure int
* @param bool $space default true, to add space between number and suffix
* @param bool $adjust default false, always print two decimals (sprintf)
* @param bool $si default false, if set to true, use 1000 for calculation
* @return string converted byte number (float) with suffix
* @deprecated Use humanReadableByteFormat instead
*/
public static function byteStringFormat($number, bool $space = true): string
public static function byteStringFormat($bytes, bool $space = true, bool $adjust = false, bool $si = false): string
{
if (is_numeric($number) && $number > 0) {
// 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((float)$number / pow(1024, ($i = floor(log((float)$number, 1024)))), 2).($space ? ' ' : '').(isset($labels[(int)$i]) ? $labels[(int)$i] : '>EB');
// trigger_error('Method '.__METHOD__.' is deprecated, use humanReadableByteFormat', E_USER_DEPRECATED);
$flags = 0;
// match over the true/false flags to the new int style flag
// if space need to set 1
if ($space === false) {
$flags |= self::BYTE_FORMAT_NOSPACE;
}
// if adjust need to set 2
if ($adjust === true) {
$flags |= self::BYTE_FORMAT_ADJUST;
}
// if si need to set 3
if ($si === true) {
$flags |= self::BYTE_FORMAT_SI;
}
// call
return self::humanReadableByteFormat($bytes, $flags);
}
/**
* This function replaces the old byteStringFormat
*
* Converts any number string to human readable byte format
* Maxium is Exobytes and above that the Exobytes suffix is used for all
* If more are needed only the correct short name for the suffix has to be
* added to the labels array
* On no number string it returns string as is
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
*
* The class itself hast the following defined
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and extension
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
* To use the constant from outside use $class::CONSTANT
* @param string|int|float $bytes bytes as string int or pure int
* @param int $flags bitwise flag with use space turned on
* @return string converted byte number (float) with suffix
*/
public static function humanReadableByteFormat($bytes, int $flags = 0): string
{
// if not numeric, return as is
if (is_numeric($bytes)) {
// flags bit wise check
// remove space between number and suffix
if ($flags & self::BYTE_FORMAT_NOSPACE) {
$space = false;
} else {
$space = true;
}
// use sprintf instead of round
if ($flags & self::BYTE_FORMAT_ADJUST) {
$adjust = true;
} else {
$adjust = false;
}
// use SI 1000 mod and not 1024 mod
if ($flags & self::BYTE_FORMAT_SI) {
$si = true;
} else {
$si = false;
}
// si or normal
$unit = $si ? 1000 : 1024;
// always positive
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs($bytes);
// smaller than unit is always B
if ($abs_bytes < $unit) {
return $bytes.'B';
}
// labels in order of size [Y, Z]
$labels = array('', 'K', 'M', 'G', 'T', 'P', 'E');
// exp position calculation
$exp = floor(log($abs_bytes, $unit));
// avoid printing out anything larger than max labels
if ($exp >= count($labels)) {
$exp = count($labels) - 1;
}
// deviation calculation
$dev = pow($unit, $exp) * ($unit - 0.05);
// shift the exp +1 for on the border units
if ($exp < 6 &&
$abs_bytes > ($dev - (((int)$dev & 0xfff) == 0xd00 ? 52 : 0))
) {
$exp ++;
}
// label name, including leading space if flagged
$pre = ($space ? ' ' : '').(isset($labels[$exp]) ? $labels[$exp] : '>E').($si ? 'i' : '').'B';
$bytes_calc = $abs_bytes / pow($unit, $exp);
if ($adjust) {
return sprintf("%.2f%sB", $bytes_calc, $pre);
} else {
return round($bytes_calc, 2).$pre;
}
} else {
// if anything other return as string
return (string)$bytes;
}
return (string)$number;
}
/**

View File

@@ -1779,16 +1779,30 @@ class IO extends \CoreLibs\Basic
'row' => $table.'_id',
'value' => $primary_key
);
} elseif (!isset($primary_key['value'])) {
$primary_key['value'] = '';
} else {
if (!isset($primary_key['row'])) {
$primary_key['row'] = '';
}
if (!isset($primary_key['value'])) {
$primary_key['value'] = '';
}
}
// var set for strings
$q_sub_value = '';
$q_sub_data = '';
// get the table layout and row types
$table_data = $this->dbShowTableMetaData(($this->db_schema ? $this->db_schema.'.' : '').$table);
// @phan HACK
$primary_key['value'] = $primary_key['value'] ?? '';
$primary_key['row'] = $primary_key['row'] ?? '';
// loop through the write array and each field to build the query
foreach ($write_array as $field) {
if ((!$primary_key['value'] || ($primary_key['value'] && !in_array($field, $not_write_update_array))) && !in_array($field, $not_write_array)) {
if ((!$primary_key['value'] ||
($primary_key['value'] &&
!in_array($field, $not_write_update_array))
) &&
!in_array($field, $not_write_array)
) {
// data from external or data field
$_data = null;
if (count($data) >= 1 && array_key_exists($field, $data)) {
@@ -1842,7 +1856,7 @@ class IO extends \CoreLibs\Basic
}
// first work contact itself (we need contact id for everything else)
if ($primary_key['value']) {
if ($primary_key['value'] && $primary_key['row']) {
$q = 'UPDATE '.$table.' SET ';
$q .= $q_sub_data.' ';
$q .= 'WHERE '.$primary_key['row'].' = '.$primary_key['value'];
@@ -1861,8 +1875,8 @@ class IO extends \CoreLibs\Basic
if (!$primary_key['value']) {
$primary_key['value'] = $this->insert_id;
}
return $primary_key['value'];
// if there is not priamry key value field return false
return isset($primary_key['value']) ? $primary_key['value'] : false;
}
/**

View File

@@ -328,18 +328,28 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$this->base_acl_level = isset($_SESSION['BASE_ACL_LEVEL']) ? $_SESSION['BASE_ACL_LEVEL'] : 0;
// security levels for buttons/actions
// if array does not exists create basic
if (!isset($config_array['security_level']) || !is_array($config_array['security_level']) ||
(is_array($config_array['security_level']) && count($config_array['security_level']) < 4)
if (!isset($config_array['security_level']) ||
(isset($config_array['security_level']) &&
(!is_array($config_array['security_level']) ||
(is_array($config_array['security_level']) && count($config_array['security_level']) < 4))
)
) {
$config_array['security_level'] = array(
$this->security_level = array(
'load' => 100,
'new' => 100,
'save' => 100,
'delete' => 100
);
} else {
// write array to class var
$this->security_level = isset($config_array['security_level']) ?
$config_array['security_level'] :
array('load' => 100,
'new' => 100,
'save' => 100,
'delete' => 100
);
}
// write array to class var
$this->security_level = $config_array['security_level'];
}
/**
@@ -486,7 +496,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
*/
public function formProcedureLoad(string $archive_id): void
{
if ($this->archive && $archive_id && $this->base_acl_level >= $this->security_level['load']) {
if (isset($this->security_level['load']) &&
$this->archive &&
$archive_id &&
$this->base_acl_level >= $this->security_level['load']
) {
$this->formLoadTableArray($archive_id);
$this->yes = 1;
}
@@ -498,7 +512,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
*/
public function formProcedureNew(): void
{
if ($this->new && $this->base_acl_level >= $this->security_level['new']) {
if (isset($this->security_level['new']) &&
$this->new &&
$this->base_acl_level >= $this->security_level['new']
) {
if ($this->really_new == 'yes') {
$this->formUnsetTablearray();
} else {
@@ -515,7 +532,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
*/
public function formProcedureSave(): void
{
if ($this->save && $this->base_acl_level >= $this->security_level['save']) {
if (isset($this->security_level['save']) &&
$this->save &&
$this->base_acl_level >= $this->security_level['save']
) {
$this->formErrorCheck();
if (!$this->error) {
$this->formSaveTableArray();
@@ -531,7 +551,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
public function formProcedureDelete(): void
{
// delete is also by 'protected'
if ($this->delete && $this->base_acl_level >= $this->security_level['delete']) {
if (isset($this->security_level['delete']) &&
$this->delete &&
$this->base_acl_level >= $this->security_level['delete']
) {
if (isset($this->table_array['protected']['value']) && $this->table_array['protected']['value']) {
$this->msg .= $this->l->__('Cannot delete this Dataset, because it is internaly protected!');
$this->error = 2;
@@ -554,11 +577,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
*/
public function formProcedureDeleteFromElementList(array $element_list, array $remove_name): void
{
/** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */
$this->debug('REMOVE ELEMENT', 'Remove REF ELEMENT: '.$this->base_acl_level.' >= '.$this->security_level['delete']);
$this->debug('REMOVE ELEMENT', 'Protected Value set: '.(string)isset($this->table_array['protected']['value']));
$this->debug('REMOVE ELEMENT', 'Error: '.$this->error);
// only do if the user is allowed to delete
if ($this->base_acl_level >= $this->security_level['delete'] &&
if (isset($this->security_level['delete']) &&
$this->base_acl_level >= $this->security_level['delete'] &&
(!isset($this->table_array['protected']['value']) ||
(isset($this->table_array['protected']['value']) && !$this->table_array['protected']['value'])) &&
!$this->error
@@ -641,7 +666,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$pk_names = array();
$pk_ids = array();
// when security level is okay ...
if ($this->base_acl_level >= $this->security_level['load']) {
if (isset($this->security_level['load']) &&
$this->base_acl_level >= $this->security_level['load']
) {
$t_pk_name = $this->archive_pk_name;
// load list data
@@ -654,17 +681,24 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$pk_selected = $res[$this->int_pk_name];
}
$t_string = '';
for ($i = 0, $i_max = count($this->field_array); $i < $i_max; $i ++) {
foreach ($this->field_array as $i => $field_array) {
if ($t_string) {
$t_string .= ', ';
}
if (isset($this->field_array[$i]['before_value'])) {
$t_string .= $this->field_array[$i]['before_value'];
if (isset($field_array['before_value'])) {
$t_string .= $field_array['before_value'];
}
if (isset($this->field_array[$i]['binary'])) {
$t_string .= ($res[$this->field_array[$i]['name']]) ? $this->field_array[$i]['binary'][0] : $this->field_array[$i]['binary'][1];
} else {
$t_string .= $res[$this->field_array[$i]['name']];
// must have res element set
if (isset($res[$field_array['name']])) {
if (isset($field_array['binary'])) {
if (isset($field_array['binary'][0])) {
$t_string .= $field_array['binary'][0];
} elseif (isset($field_array['binary'][1])) {
$t_string .= $field_array['binary'][1];
}
} else {
$t_string .= $res[$field_array['name']];
}
}
}
$pk_names[] = $t_string;
@@ -688,7 +722,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$show_checkbox = 0;
$new_name = '';
// when security level is okay
if ($this->base_acl_level >= $this->security_level['new']) {
if (isset($this->security_level['new']) &&
$this->base_acl_level >= $this->security_level['new']
) {
if ($this->yes && !$hide_new_checkbox) {
$show_checkbox = 1;
}
@@ -719,7 +755,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$pk_value = '';
$show_delete = 0;
$old_school_hidden = 0;
if ($this->base_acl_level >= $this->security_level['save'] || $this->base_acl_level >= $this->security_level['delete']) {
if ((isset($this->security_level['save']) &&
$this->base_acl_level >= $this->security_level['save']) ||
(isset($this->security_level['delete']) &&
$this->base_acl_level >= $this->security_level['delete'])
) {
$old_school_hidden = 0;
if ($this->base_acl_level >= $this->security_level['save']) {
$seclevel_okay = 1;
@@ -943,7 +983,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$data['value'] = isset($this->table_array[$element_name]['value']) ? $this->table_array[$element_name]['value'] : 0;
$data['col_name'] = $this->col_name;
$data['table_name'] = $this->table_name;
$data['query'] = urlencode($query);
$data['query'] = $query !== null ? urlencode($query) : '';
}
// file upload
if ($this->table_array[$element_name]['type'] == 'file') {
@@ -1634,13 +1674,28 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$q = '';
// skip empty or not fully filled rows
if (isset($no_write[$i]) && !$no_write[$i]) {
if (!isset($q_begin[$i])) {
$q_begin[$i] = '';
}
if (!isset($q_end[$i])) {
$q_end[$i] = '';
}
// if tpye is update
if ($type[$i] == 'update') {
$q = $q_begin[$i].$q_data[$i].$q_end[$i];
if (isset($type[$i]) && $type[$i] == 'update') {
$q = $q_begin[$i].
(isset($q_data[$i]) ? $q_data[$i] : '').
$q_end[$i];
// or if we have block write, then it is insert (new)
} elseif (isset($block_write[$i]) && $block_write[$i]) {
$q = $q_begin[$i].$q_names[$i].', '.$this->int_pk_name.$q_middle[$i].$q_values[$i].', '.$this->table_array[$this->int_pk_name]['value'].$q_end[$i];
$q = $q_begin[$i].
(isset($q_names[$i]) ? $q_names[$i] : '').', '.
$this->int_pk_name.
(isset($q_middle[$i]) ? $q_middle[$i] : '').
(isset($q_values[$i]) ? $q_values[$i] : '').', '.
$this->table_array[$this->int_pk_name]['value'].
$q_end[$i];
}
/** @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset */
$this->debug('edit', 'Pos['.$i.'] => '.$type[$i].' Q: '.$q.'<br>');
// write the dataset
if ($q) {
@@ -1768,7 +1823,23 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
*/
public function formCreateElementListTable(string $table_name): array
{
$data = array();
// init data rray
$data = array(
'delete_name' => '',
'delete' => 0,
'enable_name' => '',
'prefix' => '',
'pk_name' => '',
'fk_name' => '',
'type' => array(),
'output_name' => array(),
'preset' => array(),
'element_list' => array(),
'output_data' => array(),
'content' => array(),
'pos' => array(),
'table_name' => $table_name // sub table name
);
// output name for the viewable left table td box, prefixed with * if mandatory
$output_name = $this->element_list[$table_name]['output_name'];
if (isset($this->element_list[$table_name]['mandatory']) &&
@@ -1779,8 +1850,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// delete button name, if there is one set
if (isset($this->element_list[$table_name]['delete_name'])) {
$data['delete_name'] = $this->element_list[$table_name]['delete_name'];
} else {
$data['delete_name'] = '';
}
// set the enable checkbox for delete, if the delete flag is given if there is one
if (isset($this->element_list[$table_name]['enable_name'])) {
@@ -1788,17 +1857,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
if (isset($this->element_list[$table_name]['delete'])) {
$data['delete'] = 1;
}
} else {
$data['enable_name'] = '';
}
// prefix for the elements, to not collide with names in the master set
if (isset($this->element_list[$table_name]['prefix'])) {
$data['prefix'] = $this->element_list[$table_name]['prefix'].'_';
} else {
$data['prefix'] = '';
}
// the sub data table name
$data['table_name'] = $table_name;
// build the select part
if (!isset($this->element_list[$table_name]['elements']) || !is_array($this->element_list[$table_name]['elements'])) {
@@ -1832,10 +1895,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') {
$md_q = md5($data_array['query']);
while ($res = $this->dbReturn($data_array['query'])) {
/** @phan-suppress-next-line PhanTypeInvalidDimOffset */
$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] : '-'));
// first is default for this element
if (isset($data_array['preset']) &&
(!isset($data['preset'][$el_name]) || (isset($data['preset'][$el_name]) && !$data['preset'][$el_name])) &&
(!isset($data['preset'][$el_name]) || empty($data['preset'][$el_name])) &&
($this->cursor_ext[$md_q]['pos'] == $data_array['preset'])
) {
$data['preset'][$el_name] = $res[0];
@@ -1884,6 +1948,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
array_unshift($q_select, $read_name);
}
}
// @phan HACK
$data['prefix'] = $data['prefix'] ?? '';
// set the rest of the data so we can print something out
$data['type'][$data['prefix'].$this->element_list[$table_name]['read_data']['name']] = 'string';
// build the read query
@@ -1919,7 +1985,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
// read out the list and add the selected data if needed
while ($res = $this->dbReturn($q)) {
$_data = array();
$prfx = $data['prefix']; // short
$prfx = $data['prefix'] ?? ''; // short
// go through each res
for ($i = 0, $i_max = count($q_select); $i < $i_max; $i ++) {
// query select part, set to the element name
@@ -1967,15 +2033,23 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
$missing_empty_count = $this->element_list[$table_name]['max_empty'] - $element_count;
$this->debug('CFG MAX', 'Max empty: '.$this->element_list[$table_name]['max_empty'].', Missing: '.$missing_empty_count.', Has: '.$element_count);
// set if we need more open entries or if we do not have any entries yet
if (($missing_empty_count < $this->element_list[$table_name]['max_empty']) || $element_count == 0) {
if (($missing_empty_count < $this->element_list[$table_name]['max_empty']) ||
$element_count == 0
) {
for ($pos = $element_count, $pos_max = $this->element_list[$table_name]['max_empty'] + $element_count; $pos <= $pos_max; $pos ++) {
$_data = array();
// just in case
if (!isset($data['type'])) {
$data['type'] = array();
}
// the fields that need to be filled are in data->type array:
// pk fields are unfilled
// fk fields are filled with the fk_id 'int_pk_name' value
foreach ($data['type'] as $el_name => $type) {
$_data[$el_name] = '';
if ($el_name == $data['pk_name']) {
if (isset($data['pk_name']) &&
$el_name == $data['pk_name']
) {
// do nothing for pk name
} elseif (isset($data['fk_name']) &&
$el_name == $data['fk_name'] &&
@@ -1985,8 +2059,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
}
}
$data['content'][] = $_data;
$data['pos'][] = array(0 => $pos); // this is for the checkboxes
// $this->debug('CFG ELEMENT LIST FILL', 'Pos: '.$pos.'/'.$pos_max.', Content: '.count($data['content']).', Pos: '.count($data['pos']));
// this is for the checkboxes
$data['pos'][] = array(
0 => $pos
);
$this->debug('CFG ELEMENT LIST FILL', 'Pos: '.$pos.'/'.$pos_max.', Content: '.count($data['content']).', Pos: '.count($data['pos']));
}
}
}