|
17 | 17 |
|
18 | 18 | use phpMyFAQ\Category; |
19 | 19 | use phpMyFAQ\Category\CategoryPermission; |
| 20 | +use phpMyFAQ\Configuration; |
20 | 21 | use phpMyFAQ\Enums\PermissionType; |
21 | 22 | use phpMyFAQ\Filter; |
22 | 23 | use phpMyFAQ\Helper\UserHelper; |
23 | 24 | use phpMyFAQ\Session\Token; |
24 | 25 | use phpMyFAQ\Strings; |
| 26 | +use phpMyFAQ\Template\TwigWrapper; |
25 | 27 | use phpMyFAQ\Translation; |
| 28 | +use phpMyFAQ\User\CurrentUser; |
26 | 29 |
|
27 | 30 | if (!defined('IS_VALID_PHPMYFAQ')) { |
28 | 31 | http_response_code(400); |
29 | 32 | exit(); |
30 | 33 | } |
31 | 34 |
|
32 | | -$currentUserId = $user->getUserId(); |
| 35 | +$faqConfig = Configuration::getConfigurationInstance(); |
| 36 | +$currentUser = CurrentUser::getCurrentUser($faqConfig); |
33 | 37 |
|
34 | | -if ($user->perm->hasPermission($user->getUserId(), PermissionType::CATEGORY_EDIT->value)) { |
| 38 | +$currentUserId = $currentUser->getUserId(); |
| 39 | + |
| 40 | +if ($currentUser->perm->hasPermission($currentUser->getUserId(), PermissionType::CATEGORY_EDIT->value)) { |
35 | 41 | $categoryId = Filter::filterInput(INPUT_GET, 'cat', FILTER_VALIDATE_INT, 0); |
36 | 42 |
|
37 | 43 | $category = new Category($faqConfig, [], false); |
|
40 | 46 |
|
41 | 47 | $categoryPermission = new CategoryPermission($faqConfig); |
42 | 48 |
|
43 | | - $userHelper = new UserHelper($user); |
| 49 | + $userHelper = new UserHelper($currentUser); |
44 | 50 |
|
45 | 51 | $categoryData = $category->getCategoryData($categoryId); |
46 | 52 | $userPermission = $categoryPermission->get(CategoryPermission::USER, [$categoryId]); |
|
64 | 70 |
|
65 | 71 | $header = Translation::get('ad_categ_edit_1') . ' "' . Strings::htmlentities($categoryData->getName()) . '" ' . |
66 | 72 | Translation::get('ad_categ_edit_2'); |
67 | | - ?> |
68 | | - <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"> |
69 | | - <h1 class="h2"> |
70 | | - <i aria-hidden="true" class="bi bi-folder"></i> <?= $header ?> |
71 | | - </h1> |
72 | | - </div> |
73 | | - |
74 | | - <div class="row mb-2"> |
75 | | - <div class="col-lg-12"> |
76 | | - <form enctype="multipart/form-data" action="?action=updatecategory" method="post"> |
77 | | - <input type="hidden" name="id" value="<?= $categoryId ?>"> |
78 | | - <input type="hidden" name="catlang" id="catlang" value="<?= $categoryData->getLang() ?>"> |
79 | | - <input type="hidden" name="parent_id" value="<?= $categoryData->getParentId() ?>"> |
80 | | - <?= Token::getInstance()->getTokenInput('update-category') ?> |
81 | | - <input type="hidden" name="existing_image" value="<?= $categoryData->getImage() ?>" |
82 | | - id="pmf-category-existing-image"> |
83 | | - |
84 | | - <div class="row mb-2"> |
85 | | - <label class="col-lg-2 col-form-label" for="name"> |
86 | | - <?= Translation::get('ad_categ_titel') ?> |
87 | | - </label> |
88 | | - <div class="col-lg-4"> |
89 | | - <input type="text" id="name" name="name" value="<?= Strings::htmlentities($categoryData->getName()) ?>" |
90 | | - class="form-control"> |
91 | | - </div> |
92 | | - </div> |
93 | | - |
94 | | - <div class="row mb-2"> |
95 | | - <label class="col-lg-2 col-form-label" for="description"> |
96 | | - <?= Translation::get('ad_categ_desc') ?> |
97 | | - </label> |
98 | | - <div class="col-lg-4"> |
99 | | - <textarea id="description" name="description" rows="3" |
100 | | - class="form-control"><?= Strings::htmlentities($categoryData->getDescription()) ?></textarea> |
101 | | - </div> |
102 | | - </div> |
103 | | - |
104 | | - <div class="row mb-2"> |
105 | | - <div class="offset-lg-2 col-lg-4"> |
106 | | - <div class="form-check"> |
107 | | - <input class="form-check-input" type="checkbox" name="active" id='active' value="1" |
108 | | - <?= (1 === (int)$categoryData->getActive() ? 'checked' : '') ?>> |
109 | | - <label class="form-check-label" for="active"><?= Translation::get('ad_user_active') ?></label> |
110 | | - </div> |
111 | | - </div> |
112 | | - </div> |
113 | | - |
114 | | - <div class="row mb-2"> |
115 | | - <div class="offset-lg-2 col-lg-4"> |
116 | | - <div class="form-check"> |
117 | | - <input class="form-check-input" type="checkbox" name="show_home" id='show_home' value="1" |
118 | | - <?= (1 === (int)$categoryData->getShowHome() ? 'checked' : '') ?>> |
119 | | - <label class="form-check-label" for="show_home"><?= Translation::get('ad_user_show_home') ?></label> |
120 | | - </div> |
121 | | - </div> |
122 | | - </div> |
123 | | - |
124 | | - |
125 | | - <div class="row mb-2"> |
126 | | - <label class="col-lg-2 col-form-label" for="pmf-category-image-upload"> |
127 | | - <?= Translation::get('ad_category_image') ?>: |
128 | | - </label> |
129 | | - <div class="col-lg-4"> |
130 | | - <div class="input-group"> |
131 | | - <input class="form-control" type="file" name="image" id="pmf-category-image-upload" |
132 | | - value="<?= $categoryData->getImage() ?>"> |
133 | | - <span class="input-group-text" id="pmf-category-image-label"><?= $categoryData->getImage() ?></span> |
134 | | - </div> |
135 | | - <div class="input-group mt-2"> |
136 | | - <button type="button" class="btn btn-info" id="button-reset-category-image"> |
137 | | - Reset category image |
138 | | - </button> |
139 | | - </div> |
140 | | - </div> |
141 | | - </div> |
142 | | - |
143 | | - <div class="row mb-2"> |
144 | | - <label class="col-lg-2 col-form-label" for="user_id"> |
145 | | - <?= Translation::get('ad_categ_owner') ?> |
146 | | - </label> |
147 | | - <div class="col-lg-4"> |
148 | | - <select id="user_id" name="user_id" class="form-select"> |
149 | | - <?= $userHelper->getAllUserOptions($categoryData->getUserId()) ?> |
150 | | - </select> |
151 | | - </div> |
152 | | - </div> |
153 | | - |
154 | | - <?php if ($faqConfig->get('security.permLevel') != 'basic') { ?> |
155 | | - <div class="row mb-2"> |
156 | | - <label class="col-lg-2 col-form-label" for="group_id"><?= Translation::get('ad_categ_moderator') ?>:</label> |
157 | | - <div class="col-lg-4"> |
158 | | - <select name="group_id" id="group_id" class="form-select"> |
159 | | - <?= $user->perm->getAllGroupsOptions([$categoryData->getGroupId()], $user) ?> |
160 | | - </select> |
161 | | - </div> |
162 | | - </div> |
163 | | - |
164 | | - <div class="row mb-2"> |
165 | | - <label class="col-lg-2 col-form-label" for="restricted_groups"> |
166 | | - <?= Translation::get('ad_entry_grouppermission') ?> |
167 | | - </label> |
168 | | - <div class="col-lg-4"> |
169 | | - <div class="form-check"> |
170 | | - <input type="radio" name="grouppermission" id="grouppermission_all" value="all" |
171 | | - class="form-check-input" <?php echo($allGroups ? 'checked' : '') ?>> |
172 | | - <label class="form-check-label" for="grouppermission_all"> |
173 | | - <?= Translation::get('ad_entry_all_groups') ?> |
174 | | - </label> |
175 | | - </div> |
176 | | - <div class="form-check"> |
177 | | - <input type="radio" name="grouppermission" id="grouppermission" value="restricted" |
178 | | - class="form-check-input" <?php echo($restrictedGroups ? 'checked' : '') ?>> |
179 | | - <label class="form-check-label" for="grouppermission"> |
180 | | - <?= Translation::get('ad_entry_restricted_groups') ?> |
181 | | - </label> |
182 | | - </div> |
183 | | - <select name="restricted_groups[]" id="restricted_groups" size="3" class="form-select" |
184 | | - multiple> |
185 | | - <?= $user->perm->getAllGroupsOptions($groupPermission, $user) ?> |
186 | | - </select> |
187 | | - </div> |
188 | | - </div> |
189 | | - |
190 | | - <?php } else { ?> |
191 | | - <input type="hidden" name="grouppermission" value="all"> |
192 | | - <?php } ?> |
193 | | - <div class="row mb-2"> |
194 | | - <label class="col-lg-2 col-form-label" for="restricted_users"> |
195 | | - <?= Translation::get('ad_entry_userpermission') ?> |
196 | | - </label> |
197 | | - <div class="col-lg-4"> |
198 | | - <div class="form-check"> |
199 | | - <input type="radio" name="userpermission" id="userpermission_all" value="all" |
200 | | - class="form-check-input" <?= ($allUsers ? 'checked' : '') ?>> |
201 | | - <label class="form-check-label" for="userpermission_all"> |
202 | | - <?= Translation::get('ad_entry_all_users') ?> |
203 | | - </label> |
204 | | - </div> |
205 | | - <div class="form-check"> |
206 | | - <input type="radio" name="userpermission" id="userpermission" value="restricted" class="form-check-input"> |
207 | | - <label class="form-check-label" for="userpermission"<?= ($restrictedUsers ? 'checked' : '') ?>> |
208 | | - <?= Translation::get('ad_entry_restricted_users') ?> |
209 | | - </label> |
210 | | - </div> |
211 | | - <select name="restricted_users" id="restricted_users" class="form-select"> |
212 | | - <?= $userHelper->getAllUserOptions($categoryData->getUserId()) ?> |
213 | | - </select> |
214 | | - </div> |
215 | | - </div> |
216 | | - |
217 | | - <div class="row mb-2"> |
218 | | - <div class="offset-lg-2 col-lg-4 text-end"> |
219 | | - <button class="btn btn-primary" type="submit" name="submit"> |
220 | | - <?= Translation::get('ad_categ_updatecateg') ?> |
221 | | - </button> |
222 | | - </div> |
223 | | - </div> |
224 | | - </form> |
225 | | - </div> |
226 | | - </div> |
227 | | - <?php |
| 73 | + |
| 74 | + $templateVars = [ |
| 75 | + 'header' => $header, |
| 76 | + 'categoryId' => $categoryId, |
| 77 | + 'categoryLanguage' => $categoryData->getLang(), |
| 78 | + 'parentId' => $categoryData->getParentId(), |
| 79 | + 'csrfInputToken' => Token::getInstance()->getTokenInput('update-category'), |
| 80 | + 'categoryImage' => $categoryData->getImage(), |
| 81 | + 'categoryNameLabel' => Translation::get('ad_categ_titel'), |
| 82 | + 'categoryName' => $categoryData->getName(), |
| 83 | + 'categoryDescriptionLabel' => Translation::get('ad_categ_desc'), |
| 84 | + 'categoryDescription' => $categoryData->getDescription(), |
| 85 | + 'categoryActiveLabel' => Translation::get('ad_user_active'), |
| 86 | + 'categoryActive' => 1 === (int)$categoryData->getActive() ? 'checked' : '', |
| 87 | + 'categoryShowHomeLabel' => Translation::get('ad_user_show_home'), |
| 88 | + 'categoryShowHome' => 1 === (int)$categoryData->getShowHome() ? 'checked' : '', |
| 89 | + 'categoryImageLabel' => Translation::get('ad_category_image'), |
| 90 | + 'categoryImageReset' => 'Reset category image', |
| 91 | + 'categoryOwnerLabel' => Translation::get('ad_categ_owner'), |
| 92 | + 'categoryOwnerOptions' => $userHelper->getAllUserOptions($categoryData->getUserId()), |
| 93 | + 'isMediumPermission' => $faqConfig->get('security.permLevel') !== 'basic', |
| 94 | + 'categoryModeratorLabel' => Translation::get('ad_categ_moderator'), |
| 95 | + 'allGroupsOptions' => $currentUser->perm->getAllGroupsOptions([$categoryData->getGroupId()], $currentUser), |
| 96 | + 'categoryGroupPermissionLabel' => Translation::get('ad_entry_grouppermission'), |
| 97 | + 'allGroups' => $allGroups ? 'checked' : '', |
| 98 | + 'categoryGroupPermissionAllLabel' => Translation::get('ad_entry_all_groups'), |
| 99 | + 'restrictedGroups' => $restrictedGroups ? 'checked' : '', |
| 100 | + 'restrictedGroupsLabel' => Translation::get('ad_entry_restricted_groups'), |
| 101 | + 'restrictedGroupsOptions' => $currentUser->perm->getAllGroupsOptions($groupPermission, $currentUser), |
| 102 | + 'userPermissionLabel' => Translation::get('ad_entry_userpermission'), |
| 103 | + 'allUsers' => $allUsers ? 'checked' : '', |
| 104 | + 'allUsersLabel' => Translation::get('ad_entry_all_users'), |
| 105 | + 'restrictedUsers' => $restrictedUsers ? 'checked' : '', |
| 106 | + 'restrictedUsersLabel' => Translation::get('ad_entry_restricted_users'), |
| 107 | + 'allUsersOptions' => $userHelper->getAllUserOptions($categoryData->getUserId()), |
| 108 | + 'buttonUpdate' => Translation::get('ad_categ_update'), |
| 109 | + ]; |
| 110 | + |
| 111 | + |
| 112 | + $twig = new TwigWrapper(PMF_ROOT_DIR . '/assets/templates'); |
| 113 | + $template = $twig->loadTemplate('./admin/content/category.edit.twig'); |
| 114 | + |
| 115 | + echo $template->render($templateVars); |
228 | 116 | } else { |
229 | 117 | require 'no-permission.php'; |
230 | 118 | } |
0 commit comments