|
36 | 36 | if (isset($_POST['savedsearches_id']) && $_POST['savedsearches_id']) { |
37 | 37 | $savedSearchId = $_POST['savedsearches_id']; |
38 | 38 | } |
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 | + ]; |
48 | 49 |
|
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 | + } |
90 | 91 |
|
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 | + } |
101 | 102 |
|
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); |
106 | 107 |
|
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 " |
116 | 117 | <tr class='tab_bg_1 text-center'> |
117 | 118 | <td> |
118 | 119 | <label>{$field['name']}</label> |
|
129 | 130 | </td> |
130 | 131 | </tr> |
131 | 132 | "; |
| 133 | + } |
132 | 134 | } |
133 | 135 | } |
134 | 136 | } |
135 | 137 | } |
136 | 138 | } |
| 139 | + echo "</tbody></table>"; |
137 | 140 | } |
138 | | - echo "</tbody></table>"; |
139 | 141 | } else { |
140 | 142 | Html::displayRightError(); |
141 | 143 | } |
|
0 commit comments