Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions languages/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@
<string name="SYS_LAST_EDITED_AT">Last edited at #VAR1#</string>
<string name="SYS_LAST_EDITED_BY">Last edited by #VAR1# at #VAR2#</string>
<string name="SYS_LAST_LOGIN_ON">Last login on #VAR1# at #VAR2#</string>
<string name="SYS_LAST_LOGIN">Last login</string>
<string name="SYS_LAST_POST">Last post</string>
<string name="SYS_LAST_REPLY_BY_AT">#VAR1#Last reply#VAR2# by #VAR3# at #VAR4#</string>
<string name="SYS_LASTNAME">Surname</string>
Expand Down Expand Up @@ -1126,6 +1127,7 @@
<string name="SYS_NUMBER_OF_ENTRIES_PER_PAGE">Number of entries per page</string>
<string name="SYS_NUMBER_OF_ENTRIES_PER_PAGE_DESC">Number of entries that are displayed on a page. If there are more entries, a pagination is added to the page. If the value is 0, all entries on a page are listed and the pagination is deactivated. (Default setting: #VAR1#)</string>
<string name="SYS_NUMBER_OF_ENTRIES_PER_PAGE_SELECT_DESC">Number of entries that are displayed on a page. If there are more entries, a pagination is added to the page. If the value is "All", all entries on a page are listed and the pagination is deactivated. (Default setting: #VAR1#)</string>
<string name="SYS_NUMBER_OF_LOGINS">Number of logins</string>
<string name="SYS_NUMBER_OF_POSTS_PER_PAGE">Number of posts per page</string>
<string name="SYS_NUMBER_OF_TOPICS_PER_PAGE">Number of topics per page</string>
<string name="SYS_NUMBER_RECIPIENTS">Number of recipients</string>
Expand Down Expand Up @@ -1325,6 +1327,7 @@
<string name="SYS_ROLE_MEMBERSHIPS">Role memberships</string>
<string name="SYS_ROLE_MEMBERSHIPS_CHANGE">Change role memberships</string>
<string name="SYS_ROLE_NAME_EXISTS">Role with same name already exists in this category.</string>
<string name="SYS_ROLE_PAST">Past role</string>
<string name="SYS_ROLE_RIGHTS">Role Rights</string>
<string name="SYS_ROLE_SELECT_RIGHT">You do not have permission to select role #VAR1#.\nPlease try to select another role.</string>
<string name="SYS_ROLE_SELECTION">Role selection</string>
Expand Down Expand Up @@ -1707,6 +1710,7 @@
<string name="SYS_UTF32BE">UTF-32BE</string>
<string name="SYS_UTF32LE">UTF-32LE</string>
<string name="SYS_UTF8">UTF-8</string>
<string name="SYS_UUID">Unique user ID</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within the list configuration we used SYS_UNIQUE_ID. I think we should use the same string in the category report. So we don't need SYS_UUID translation key.

<string name="SYS_VALID_FROM" description="Date valid from">Valid from</string>
<string name="SYS_VALID_TO" description="Date valid to">Valid until</string>
<string name="SYS_VALUE">Value</string>
Expand Down
86 changes: 81 additions & 5 deletions modules/category-report/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
* add : add a configuration
* delete : delete a configuration
* copy : copy a configuration
*
* Each column will have a select box for profile fields and roles. Internally, role properties are stored as rNN, lNN, wNN, etc.
* For the select box, all these are transformed to rNN (so the select box allows selecting the desired role), and the actual first
* letter is passed on to the second select box to determine the role property!
* When saving, the values from both select boxes are merged together again!
*
***********************************************************************************************
*/
Expand Down Expand Up @@ -75,17 +80,30 @@
$javascriptCode = 'var arr_user_fields = createProfileFieldsArray();
function createUserFieldSelect(config, val = null)
{
var category = "";
var htmlCboFields = "<select class=\"form-control\" size=\"1\" name=\"columns" + config + "[]\" class=\"ListProfileField\" >" +
// first letters that indicate membership property -> second select box to be displayed!
const rolePropIds = new Set(arr_role_props.map(o => String(o.id).toLowerCase()));
const raw = (val ?? "").toString().trim();
const first = raw.charAt(0).toLowerCase();
if (rolePropIds.has(first) && raw != "ddummy") {
val = "r" + raw.slice(1);
}

var category = "";
var htmlCboFields = "<select class=\"form-control ListProfileField\" size=\"1\" name=\"columns" + config + "[]\" >" +
"<option value=\"\"></option>";
for (const field of arr_user_fields) {
if (category != field.cat_name) {
var fieldtype = String(field.id).charAt(0).toLowerCase();
if (rolePropIds.has(fieldtype) && (fieldtype !== "r") && (field.id !== "ddummy")) {
continue;
}

if (category !== field.cat_name) {
if (category.length > 0) {
htmlCboFields += "</optgroup>";
}
htmlCboFields += "<optgroup label=\"" + field.cat_name + "\">";
category = field.cat_name;
}
}
var selected = ((val != null) && (field.id == val)) ? " selected=\"selected\" " : "";
htmlCboFields += "<option value=\"" + field.id + "\" " + selected + ">" + field.data + "</option>";
}
Expand All @@ -95,6 +113,59 @@ function createUserFieldSelect(config, val = null)
htmlCboFields += "</select>";
return htmlCboFields;
};
var arr_role_props = createRolePropertiesArray();
function createUserRoleSelect(config, val = null) {
// allowed first letters
const allowedIds = new Set(arr_role_props.map(o => String(o.id)));

// parse value
const raw = (val ?? "").toString().trim();
const first = raw.charAt(0);
const rest = raw.slice(1);

// valid only if first in set AND rest is numeric
const isValid = allowedIds.has(first) && /^\\d+$/.test(rest);

// hide (do NOT disable) when invalid
const hideAttr = isValid ? "" : " style=\\"display:none\\"";

// build select with template literals
let html = `<select class="form-control ListProfileField" size="1" name="columnsRoleProp${config}[]"${hideAttr}>`;
//html += `<option value=""${isValid ? " selected=\\"selected\\"" : ""}></option>`;
for (const field of arr_role_props) {
const selected = (isValid && String(field.id).toLowerCase() === first) ? " selected=\\"selected\\"" : "";
html += `<option value="${field.id}"${selected}>${field.data}</option>`;
}
html += "</select>";
return html;
};

// Call this once per config *after* you render the selects for that config
function setupRolePropToggles(config) {
const selField = `select[name="columns${config}[]"]`;
const selRole = `select[name="columnsRoleProp${config}[]"]`;

function applyToPair($field, $role) {
const v = ($field.val() || \'\').toString().trim();
const isRnn = /^r\d+$/.test(v); // r + digits
$role.toggle(isRnn);
}

// Initial pass for existing rows
$(selField).each(function(i){
const $field = $(this);
const $role = $(selRole).eq(i);
if ($role.length) applyToPair($field, $role);
});

// Live updates for changes (works for dynamically added rows too)
$(document).on(\'change input\', selField, function() {
const i = $(selField).index(this);
const $field = $(this);
const $role = $(selRole).eq(i);
if ($role.length) applyToPair($field, $role);
});
}
';
$javascriptCode .= '
function addColumnToConfiguration(config, val = null)
Expand All @@ -105,7 +176,7 @@ function addColumnToConfiguration(config, val = null)
var newCellCount = newTableRow.insertCell();
newCellCount.setAttribute("class", "CategoryReportColumnNumber");
var newCellField = newTableRow.insertCell(-1);
newCellField.innerHTML = createUserFieldSelect(config, val);
newCellField.innerHTML = createUserFieldSelect(config, val) + createUserRoleSelect(config, val);
var newCellButtons = newTableRow.insertCell(-1);
newCellButtons.innerHTML = " <a class=\"admidio-icon-link admidio-move-row\" style=\"padding-left: 0pt; padding-right: 0pt;\">" +
" <i class=\"bi bi-arrows-move handle\" data-bs-toggle=\"tooltip\" title=\"' . $gL10n->get('SYS_MOVE_VAR') . '\"></i></a>" +
Expand Down Expand Up @@ -139,6 +210,7 @@ function createColumnsArray{$key}() {
items: \"tr\",
update: updateNumbering
});
setupRolePropToggles($key);
";
}

Expand All @@ -149,6 +221,10 @@ function createProfileFieldsArray()
{
return ' . json_encode(array_values($report->headerSelection), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . ';
};
function createRolePropertiesArray()
{
return ' . json_encode(array_values($report->headerRolePropSelection), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . ';
};
function updateNumbering() {
$(".catreport-columns-table").each(function() {
$(this).find("tbody tr").each(function(index) {
Expand Down
14 changes: 13 additions & 1 deletion modules/category-report/preferences_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@
throw new Exception('SYS_FIELD_EMPTY', array('SYS_COLUMN'));
}

$values['col_fields'] = implode(',', $_POST['columns' . $conf]);
// role selection and role property selection is split into two select boxes.
// Role selection in the first select box uses only the rNN (with NN the ID of
// the role) id, while the second select box allows the user to select the
// property (r, l, w, f, b, e, d)
// Here we need to merge the two arrays to one.
$columns = array_map(function($r, $rprop) {
if ($r[0]=='r') {
return $rprop . substr($r, 1);
} else {
return $r;
}
}, $_POST['columns' . $conf], $_POST['columnsRoleProp' . $conf]);
$values['col_fields'] = implode(',', $columns);
$config[] = $values;
}

Expand Down
Loading