diff --git a/4dev/database/data/edit_tables.sql b/4dev/database/data/edit_tables.sql index 838dc517..2439fbf9 100755 --- a/4dev/database/data/edit_tables.sql +++ b/4dev/database/data/edit_tables.sql @@ -51,6 +51,7 @@ INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHE DELETE FROM edit_access_right; INSERT INTO edit_access_right (name, level, type) VALUES ('Default', -1, 'default'); INSERT INTO edit_access_right (name, level, type) VALUES ('No Access', 0, 'none'); +INSERT INTO edit_access_right (name, level, type) VALUES ('List', 10, 'list'); INSERT INTO edit_access_right (name, level, type) VALUES ('Read', 20, 'read'); INSERT INTO edit_access_right (name, level, type) VALUES ('Translator', 30, 'mod_trans'); INSERT INTO edit_access_right (name, level, type) VALUES ('Modify', 40, 'mod'); diff --git a/www/layout/admin/javascript/edit.jq.js b/www/layout/admin/javascript/edit.jq.js index a0ea1601..6eab6076 100644 --- a/www/layout/admin/javascript/edit.jq.js +++ b/www/layout/admin/javascript/edit.jq.js @@ -605,7 +605,7 @@ function html_options(name, data, selected = '', options_only = false, return_st // NOTE : USE THIS CALL, the above one is deprecated // METHOD: html_options // PARAMS: name/id, array for the options, -// selected item uid +// selected item uid [drop down string, multi select array] // multiple [def 0] if this is 1 or larger, the drop down will be turned into multiple select // the number sets the size value unless it is 1, then it is default // options_only [def false] if this is true, it will not print the select part @@ -644,14 +644,18 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl // for (const [key, value] of Object.entries(data)) { for (const key of data_list) { value = data[key]; - console.log('create [%s] options: key: %s, value: %s', name, key, value); + // console.log('create [%s] options: key: %s, value: %s', name, key, value); // basic options init options = { 'label': value, 'value': key }; // add selected if matching - if (selected == key) { + if (multiple == 0 && !Array.isArray(selected) && selected == key) { + options.selected = ''; + } + // for multiple, we match selected as array + if (multiple == 1 && Array.isArray(selected) && selected.indexOf(key) != -1) { options.selected = ''; } // create the element option diff --git a/www/layout/admin/javascript/edit.pt.js b/www/layout/admin/javascript/edit.pt.js index 0f66430b..2d04c55f 100644 --- a/www/layout/admin/javascript/edit.pt.js +++ b/www/layout/admin/javascript/edit.pt.js @@ -683,7 +683,7 @@ function html_options(name, data, selected = '', options_only = false, return_st // NOTE : USE THIS CALL, the above one is deprecated // METHOD: html_options // PARAMS: name/id, array for the options, -// selected item uid +// selected item uid [drop down string, multi select array] // multiple [def 0] if this is 1 or larger, the drop down will be turned into multiple select // the number sets the size value unless it is 1, then it is default // options_only [def false] if this is true, it will not print the select part @@ -722,14 +722,18 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl // for (const [key, value] of Object.entries(data)) { for (const key of data_list) { value = data[key]; - console.log('create [%s] options: key: %s, value: %s', name, key, value); + // console.log('create [%s] options: key: %s, value: %s', name, key, value); // basic options init options = { 'label': value, 'value': key }; // add selected if matching - if (selected == key) { + if (multiple == 0 && !Array.isArray(selected) && selected == key) { + options.selected = ''; + } + // for multiple, we match selected as array + if (multiple == 1 && Array.isArray(selected) && selected.indexOf(key) != -1) { options.selected = ''; } // create the element option diff --git a/www/lib/CoreLibs/Basic.inc b/www/lib/CoreLibs/Basic.inc index 16f40543..a3f6b7f3 100644 --- a/www/lib/CoreLibs/Basic.inc +++ b/www/lib/CoreLibs/Basic.inc @@ -1088,6 +1088,84 @@ class Basic return false; } + // METHOD: arrayMergeRecursive + // PARAMS: array, array, ..., true/false flag how to handle key + // key flag: true: handle keys as string or int, default false: all keys are string + // RETURN: merged array + // DESC : correctly recursive merges as an array as array_merge_recursive just glues things together + public static function arrayMergeRecursive() + { + // croak on not enough arguemnts (we need at least two) + if (func_num_args() < 2) { + trigger_error(__FUNCTION__ .' needs two or more array arguments', E_USER_WARNING); + return; + } + // default key is not string + $key_is_string = false; + $arrays = func_get_args(); + // if last is not array, then assume it is trigger for key is always string + if (!is_array(end($arrays))) { + if (array_pop($arrays)) { + $key_is_string = true; + } + } + // check that arrays count is at least two, else we don't have enough to do anything + if (count($arrays) < 2) { + trigger_error(__FUNCTION__.' needs two or more array arguments', E_USER_WARNING); + return; + } + $merged = array(); + while ($arrays) { + $array = array_shift($arrays); + if (!is_array($array)) { + trigger_error(__FUNCTION__ .' encountered a non array argument', E_USER_WARNING); + return; + } + if (!$array) { + continue; + } + foreach ($array as $key => $value) { + // if string or if key is assumed to be string do key match else add new entry + if (is_string($key) || $key_is_string === false) { + if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) { + // $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string); + $merged[$key] = Basic::arrayMergeRecursive($merged[$key], $value, $key_is_string); + } else { + $merged[$key] = $value; + } + } else { + $merged[] = $value; + } + } + } + return $merged; + } + + // METHOD: arrayFlatForKey + // PARAMS: array (nested) + // search, key to find that has no sub leaf and will be pushed up + // RETURN: modified array + // DESC : searches for key -> value in an array tree and writes the value one level up + // this will remove this leaf will all other values + public static function arrayFlatForKey($array, $search) + { + foreach ($array as $key => $value) { + // if it is not an array do just nothing + if (is_array($value)) { + // probe it has search key + if (isset($value[$search])) { + // set as current + $array[$key] = $value[$search]; + } else { + // call up next node down + // $array[$key] = call_user_func(__METHOD__, $value, $search); + $array[$key] = Basic::arrayFlatForKey($value, $search); + } + } + } + return $array; + } + // METHOD: inArrayAny // WAS : in_array_any // PARAMS: needle: array