Skip to content

Commit

Permalink
faster and cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
codecivil committed Nov 22, 2024
1 parent 63ab9eb commit 5976baa
Show file tree
Hide file tree
Showing 18 changed files with 456 additions and 31 deletions.
16 changes: 16 additions & 0 deletions nightly/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#v1.8.9
======
22.11.2024

* test and statement for firefox dependency (subtable accordion needs CSS :has; in Firefox available since 121;
also nested css (117+) will be applied in the future)
* improved subtable layout: allows css accordion for up to 100 subtables per table
* openStatAdmin: create_structure.php now rudimentarily php8-compliant
* implement indexing as background task of mariadb (but perhaps not very effective since many
data model filters use LIKE '%WORD%' for comparison, so cannot use indices)
* Change in applyFilters: numbers in sql querys without quotation marks (makes query faster)
* scripts/getParamaters.php: experimental reconversion from strings to numbers if applicable
* Fix in db_functions.php: Counts of attributions led to empty display of attribution in counted
entries
* Cleanup of code with respect to attribution counts

#v1.8.8
======
26.08.2024
Expand Down
7 changes: 7 additions & 0 deletions nightly/changelog_user
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#v1.8.9
======

* Test und Anzeige der Mindestfirefoxversion
* verbessertes Layout und Verhalten von Untertabellen
* Anzeige von Zuordnungen hat bei Zählungen nicht funktioniert

#v1.8.8
======

