Skip to content

Commit dfabb13

Browse files
committed
Columns in category report not added correctly #1566
1 parent 14b281c commit dfabb13

File tree

3 files changed

+271
-284
lines changed

3 files changed

+271
-284
lines changed

adm_program/modules/category-report/preferences.php

Lines changed: 78 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,39 @@
2020
require_once(__DIR__ . '/../../system/login_valid.php');
2121

2222
// only authorized user are allowed to start this module
23-
if (!$gCurrentUser->isAdministrator())
24-
{
23+
if (!$gCurrentUser->isAdministrator()) {
2524
$gMessage->show($gL10n->get('SYS_NO_RIGHTS'));
2625
}
2726

2827
// Initialize and check the parameters
29-
$getAdd = admFuncVariableIsValid($_GET, 'add', 'bool');
28+
$getAdd = admFuncVariableIsValid($_GET, 'add', 'bool');
3029
$getDelete = admFuncVariableIsValid($_GET, 'delete', 'numeric', array('defaultValue' => 0));
31-
$getCopy = admFuncVariableIsValid($_GET, 'copy', 'numeric', array('defaultValue' => 0));
30+
$getCopy = admFuncVariableIsValid($_GET, 'copy', 'numeric', array('defaultValue' => 0));
3231

3332
$report = new CategoryReport();
3433
$config = $report->getConfigArray();
3534
$catReportConfigs = array();
3635

3736
$headline = $gL10n->get('SYS_CATEGORY_REPORT') . ' - ' . $gL10n->get('SYS_CONFIGURATIONS');
3837

39-
if ($getAdd)
40-
{
41-
$config[] = array('id' => '', 'name' => '', 'col_fields' => '', 'selection_role' => '', 'selection_cat' => '', 'number_col' => '', 'default_conf' => false);
38+
if ($getAdd) {
39+
$config[] = array('id' => '', 'name' => '', 'col_fields' => '', 'selection_role' => '', 'selection_cat' => '', 'number_col' => '', 'default_conf' => false);
4240
// ohne $report->saveConfigArray(); ansonsten würden 'name' und 'col_fields' ohne Daten gespeichert sein
4341
}
4442

45-
if ($getDelete > 0)
46-
{
47-
$config[$getDelete-1]['id'] = $config[$getDelete-1]['id']*(-1); // id negieren, als Kennzeichen für "Deleted"
43+
if ($getDelete > 0) {
44+
$config[$getDelete - 1]['id'] = $config[$getDelete - 1]['id'] * (-1); // id negieren, als Kennzeichen für "Deleted"
4845
$config = $report->saveConfigArray($config);
4946
}
5047

51-
if ($getCopy > 0)
52-
{
53-
$config[] = array('id' => '',
54-
'name' => createName($config[$getCopy-1]['name']),
55-
'col_fields' => $config[$getCopy-1]['col_fields'],
56-
'selection_role' => $config[$getCopy-1]['selection_role'],
57-
'selection_cat' => $config[$getCopy-1]['selection_cat'],
58-
'number_col' => $config[$getCopy-1]['number_col'],
59-
'default_conf' => false);
48+
if ($getCopy > 0) {
49+
$config[] = array('id' => '',
50+
'name' => $report->createName($config[$getCopy - 1]['name']),
51+
'col_fields' => $config[$getCopy - 1]['col_fields'],
52+
'selection_role' => $config[$getCopy - 1]['selection_role'],
53+
'selection_cat' => $config[$getCopy - 1]['selection_cat'],
54+
'number_col' => $config[$getCopy - 1]['number_col'],
55+
'default_conf' => false);
6056
$config = $report->saveConfigArray($config);
6157
}
6258

@@ -82,7 +78,7 @@
8278
if (data === "success") {
8379
8480
formAlert.attr("class", "alert alert-success form-alert");
85-
formAlert.html("<i class=\"fas fa-check\"></i><strong>'.$gL10n->get('SYS_SAVE_DATA').'</strong>");
81+
formAlert.html("<i class=\"fas fa-check\"></i><strong>' . $gL10n->get('SYS_SAVE_DATA') . '</strong>");
8682
formAlert.fadeIn("slow");
8783
formAlert.animate({opacity: 1.0}, 2500);
8884
formAlert.fadeOut("slow");
@@ -100,29 +96,26 @@
10096
$javascriptCode = 'var arr_user_fields = createProfileFieldsArray();';
10197

10298
// create an array with the necessary data
103-
foreach($config as $key => $value)
104-
{
99+
foreach ($config as $key => $value) {
105100
$catReportConfigs[$key] = $value['name'];
106101
$javascriptCode .= '
107102
108-
var arr_default_fields'.$key.' = createColumnsArray'.$key.'();
109-
var fieldNumberIntern'.$key.' = 0;
103+
var arr_default_fields' . $key . ' = createColumnsArray' . $key . '();
104+
var fieldNumberIntern' . $key . ' = 0;
110105
111-
// Funktion fuegt eine neue Zeile zum Zuordnen von Spalten fuer die Liste hinzu
112-
function addColumn'.$key.'()
106+
// Function adds a new row for assigning columns to the list
107+
function addColumn' . $key . '()
113108
{
114109
var category = "";
115-
var fieldNumberShow = fieldNumberIntern'.$key.' + 1;
116-
var table = document.getElementById("mylist_fields_tbody'.$key.'");
117-
var newTableRow = table.insertRow(fieldNumberIntern'.$key.');
118-
newTableRow.setAttribute("id", "row" + (fieldNumberIntern'.$key.' + 1))
119-
//$(newTableRow).css("display", "none"); // ausgebaut wg. Kompatibilitaetsproblemen im IE8
110+
var table = document.getElementById("mylist_fields_tbody' . $key . '");
111+
var newTableRow = table.insertRow(fieldNumberIntern' . $key . ');
112+
newTableRow.setAttribute("id", "row" + (fieldNumberIntern' . $key . '))
120113
var newCellCount = newTableRow.insertCell(-1);
121-
newCellCount.innerHTML = (fieldNumberShow) + ".&nbsp;'.$gL10n->get('SYS_COLUMN').':";
114+
newCellCount.innerHTML = (fieldNumberIntern' . $key . ' + 1) + ".&nbsp;' . $gL10n->get('SYS_COLUMN') . ':";
122115
123-
// neue Spalte zur Auswahl des Profilfeldes
116+
// New column for selecting the profile field
124117
var newCellField = newTableRow.insertCell(-1);
125-
htmlCboFields = "<select class=\"form-control\" size=\"1\" id=\"column" + fieldNumberShow + "\" class=\"ListProfileField\" name=\"column'.$key.'_" + fieldNumberShow + "\">" +
118+
htmlCboFields = "<select class=\"form-control\" size=\"1\" id=\"column" + fieldNumberIntern' . $key . ' + "\" class=\"ListProfileField\" name=\"column' . $key . '_" + fieldNumberIntern' . $key . ' + "\">" +
126119
"<option value=\"\"></option>";
127120
for(var counter = 1; counter < arr_user_fields.length; counter++)
128121
{
@@ -138,14 +131,13 @@ function addColumn'.$key.'()
138131
139132
var selected = "";
140133
141-
// bei gespeicherten Listen das entsprechende Profilfeld selektieren
142-
// und den Feldnamen dem Listenarray hinzufuegen
143-
if(arr_default_fields'.$key.'[fieldNumberIntern'.$key.'])
134+
// for saved lists, select the corresponding profile field and add the field name to the list array
135+
if(arr_default_fields' . $key . '[fieldNumberIntern' . $key . '])
144136
{
145-
if(arr_user_fields[counter]["id"] == arr_default_fields'.$key.'[fieldNumberIntern'.$key.']["id"])
137+
if(arr_user_fields[counter]["id"] == arr_default_fields' . $key . '[fieldNumberIntern' . $key . ']["id"])
146138
{
147139
selected = " selected=\"selected\" ";
148-
arr_default_fields'.$key.'[fieldNumberIntern'.$key.']["data"] = arr_user_fields[counter]["data"];
140+
arr_default_fields' . $key . '[fieldNumberIntern' . $key . ']["data"] = arr_user_fields[counter]["data"];
149141
}
150142
}
151143
htmlCboFields += "<option value=\"" + arr_user_fields[counter]["id"] + "\" " + selected + ">" + arr_user_fields[counter]["data"] + "</option>";
@@ -154,24 +146,22 @@ function addColumn'.$key.'()
154146
newCellField.innerHTML = htmlCboFields;
155147
156148
$(newTableRow).fadeIn("slow");
157-
fieldNumberIntern'.$key.'++;
149+
fieldNumberIntern' . $key . '++;
158150
}
159151
160-
function createColumnsArray'.$key.'()
152+
function createColumnsArray' . $key . '()
161153
{
162154
var default_fields = new Array(); ';
163155
$fields = explode(',', $value['col_fields']);
164-
for ($number = 0; $number < count($fields); $number++)
165-
{
166-
// das ist nur zur Überprüfung, ob diese Freigabe noch existent ist
167-
// es koennte u.U. ja sein, dass ein Profilfeld oder eine Rolle seit der letzten Speicherung geloescht wurde
156+
for ($number = 0; $number < count($fields); $number++) {
157+
// this is only to check whether this release still exists
158+
// it could be that a profile field or role has been deleted since the last save
168159
$found = $report->isInHeaderSelection($fields[$number]);
169-
if ($found > 0)
170-
{
160+
if ($found > 0) {
171161
$javascriptCode .= '
172-
default_fields['. $number. '] = new Object();
173-
default_fields['. $number. ']["id"] = "'. $report->headerSelection[$found]["id"]. '";
174-
default_fields['. $number. ']["data"] = "'. $report->headerSelection[$found]["data"]. '";
162+
default_fields[' . $number . '] = new Object();
163+
default_fields[' . $number . ']["id"] = "' . $report->headerSelection[$found]["id"] . '";
164+
default_fields[' . $number . ']["data"] = "' . $report->headerSelection[$found]["data"] . '";
175165
';
176166
}
177167
}
@@ -187,58 +177,56 @@ function createProfileFieldsArray()
187177
var user_fields = new Array(); ';
188178

189179
// create an array for all columns with the necessary data
190-
foreach($report->headerSelection as $key => $value)
191-
{
180+
foreach ($report->headerSelection as $key => $value) {
192181
$javascriptCode .= '
193-
user_fields['. $key. '] = new Object();
194-
user_fields['. $key. ']["id"] = "'. $report->headerSelection[$key]['id'] . '";
195-
user_fields['. $key. ']["cat_name"] = "'. $report->headerSelection[$key]['cat_name']. '";
196-
user_fields['. $key. ']["data"] = "'. $report->headerSelection[$key]['data'] . '";
182+
user_fields[' . $key . '] = new Object();
183+
user_fields[' . $key . ']["id"] = "' . $report->headerSelection[$key]['id'] . '";
184+
user_fields[' . $key . ']["cat_name"] = "' . $report->headerSelection[$key]['cat_name'] . '";
185+
user_fields[' . $key . ']["data"] = "' . $report->headerSelection[$key]['data'] . '";
197186
';
198187
}
199188
$javascriptCode .= '
200189
return user_fields;
201190
}
202191
';
203192
$page->addJavascript($javascriptCode);
193+
$javascriptCodeExecute = '';
204194

205-
foreach($config as $key => $value)
206-
{
207-
$javascriptCode .= '
208-
for(var counter = 0; counter < '. count(explode(',', $value['col_fields'])). '; counter++) {
209-
addColumn'. $key. '();
195+
foreach ($config as $key => $value) {
196+
$javascriptCodeExecute .= '
197+
for(var counter = 0; counter < ' . count(explode(',', $value['col_fields'])) . '; counter++) {
198+
addColumn' . $key . '();
210199
}
211200
';
212201
}
213-
$page->addJavascript($javascriptCode, true);
202+
$page->addJavascript($javascriptCodeExecute, true);
214203

215204
$formConfigurations = new HtmlForm(
216-
'configurations_preferences_form', SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/category-report/preferences_function.php', array('form' => 'configurations')),
205+
'configurations_preferences_form', SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/category-report/preferences_function.php', array('form' => 'configurations')),
217206
$page, array('class' => 'form-preferences')
218207
);
219208

220209
$formConfigurations->addDescription($gL10n->get('SYS_CONFIGURATIONS_HEADER'));
221210
$formConfigurations->addLine();
222211
$currentNumberConf = 0;
223212

224-
foreach($config as $key => $value)
225-
{
226-
$formConfigurations->openGroupBox('configurations_group',++$currentNumberConf.'. '.$gL10n->get('SYS_CONFIGURATION'));
227-
$formConfigurations->addInput('name'.$key, $gL10n->get('SYS_DESIGNATION'), $value['name'],
213+
foreach ($config as $key => $value) {
214+
$formConfigurations->openGroupBox('configurations_group', ++$currentNumberConf . '. ' . $gL10n->get('SYS_CONFIGURATION'));
215+
$formConfigurations->addInput('name' . $key, $gL10n->get('SYS_DESIGNATION'), $value['name'],
228216
array('property' => HtmlForm::FIELD_REQUIRED));
229217
$html = '
230218
<div class="table-responsive">
231219
<table class="table table-condensed" id="mylist_fields_table">
232220
<thead>
233221
<tr>
234-
<th style="width: 20%;">'.$gL10n->get('SYS_ABR_NO').'</th>
235-
<th style="width: 37%;">'.$gL10n->get('SYS_CONTENT').'</th>
222+
<th style="width: 20%;">' . $gL10n->get('SYS_ABR_NO') . '</th>
223+
<th style="width: 37%;">' . $gL10n->get('SYS_CONTENT') . '</th>
236224
</tr>
237225
</thead>
238-
<tbody id="mylist_fields_tbody'.$key.'">
226+
<tbody id="mylist_fields_tbody' . $key . '">
239227
<tr id="table_row_button">
240228
<td colspan="2">
241-
<a class="icon-text-link" href="javascript:addColumn'.$key.'()"><i class="fas fa-plus-circle"></i> '.$gL10n->get('SYS_ADD_COLUMN').'</a>
229+
<a class="icon-text-link" href="javascript:addColumn' . $key . '()"><i class="fas fa-plus-circle"></i> ' . $gL10n->get('SYS_ADD_COLUMN') . '</a>
242230
</td>
243231
</tr>
244232
</tbody>
@@ -247,77 +235,45 @@ function createProfileFieldsArray()
247235
$formConfigurations->addCustomContent($gL10n->get('SYS_COLUMN_SELECTION'), $html, array('helpTextIdLabel' => 'SYS_COLUMN_SELECTION_DESC'));
248236

249237
$sql = 'SELECT rol_id, rol_name, cat_name
250-
FROM '.TBL_CATEGORIES.' , '.TBL_ROLES.'
238+
FROM ' . TBL_CATEGORIES . ' , ' . TBL_ROLES . '
251239
WHERE cat_id = rol_cat_id
252-
AND ( cat_org_id = '. $gCurrentOrgId . '
240+
AND ( cat_org_id = ' . $gCurrentOrgId . '
253241
OR cat_org_id IS NULL )';
254-
$formConfigurations->addSelectBoxFromSql('selection_role'.$key, $gL10n->get('SYS_ROLE_SELECTION'), $gDb, $sql,
255-
array('defaultValue' => explode(',', (string) $value['selection_role']),'multiselect' => true, 'helpTextIdLabel' => 'SYS_ROLE_SELECTION_CONF_DESC'));
242+
$formConfigurations->addSelectBoxFromSql('selection_role' . $key, $gL10n->get('SYS_ROLE_SELECTION'), $gDb, $sql,
243+
array('defaultValue' => explode(',', (string)$value['selection_role']), 'multiselect' => true, 'helpTextIdLabel' => 'SYS_ROLE_SELECTION_CONF_DESC'));
256244

257245
$sql = 'SELECT cat_id, cat_name
258-
FROM '.TBL_CATEGORIES.' , '.TBL_ROLES.'
246+
FROM ' . TBL_CATEGORIES . ' , ' . TBL_ROLES . '
259247
WHERE cat_id = rol_cat_id
260248
AND ( cat_org_id = ' . $gCurrentOrgId . '
261249
OR cat_org_id IS NULL )';
262-
$formConfigurations->addSelectBoxFromSql('selection_cat'.$key, $gL10n->get('SYS_CAT_SELECTION'), $gDb, $sql,
263-
array('defaultValue' => explode(',', (string) $value['selection_cat']),'multiselect' => true, 'helpTextIdLabel' => 'SYS_CAT_SELECTION_CONF_DESC'));
264-
$formConfigurations->addCheckbox('number_col'.$key, $gL10n->get('SYS_QUANTITY') . ' (' . $gL10n->get('SYS_COLUMN') . ')', $value['number_col'], array('helpTextIdLabel' => 'SYS_NUMBER_COL_DESC'));
265-
$formConfigurations->addInput('id'.$key, '', $value['id'], array('property' => HtmlForm::FIELD_HIDDEN));
266-
$formConfigurations->addInput('default_conf'.$key, '', $value['default_conf'], array('property' => HtmlForm::FIELD_HIDDEN));
267-
$html = '<a id="copy_config" class="icon-text-link" href="'. SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/category-report/preferences.php', array('copy' => $key+1)).'">
268-
<i class="fas fa-clone"></i> '.$gL10n->get('SYS_COPY_CONFIGURATION').'</a>';
269-
if(count($config) > 1 && $value['default_conf'] == false)
270-
{
271-
$html .= '&nbsp;&nbsp;&nbsp;&nbsp;<a id="delete_config" class="icon-text-link" href="'. SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/category-report/preferences.php', array('delete' => $key+1)).'">
272-
<i class="fas fa-trash-alt"></i> '.$gL10n->get('SYS_DELETE_CONFIGURATION').'</a>';
250+
$formConfigurations->addSelectBoxFromSql('selection_cat' . $key, $gL10n->get('SYS_CAT_SELECTION'), $gDb, $sql,
251+
array('defaultValue' => explode(',', (string)$value['selection_cat']), 'multiselect' => true, 'helpTextIdLabel' => 'SYS_CAT_SELECTION_CONF_DESC'));
252+
$formConfigurations->addCheckbox('number_col' . $key, $gL10n->get('SYS_QUANTITY') . ' (' . $gL10n->get('SYS_COLUMN') . ')', $value['number_col'], array('helpTextIdLabel' => 'SYS_NUMBER_COL_DESC'));
253+
$formConfigurations->addInput('id' . $key, '', $value['id'], array('property' => HtmlForm::FIELD_HIDDEN));
254+
$formConfigurations->addInput('default_conf' . $key, '', $value['default_conf'], array('property' => HtmlForm::FIELD_HIDDEN));
255+
$html = '<a id="copy_config" class="icon-text-link" href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/category-report/preferences.php', array('copy' => $key + 1)) . '">
256+
<i class="fas fa-clone"></i> ' . $gL10n->get('SYS_COPY_CONFIGURATION') . '</a>';
257+
if (count($config) > 1 && $value['default_conf'] == false) {
258+
$html .= '&nbsp;&nbsp;&nbsp;&nbsp;<a id="delete_config" class="icon-text-link" href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/category-report/preferences.php', array('delete' => $key + 1)) . '">
259+
<i class="fas fa-trash-alt"></i> ' . $gL10n->get('SYS_DELETE_CONFIGURATION') . '</a>';
273260
}
274-
if(!empty($value['name']))
275-
{
261+
if (!empty($value['name'])) {
276262
$formConfigurations->addCustomContent('', $html);
277263
}
278264
$formConfigurations->closeGroupBox();
279265
}
280266

281267
$formConfigurations->addLine();
282-
$html = '<a id="add_config" class="icon-text-link" href="'. SecurityUtils::encodeUrl(ADMIDIO_URL.FOLDER_MODULES.'/category-report/preferences.php', array('add' => 1)).'">
283-
<i class="fas fa-plus-circle"></i> '.$gL10n->get('SYS_ADD_ANOTHER_CONFIG').'
268+
$html = '<a id="add_config" class="icon-text-link" href="' . SecurityUtils::encodeUrl(ADMIDIO_URL . FOLDER_MODULES . '/category-report/preferences.php', array('add' => 1)) . '">
269+
<i class="fas fa-plus-circle"></i> ' . $gL10n->get('SYS_ADD_ANOTHER_CONFIG') . '
284270
</a>';
285271
$htmlDesc = '<div class="alert alert-warning alert-small" role="alert">
286-
<i class="fas fa-exclamation-triangle"></i>'.$gL10n->get('ORG_NOT_SAVED_SETTINGS_LOST').'
272+
<i class="fas fa-exclamation-triangle"></i>' . $gL10n->get('ORG_NOT_SAVED_SETTINGS_LOST') . '
287273
</div>';
288274
$formConfigurations->addCustomContent('', $html, array('helpTextIdInline' => $htmlDesc));
289275
$formConfigurations->addSubmitButton('btn_save_configurations', $gL10n->get('SYS_SAVE'), array('icon' => 'fa-check', 'class' => ' offset-sm-3'));
290276

291277
$page->addHtml($formConfigurations->show());
292278

293279
$page->show();
294-
295-
/**
296-
* Funktion prüft, ob es eine Konfiguration mit dem übergebenen Namen bereits gibt
297-
* wenn ja: wird "- Kopie" angehängt und rekursiv überprüft
298-
* @param string $name
299-
* @return string
300-
*/
301-
function createName($name)
302-
{
303-
global $gDb, $gL10n, $gCurrentOrgId;
304-
305-
$sql = ' SELECT crt_name
306-
FROM '. TBL_CATEGORY_REPORT .'
307-
WHERE ( crt_org_id = ? -- $gCurrentOrgId
308-
OR crt_org_id IS NULL ) ';
309-
$statement = $gDb->queryPrepared($sql, array($gCurrentOrgId));
310-
311-
$crtNames = array();
312-
while($row = $statement->fetch())
313-
{
314-
$crtNames[] = $row['crt_name'];
315-
}
316-
317-
while (in_array($name, $crtNames))
318-
{
319-
$name .= ' - '.$gL10n->get('SYS_CARBON_COPY');
320-
}
321-
322-
return $name;
323-
}

0 commit comments

Comments
 (0)