Skip to content

Commit 307fb81

Browse files
fix last errors
1 parent 815bf79 commit 307fb81

File tree

2 files changed

+83
-80
lines changed

2 files changed

+83
-80
lines changed

ajax/customsearchcriterias.php

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -36,83 +36,84 @@
3636
if (isset($_POST['savedsearches_id']) && $_POST['savedsearches_id']) {
3737
$savedSearchId = $_POST['savedsearches_id'];
3838
}
39-
if ($savedSearchId && Session::haveRight("plugin_autoexportsearches_exportconfigs", READ)) {
40-
$translations = [
41-
'equals' => __('is'),
42-
'notequals' => __('is not'),
43-
'lessthan' => __('before'),
44-
'morethan' => __('after'),
45-
'contains' => __('contains'),
46-
'notcontains' => __('not contains')
47-
];
39+
if (Session::haveRight("plugin_autoexportsearches_exportconfigs", READ)) {
40+
if ($savedSearchId) {
41+
$translations = [
42+
'equals' => __('is'),
43+
'notequals' => __('is not'),
44+
'lessthan' => __('before'),
45+
'morethan' => __('after'),
46+
'contains' => __('contains'),
47+
'notcontains' => __('not contains')
48+
];
4849

49-
echo "<table style='width:100%'><tbody style='width:100%'>";
50-
$search = new SavedSearch();
51-
if ($search->getFromDB($savedSearchId)) {
52-
$url = "?" . $search->fields["query"];
53-
$url_components = parse_url($url);
54-
parse_str($url_components['query'], $p);
55-
if (isset($p['itemtype'])) {
56-
$item = getItemForItemtype($p['itemtype']);
57-
if ($item instanceof CommonITILObject) {
58-
$fields = $item->getSearchOptionsMain();
59-
$dateFields = array_filter($fields, function ($f) {
60-
if (array_key_exists('datatype', $f)) {
61-
return $f['datatype'] === 'datetime';
62-
}
63-
return false;
64-
});
65-
$dateFieldsIds = array_map(function ($f) {
66-
return $f['id'];
67-
}, $dateFields);
68-
$headerAdded = false;
69-
foreach ($p['criteria'] as $index => $criteria) {
70-
if (in_array($criteria['field'], $dateFieldsIds)) {
71-
$value = $criteria['value'];
72-
if (str_starts_with($value, '-')
73-
&& (str_contains($value, 'MONTH') || str_contains($value, 'WEEK'))) {
74-
if (!$headerAdded) {
75-
echo "<tr class='tab_bg_1'>";
76-
echo "<td colspan='3'><h4>" . __(
77-
'Customise the export of',
78-
'autoexportsearches'
79-
) . __(
80-
$p['itemtype']
81-
) . "</h4></td>";
82-
echo "</tr>";
83-
echo "<tr class='tab_bg_1 text-center'>";
84-
echo "<td><h5>" . __('Criterion') . "</h5></td>";
85-
echo "<td><h5>" . __('Value', 'autoexportsearches') . "</h5></td>";
86-
echo "<td><h5>" . __('Customise', 'autoexportsearches') . "</h5></td>";
87-
echo "</tr>";
88-
$headerAdded = true;
89-
}
50+
echo "<table style='width:100%'><tbody style='width:100%'>";
51+
$search = new SavedSearch();
52+
if ($search->getFromDB($savedSearchId)) {
53+
$url = "?" . $search->fields["query"];
54+
$url_components = parse_url($url);
55+
parse_str($url_components['query'], $p);
56+
if (isset($p['itemtype'])) {
57+
$item = getItemForItemtype($p['itemtype']);
58+
if ($item instanceof CommonITILObject) {
59+
$fields = $item->getSearchOptionsMain();
60+
$dateFields = array_filter($fields, function ($f) {
61+
if (array_key_exists('datatype', $f)) {
62+
return $f['datatype'] === 'datetime';
63+
}
64+
return false;
65+
});
66+
$dateFieldsIds = array_map(function ($f) {
67+
return $f['id'];
68+
}, $dateFields);
69+
$headerAdded = false;
70+
foreach ($p['criteria'] as $index => $criteria) {
71+
if (in_array($criteria['field'], $dateFieldsIds)) {
72+
$value = $criteria['value'];
73+
if (str_starts_with($value, '-')
74+
&& (str_contains($value, 'MONTH') || str_contains($value, 'WEEK'))) {
75+
if (!$headerAdded) {
76+
echo "<tr class='tab_bg_1'>";
77+
echo "<td colspan='3'><h4>" . __(
78+
'Customise the export of',
79+
'autoexportsearches'
80+
) . __(
81+
$p['itemtype']
82+
) . "</h4></td>";
83+
echo "</tr>";
84+
echo "<tr class='tab_bg_1 text-center'>";
85+
echo "<td><h5>" . __('Criterion') . "</h5></td>";
86+
echo "<td><h5>" . __('Value', 'autoexportsearches') . "</h5></td>";
87+
echo "<td><h5>" . __('Customise', 'autoexportsearches') . "</h5></td>";
88+
echo "</tr>";
89+
$headerAdded = true;
90+
}
9091

91-
$customValue = null;
92-
$customCriteria = new PluginAutoexportsearchesCustomsearchcriteria();
93-
if ($customCriteria->getFromDBByCrit([
94-
'savedsearches_id' => $savedSearchId,
95-
'exportconfigs_id' => $_POST['exportconfigs_id'],
96-
'criteria_field' => $criteria['field'],
97-
'criteria_searchtype' => $criteria['searchtype']
98-
])) {
99-
$customValue = $customCriteria->fields['criteria_value'];
100-
}
92+
$customValue = null;
93+
$customCriteria = new PluginAutoexportsearchesCustomsearchcriteria();
94+
if ($customCriteria->getFromDBByCrit([
95+
'savedsearches_id' => $savedSearchId,
96+
'exportconfigs_id' => $_POST['exportconfigs_id'],
97+
'criteria_field' => $criteria['field'],
98+
'criteria_searchtype' => $criteria['searchtype']
99+
])) {
100+
$customValue = $customCriteria->fields['criteria_value'];
101+
}
101102

102-
$field = array_filter($dateFields, function ($f) use ($criteria) {
103-
return $f['id'] == $criteria['field'];
104-
});
105-
$field = reset($field);
103+
$field = array_filter($dateFields, function ($f) use ($criteria) {
104+
return $f['id'] == $criteria['field'];
105+
});
106+
$field = reset($field);
106107

107-
$timeValue = str_contains($value, 'MONTH') ? 'month' : 'week';
108-
$searchValue = $translations[$criteria['searchtype']] . ' : -' . sprintf(
109-
_n("%d $timeValue", "%d $timeValue" . 's', $value[1]),
110-
$value[1]
111-
);
112-
$label = $timeValue === 'month' ? __('Beginning of the month') : __('Monday');
113-
$inputValue = $timeValue === 'month' ? PluginAutoexportsearchesCustomsearchcriteria::CRITERIA_FIRST_DAY_OF_MONTH : PluginAutoexportsearchesCustomsearchcriteria::CRITERIA_FIRST_DAY_OF_WEEK;
114-
$checked = $customValue === $inputValue ? 'checked' : '';
115-
echo "
108+
$timeValue = str_contains($value, 'MONTH') ? 'month' : 'week';
109+
$searchValue = $translations[$criteria['searchtype']] . ' : -' . sprintf(
110+
_n("%d $timeValue", "%d $timeValue" . 's', $value[1]),
111+
$value[1]
112+
);
113+
$label = $timeValue === 'month' ? __('Beginning of the month') : __('Monday');
114+
$inputValue = $timeValue === 'month' ? PluginAutoexportsearchesCustomsearchcriteria::CRITERIA_FIRST_DAY_OF_MONTH : PluginAutoexportsearchesCustomsearchcriteria::CRITERIA_FIRST_DAY_OF_WEEK;
115+
$checked = $customValue === $inputValue ? 'checked' : '';
116+
echo "
116117
<tr class='tab_bg_1 text-center'>
117118
<td>
118119
<label>{$field['name']}</label>
@@ -129,13 +130,14 @@
129130
</td>
130131
</tr>
131132
";
133+
}
132134
}
133135
}
134136
}
135137
}
136138
}
139+
echo "</tbody></table>";
137140
}
138-
echo "</tbody></table>";
139141
} else {
140142
Html::displayRightError();
141143
}

ajax/periodicityfields.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
if (isset($_POST['id']) && $_POST['id']) {
3737
$id = $_POST['id'];
3838
}
39-
$exportConfig = null;
40-
if ($id > 0) {
41-
$exportConfig = new PluginAutoexportsearchesExportconfig();
42-
$exportConfig->getFromDB($id);
43-
}
44-
if ($exportConfig->canView() && $exportConfig->canUpdate()) {
39+
if (Session::haveRight("plugin_autoexportsearches_exportconfigs", READ)
40+
&& Session::haveRight("plugin_autoexportsearches_exportconfigs", UPDATE)) {
41+
$exportConfig = null;
42+
if ($id > 0) {
43+
$exportConfig = new PluginAutoexportsearchesExportconfig();
44+
$exportConfig->getFromDB($id);
45+
}
4546
switch ($_POST['periodicity_type']) {
4647
case PluginAutoexportsearchesExportconfig::PERIODICITY_DAYS:
4748
echo "<td>" . __('Periodicity (in days)', 'autoexportsearches') . "</td>";

0 commit comments

Comments
 (0)