Expand Down
22 changes: 17 additions & 5 deletions nightly/core/classes/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ protected function _getOptions(int $compound = -1) { // -1 means not compound, e
$_stmt_array['stmt'] = 'SELECT typelist,edittype,referencetag,defaultvalue,role_'.$_SESSION['os_role'].' AS role, restrictrole_'.$_SESSION['os_role'].' AS restrictrole, role_'.$_SESSION['os_parent'].' AS parentrole, restrictrole_'.$_SESSION['os_parent'].' AS restrictparentrole FROM '.$this->table.'_permissions WHERE keymachine = ?';
$_stmt_array['str_types'] = 's';
$_stmt_array['arr_values'] = array($this->key);
$_result = execute_stmt($_stmt_array,$this->connection,true)['result'][0];
$_result = execute_stmt($_stmt_array,$this->connection,true);
if ( isset($_result['result']) ) { $_result = $_result['result']; } else { $_result = array(); };
if ( isset($_result[0]) ) { $_result = $_result[0]; } else { $_result = array(); };
//return if result is empty (currently for counts; they correspond to no column)
if ( sizeof($_result) == 0 ) {
return array("options"=>array(), "conditions"=>array(), "dependencies"=>array());
}
//
$_result['edittype'] = explode(' + ',$_result['edittype']);
if ( isset($_result['edittype'][$effective_compound]) ) {
$_result['edittype'] = $_result['edittype'][$effective_compound];
Expand Down Expand Up @@ -239,7 +246,9 @@ protected function _getOptions(int $compound = -1) { // -1 means not compound, e
$_this_key = '`'.$this->key.'`';
unset($_stmt_array);
$_stmt_array['stmt'] = 'SELECT '.$_this_key.' FROM `view__' . $this->table . '__' . $_SESSION['os_role'].'`';
$options = execute_stmt($_stmt_array,$this->connection)['result'][$this->key];
$options = execute_stmt($_stmt_array,$this->connection);
if ( isset($options['result']) ) { $options = $options['result']; } else { $options = array(); };
if ( isset($options[$this->key]) ) { $options = $options[$this->key]; } else { $options = array(); };
break;
}
if ( is_array($options) AND sizeof($options) > 0 AND ( ! isset($options[0]) OR ! is_array($options[0]) ) ) {
Expand Down Expand Up @@ -877,7 +886,7 @@ public function edit(string $_default, bool $_single = true) {
?>
<label for="note_<?php echo($_cbcolor); ?>_cb<?php echo($rnd); ?>" class="unlimitedWidth note_<?php echo($_cbcolor); ?>"><i class="far fa-square"></i></label>
<?php } ?>
<textarea <?php echo($_disabled.' '.$_onchange_text.' '.$_maxlength); ?> onchange="note_synctext(this)" spellcheck="true" type="text" id="db_<?php echo($key.$rnd); ?>" name="<?php echo($this->table.'__'.$this->key.$_arrayed); ?>[]" class="textarea db_formbox db_<?php echo($key.' note_'.$default[0]); ?>" value="" rows="3" wrap="hard"><?php echo($default[1]); ?></textarea>
<textarea <?php echo($_disabled.' '.$_onchange_text.' '.$_maxlength); ?> spellcheck="true" type="text" id="db_<?php echo($key.$rnd); ?>" name="<?php echo($this->table.'__'.$this->key.$_arrayed); ?>[]" class="textarea db_formbox db_<?php echo($key.' note_'.$default[0]); ?>" value="" rows="3" wrap="hard"><?php echo($default[1]); ?></textarea>
</div>
</div>
<?php break;
Expand Down Expand Up @@ -947,9 +956,11 @@ public function choose(array $checked) {
$_stmt_array['stmt'] = 'SELECT typelist,edittype,referencetag,keyreadable,role_'.$_SESSION['os_role'].' AS role, restrictrole_'.$_SESSION['os_role'].' AS restrictrole, role_'.$_SESSION['os_parent'].' AS parentrole, restrictrole_'.$_SESSION['os_parent'].' AS restrictparentrole FROM '.$this->table.'_permissions WHERE keymachine = ?';
$_stmt_array['str_types'] = 's';
$_stmt_array['arr_values'] = array($this->key);
$_result = execute_stmt($_stmt_array,$this->connection,true)['result'][0];
$_result = execute_stmt($_stmt_array,$this->connection,true);
if ( isset($_result['result']) ) { $_result = $_result['result']; } else { $_result = array(); };
if ( isset($_result[0]) ) { $_result = $_result[0]; } else { $_result = array(); };
//if it is an attribution, then $_result is not set:
if ( ! isset($_result) ) {
if ( sizeof($_result) == 0) {
$_stmt_array = array();
$_stmt_array['stmt'] = 'SELECT tablereadable AS keyreadable,allowed_roles,iconname FROM os_tables WHERE tablemachine = ?';
$_stmt_array['str_types'] = 's';
Expand All @@ -961,6 +972,7 @@ public function choose(array $checked) {
$_result['role'] = '0';
$_result['restrictrole'] = '';
$_result['parentrole'] = '0';
$_result['referencetag'] = '';
$_result['restrictparentrole'] = '';
}
$options_array = $this->_getOptions();
Expand Down
5 changes: 3 additions & 2 deletions nightly/core/data/info.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
$author = "codecivil Dr. Marco Kühnel ICT Services";
$license = "GPLv3";
$versiondate = "27.08.2024";
$versionnumber = "1.8.8";
$versiondate = "22.11.2024";
$versionnumber = "1.8.9";
$firefox_least_featureversion = "121";
$contact = "[email protected]";
?>
22 changes: 21 additions & 1 deletion nightly/core/functions/db_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ function _execute_stmt(array $stmt_array, mysqli $conn, bool $log = false)
$stmt = ''; $str_types = ''; $arr_values = ''; $message = '';
if (isset($stmt_array['stmt']) ) { $stmt = $stmt_array['stmt']; };
if (isset($stmt_array['str_types']) ) { $str_types = $stmt_array['str_types']; };
if (isset($stmt_array['arr_values']) ) { $arr_values = $stmt_array['arr_values']; };
if (isset($stmt_array['arr_values']) ) {
$arr_values = $stmt_array['arr_values'];
if ( ! is_array($arr_values) ) { $arr_values = array($arr_values); }
};
if (isset($stmt_array['message']) ) { $message = $stmt_array['message']; }
$dbMessage = ''; $dbMessageGood = '';
//often saving of new entries is rejected; I think this is due to an overload of the mariadb server; so, cynic who I am, let's try it more often...
Expand Down Expand Up @@ -79,6 +82,16 @@ function execute_stmt(array $stmt_array, mysqli $conn, bool $flip = false)
}
}

function flipResults(array $return) {
if ( isset($return['result']) ) {
//use array_map with callback "null" on sequence of "inner" arrays of $a, see
//https://www.php.net/manual/en/function.array-map.php
array_unshift($return['result'], null);
$return['result'] = call_user_func_array("array_map", $return['result']);
}
return $return;
}


function dbAction(array $_PARAMETER,mysqli $conn) {
$message = '';
Expand Down Expand Up @@ -483,6 +496,9 @@ function addSubtablesToStmt($table,$_table_result,$_config,$stmt) {
if ( isset($_tmp_keys[$index]) AND $_tmp_keys[$index] == $_table_result[$i]['tablemachine'] ) { unset($_tmp_keys[$index]); }
}
}
//save $_table_result in a new variable, since it is redefined a few lines below (and clean up code later)
$_tables_here = json_decode(json_encode($_table_result),true);
//
$_tmp_keys = array_values($_tmp_keys);
if ( sizeof($_tmp_keys) == 0 ) { $_tmp_keys = array('id_'.$table); }
unset($_stmt_array); $_stmt_array = array();
Expand Down Expand Up @@ -606,6 +622,10 @@ function addSubtablesToStmt($table,$_table_result,$_config,$stmt) {
{
if ( substr($value,0,strlen($_tmp_table)) != $_tmp_table ) { unset($_tmp_keys[$index]); }
else { $_tmp_keys[$index] = substr($value,strlen($_tmp_table)+2); }
//exclude counts of attributions (they do not exist as columns)):
for ( $i = 0; $i < sizeof($_tables_here); $i++ ) {
if ( isset($_tmp_keys[$index]) AND $_tmp_keys[$index] == $_tables_here[$i]['tablemachine'] ) { unset($_tmp_keys[$index]); }
}
}
$_tmp_keys = array_values($_tmp_keys);
if ( sizeof($_tmp_keys) == 0 ) { $_tmp_keys = array('id_'.$_tmp_table); };
Expand Down
26 changes: 19 additions & 7 deletions nightly/core/functions/sidebar_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,13 @@ function applyFilters(array $parameter, mysqli $conn, bool $_complement = false,
}
//select from former result if requested; also here for economic reasons...
if ( isset($searchinresults) and $searchinresults ) {
$_WHERE .= $komma0.'(`view__'.$table.'__'.$_SESSION['os_role'].'`.id_'.$table.' IS NULL OR `view__'.$table.'__'.$_SESSION['os_role'].'`.id_'.$table.' IN ('.implode(',',json_decode($_SESSION['results'],true)[$table]).') )';
$komma0 = " AND ";
$komma2 = " AND (";
$_tableresults = json_decode($_SESSION['results'],true)[$table];
//do not restrict if $_tableresults is empty (== [-1]); otherwise search in complements wont work
if ( sizeof($_tableresults) > 1 ) {
$_WHERE .= $komma0.'(`view__'.$table.'__'.$_SESSION['os_role'].'`.id_'.$table.' IS NULL OR `view__'.$table.'__'.$_SESSION['os_role'].'`.id_'.$table.' IN ('.implode(',',json_decode($_SESSION['results'],true)[$table]).') )';
$komma0 = " AND ";
$komma2 = " AND (";
}
}
//
$JOINSRC[$HIERARCHY[$tindex]] = $table;
Expand Down Expand Up @@ -783,11 +787,15 @@ function applyFilters(array $parameter, mysqli $conn, bool $_complement = false,
{
// $_WHERE .= $komma2.'(`'.$key."` = '".date("Y-m-d H:i:s",$value)."'";
if ( ! isset($values[5001][$i]) OR $values[5001][$i] == '' ) { $values[5001][$i] = '0'; }
$_WHERE .= $komma2.'('.$_sqlforkey." ".$_ge." '".$values[5001][$i]."'";
//$_WHERE .= $komma2.'('.$_sqlforkey." ".$_ge." '".$values[5001][$i]."'";
//DO NOT USE TICKS: THE CONVERSION OF STRINGS TO NUMBERS COSTS A LOT OF TIME!!!
$_WHERE .= $komma2.'('.$_sqlforkey." ".$_ge." ".$values[5001][$i];
$komma2 = $_komma_date_inner;
$bracket = ')';
if ( ! isset($values[5002][$i]) OR $values[5002][$i] == '' ) { $values[5002][$i] = '1000000000'; }
$_WHERE .= $komma2.''.$_sqlforkey." ".$_le." '".$values[5002][$i]."')";
//$_WHERE .= $komma2.''.$_sqlforkey." ".$_le." '".$values[5002][$i]."')";
//DO NOT USE TICKS: THE CONVERSION OF STRINGS TO NUMBERS COSTS A LOT OF TIME!!!
$_WHERE .= $komma2.''.$_sqlforkey." ".$_le." ".$values[5002][$i].")";
$komma2 = $_komma_outer;
$bracket = ')';
}
Expand Down Expand Up @@ -846,11 +854,15 @@ function applyFilters(array $parameter, mysqli $conn, bool $_complement = false,
{
// $_WHERE .= $komma2.'(`'.$key."` = '".date("Y-m-d H:i:s",$value)."'";
if ( ! isset($cmp_values[$compoundnumber][5001][$i]) OR $cmp_values[$compoundnumber][5001][$i] == '' ) { $cmp_values[$compoundnumber][5001][$i] = '0'; }
$_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey."`,'$[".$compoundnumber."]'),'$[".$j."]') ".$_ge." '".$cmp_values[$compoundnumber][5001][$i]."'";
// $_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey."`,'$[".$compoundnumber."]'),'$[".$j."]') ".$_ge." '".$cmp_values[$compoundnumber][5001][$i]."'";
// DO NOT USE TICKS FOR NUMBER VALUES, see above
$_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey."`,'$[".$compoundnumber."]'),'$[".$j."]') ".$_ge." ".$cmp_values[$compoundnumber][5001][$i];
$komma2 = $_komma_date_inner;
$bracket = ')';
if ( ! isset($cmp_values[$compoundnumber][5002][$i]) OR $cmp_values[$compoundnumber][5002][$i] == '' ) { $cmp_values[$compoundnumber][5002][$i] = '1000000000'; }
$_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey.",'$[".$compoundnumber."]'),'$[".$j."]') ".$_le." '".$cmp_values[$compoundnumber][5002][$i]."')";
// $_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey.",'$[".$compoundnumber."]'),'$[".$j."]') ".$_le." '".$cmp_values[$compoundnumber][5002][$i]."')";
// DO NOT USE TICKS FOR NUMBER VALUES, see above
$_WHERE .= $komma2.'(JSON_VALUE(JSON_QUERY('.$_sqlforkey.",'$[".$compoundnumber."]'),'$[".$j."]') ".$_le." ".$cmp_values[$compoundnumber][5002][$i].")";
$komma2 = $_komma_cmp;
$bracket = ')';
}
Expand Down
14 changes: 10 additions & 4 deletions nightly/core/html/create_structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
require_once('../../core/functions/display_functions.php');
require_once('../../settings.php');
require_once('../../core/data/debugdata.php');

//mysqli does not throw errors (php8 makes errors fatal, so temporarily switch back to php7.4 behaviour)
mysqli_report(MYSQLI_REPORT_OFF);
?>

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de-DE">
Expand Down Expand Up @@ -893,7 +896,7 @@ function _adminActionBefore(array $PARAMETER, mysqli $conn) {
break;
case 'insert':
unset($_stmt_array);
$_stmt_array['stmt'] = "ALTER TABLE `".$_propertable."` ADD COLUMN `".$PARAMETER['keymachine']."` ".$PARAMETER['typelist'].$_DEFAULT;
$_stmt_array['stmt'] = "ALTER TABLE `".$_propertable."` ADD COLUMN IF NOT EXISTS `".$PARAMETER['keymachine']."` ".$PARAMETER['typelist'].$_DEFAULT;
_execute_stmt($_stmt_array,$conn);
break;
case 'delete':
Expand Down Expand Up @@ -1252,7 +1255,7 @@ function recreateView(string $_propertable, mysqli $conn) {
$_stmt_array['stmt'] = "SELECT delete_roles,parentmachine FROM os_tables WHERE tablemachine = ?";
$_stmt_array['str_types'] = "s";
$_stmt_array['arr_values'] = array();
$_stmt_array['arr_values'][] = $_propertable;
$_stmt_array['arr_values'][] = str_replace('MAIN','',$_propertable); //MAIN is up to now the only tablemachine extension being a view
$_os_tables_result = execute_stmt($_stmt_array,$conn,true)['result'][0];
$_delete_roles = $_os_tables_result['delete_roles'];
$PARAMETER['parentmachine'] = $_os_tables_result['parentmachine'];
Expand Down Expand Up @@ -1304,7 +1307,7 @@ function recreateView(string $_propertable, mysqli $conn) {
}
unset($_stmt_array);
//query os_roles into $PARAMETER['rolename'] in a loop
$_stmt_array['stmt'] = "SELECT id AS roleid,parentid,rolename FROM os_roles";
$_stmt_array['stmt'] = "SELECT id AS roleid,parentid,rolename FROM os_roles WHERE rolename != '_none_'";
$_result_array = _execute_stmt($_stmt_array,$conn); $_result=$_result_array['result'];
if ( $_result AND $_result->num_rows > 0 ) {
while ($row=$_result->fetch_assoc()) {
Expand Down Expand Up @@ -1332,8 +1335,11 @@ function recreateView(string $_propertable, mysqli $conn) {
$_values = str_replace('THIS_ROLE',$PARAMETER['rolename'],$_restrict['role']);
$_values = str_replace('CHILD_ROLE','',$_values);
$_values = str_replace('USER','',$_values);
file_put_contents('/var/www/test/openStat/mylog.txt','test1: '.$_values.PHP_EOL,FILE_APPEND);
$_values = trimList($_values);
$_values = implode("\',\'",json_decode($_values,true));
if ( $_values != '' ) {
$_values = implode("\',\'",json_decode($_values,true));
}
if ( $_values != ',' AND $_values != '' ) {
//key has one of the values or, for multiple combined keys: first component's last entry is one of the values
//kind of hotfix for now; may be subject to change!
Expand Down
2 changes: 2 additions & 0 deletions nightly/core/scripts/getParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
}
}

//experimental: recover numbers from strings (converted by JS's FormData object at submission)
$PARAMETER = json_decode(json_encode($PARAMETER,JSON_NUMERIC_CHECK),true);
?>
5 changes: 2 additions & 3 deletions nightly/public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,13 @@ div#wasistneu_wrapper { width: 92%; margin: 0.5rem auto; box-shadow: 0 2px 5px #
.details .export { text-align: center; }
.details .toggle + div { display: none; }
.details .toggle:checked + div { display: block; }
.details .subtoggle ~ .subtable { display: none; }
.details .subtoggle ~ .subtoggle ~ .subtable { display: initial; }
.details .subtoggle:checked ~ .subtable { display: block; }
/* toggling of subtables is now in subtables.css */
.details .subtoggle:checked + div label .open { display: inline; }
.details .subtoggle:checked + div label .closed { display: none; }
.details .subtoggle:not(:checked) + div label .open { display: none; }
.details .subtoggle:not(:checked) + div label .closed { display: inline; }
.details .subtable_header { display: block; height: 2rem; background: var(--background-subtable-header); margin: 0.5rem; }
.details .subtable_header label { width: initial; float: none; text-align: left; padding: 0.5rem; }
/** SUGGESTion windows **/
.details .suggestions {
opacity: 0;
Expand Down
7 changes: 3 additions & 4 deletions nightly/public/css/main_clear_.css
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,13 @@ div#wasistneu_wrapper { width: 92%; margin: 0.5rem auto; box-shadow: 0 2px 5px #
.details .export { text-align: center; }
.details .toggle + div { display: none; }
.details .toggle:checked + div { display: block; }
.details .subtoggle ~ .subtable { display: none; }
.details .subtoggle ~ .subtoggle ~ .subtable { display: initial; }
.details .subtoggle:checked ~ .subtable { display: block; }
/* toggling of subtables is now in subtables.css */
.details .subtoggle:checked + div label .open { display: inline; }
.details .subtoggle:checked + div label .closed { display: none; }
.details .subtoggle:not(:checked) + div label .open { display: none; }
.details .subtoggle:not(:checked) + div label .closed { display: inline; }
.details .subtable_header { display: block; height: 2rem; background: var(--background-subtable-header); margin: 0.5rem; }
.details .subtable_header { display: block; height: 2rem; background: var(--background-subtable-header); margin: 0.5rem; position: sticky; top: 8.5rem; }
.details .subtable_header label { width: initial; float: none; text-align: left; padding: 0.5rem; }
/** SUGGESTion windows **/
.details .suggestions {
opacity: 0;
Expand Down
Loading

0 comments on commit 5976baa

Please sign in to comment.