analytics.php
4 years ago
apiban.php
4 years ago
apilog.php
4 years ago
apiplugin.php
4 years ago
apiuser.php
4 years ago
backup.php
4 years ago
calendar.php
4 years ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
2 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
1 month ago
conversion.php
1 year ago
country.php
4 years ago
coupon.php
4 years ago
coupongroup.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
4 months ago
customf.php
1 year ago
dashboard.php
4 years ago
emplocwdays.php
4 years ago
employee.php
1 year ago
emprates.php
4 years ago
export.php
4 years ago
exportres.php
4 years ago
file.php
4 months ago
findreservation.php
1 month ago
group.php
4 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
4 years ago
langoptiongroup.php
4 years ago
langpackage.php
4 years ago
langpackgroup.php
4 years ago
langpayment.php
4 years ago
langservice.php
4 years ago
langstatuscode.php
4 years ago
langsubscr.php
4 years ago
langtax.php
4 years ago
location.php
4 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
4 years ago
multiorder.php
4 years ago
option.php
4 months ago
optiongroup.php
4 years ago
package.php
2 years ago
packgroup.php
4 years ago
packorder.php
1 year ago
payment.php
4 years ago
rate.php
4 years ago
reportsemp.php
4 years ago
reportsser.php
4 years ago
reservation.php
1 month ago
restriction.php
4 years ago
review.php
4 years ago
service.php
1 year ago
serworkday.php
4 months ago
state.php
4 years ago
statuscode.php
4 years ago
subscription.php
4 years ago
subscrorder.php
4 years ago
tag.php
4 years ago
tax.php
4 years ago
usernote.php
4 years ago
waitinglist.php
4 years ago
webhook.php
4 years ago
wizard.php
1 year ago
langgroup.php
329 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | VAPLoader::import('libraries.mvc.controllers.admin'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments group language controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerLanggroup extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * Task used to access the creation page of a new record. |
| 25 | * |
| 26 | * @return boolean |
| 27 | */ |
| 28 | public function add() |
| 29 | { |
| 30 | $app = JFactory::getApplication(); |
| 31 | $user = JFactory::getUser(); |
| 32 | |
| 33 | // unset user state for being recovered again |
| 34 | $app->setUserState('vap.langgroup.data', array()); |
| 35 | |
| 36 | // check user permissions |
| 37 | if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments')) |
| 38 | { |
| 39 | // back to main list, not authorised to create records |
| 40 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 41 | $this->cancel(); |
| 42 | |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | $id_group = $app->input->getUint('id_group'); |
| 47 | |
| 48 | // extract page type from request: |
| 49 | // - 1 for services (default) |
| 50 | // - 2 for employees |
| 51 | $type = $app->input->get('type', 1, 'uint'); |
| 52 | |
| 53 | $this->setRedirect('index.php?option=com_vikappointments&view=managelanggroup&id_group=' . $id_group . '&type=' . $type); |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Task used to access the management page of an existing record. |
| 60 | * |
| 61 | * @return boolean |
| 62 | */ |
| 63 | public function edit() |
| 64 | { |
| 65 | $app = JFactory::getApplication(); |
| 66 | $user = JFactory::getUser(); |
| 67 | |
| 68 | // unset user state for being recovered again |
| 69 | $app->setUserState('vap.langgroup.data', array()); |
| 70 | |
| 71 | // check user permissions |
| 72 | if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments')) |
| 73 | { |
| 74 | // back to main list, not authorised to edit records |
| 75 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 76 | $this->cancel(); |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | $cid = $app->input->getUint('cid', array(0)); |
| 82 | |
| 83 | // extract page type from request: |
| 84 | // - 1 for services (default) |
| 85 | // - 2 for employees |
| 86 | $type = $app->input->get('type', 1, 'uint'); |
| 87 | |
| 88 | $this->setRedirect('index.php?option=com_vikappointments&view=managelanggroup&cid[]=' . $cid[0] . '&type=' . $type); |
| 89 | |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Task used to save the record data set in the request. |
| 95 | * After saving, the user is redirected to the main list. |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | public function saveclose() |
| 100 | { |
| 101 | if ($this->save()) |
| 102 | { |
| 103 | $this->cancel(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Task used to save the record data set in the request. |
| 109 | * After saving, the user is redirected to the creation |
| 110 | * page of a new record. |
| 111 | * |
| 112 | * @return void |
| 113 | */ |
| 114 | public function savenew() |
| 115 | { |
| 116 | if ($this->save()) |
| 117 | { |
| 118 | $input = JFactory::getApplication()->input; |
| 119 | |
| 120 | // recover group ID from request |
| 121 | $id_group = $input->getUint('id_group'); |
| 122 | |
| 123 | // extract page type from request: |
| 124 | // - 1 for services (default) |
| 125 | // - 2 for employees |
| 126 | $type = $input->get('type', 1, 'uint'); |
| 127 | |
| 128 | $url = 'index.php?option=com_vikappointments&task=langgroup.add&type=' . $type; |
| 129 | |
| 130 | if ($id_group) |
| 131 | { |
| 132 | $url .= '&id_group=' . $id_group; |
| 133 | } |
| 134 | |
| 135 | $this->setRedirect($url); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Task used to save the record data set in the request. |
| 141 | * After saving, the user is redirected to the management |
| 142 | * page of the record that has been saved. |
| 143 | * |
| 144 | * @return boolean |
| 145 | */ |
| 146 | public function save() |
| 147 | { |
| 148 | $app = JFactory::getApplication(); |
| 149 | $input = $app->input; |
| 150 | $user = JFactory::getUser(); |
| 151 | |
| 152 | /** |
| 153 | * Added token validation. |
| 154 | * |
| 155 | * @since 1.7 |
| 156 | */ |
| 157 | if (!JSession::checkToken()) |
| 158 | { |
| 159 | // back to main list, missing CSRF-proof token |
| 160 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 161 | $this->cancel(); |
| 162 | |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | $args = array(); |
| 167 | $args['name'] = $input->get('name', '', 'string'); |
| 168 | $args['description'] = JComponentHelper::filterText($input->get('description', '', 'raw')); |
| 169 | $args['id'] = $input->get('id', 0, 'uint'); |
| 170 | $args['id_group'] = $input->get('id_group', 0, 'uint'); |
| 171 | $args['tag'] = $input->get('tag', '', 'string'); |
| 172 | |
| 173 | $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create'); |
| 174 | |
| 175 | // check user permissions |
| 176 | if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments')) |
| 177 | { |
| 178 | // back to main list, not authorised to create/edit records |
| 179 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 180 | $this->cancel(); |
| 181 | |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | // extract page type from request: |
| 186 | // - 1 for services (default) |
| 187 | // - 2 for employees |
| 188 | $pagetype = $input->get('type', 1, 'uint'); |
| 189 | |
| 190 | // get db model |
| 191 | $langgroup = $this->getGroupModel($pagetype); |
| 192 | |
| 193 | // try to save arguments |
| 194 | $id = $langgroup->save($args); |
| 195 | |
| 196 | if (!$id) |
| 197 | { |
| 198 | // get string error |
| 199 | $error = $langgroup->getError(null, true); |
| 200 | |
| 201 | // display error message |
| 202 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 203 | |
| 204 | $url = 'index.php?option=com_vikappointments&view=managelanggroup&type=' . $pagetype; |
| 205 | |
| 206 | if ($args['id']) |
| 207 | { |
| 208 | $url .= '&cid[]=' . $args['id']; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | $url .= '&id_group=' . $args['id_group']; |
| 213 | } |
| 214 | |
| 215 | // redirect to new/edit page |
| 216 | $this->setRedirect($url); |
| 217 | |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | // display generic successful message |
| 222 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 223 | |
| 224 | // redirect to edit page |
| 225 | $this->setRedirect('index.php?option=com_vikappointments&task=langgroup.edit&cid[]=' . $id . '&type=' . $pagetype); |
| 226 | |
| 227 | return true; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Deletes a list of records set in the request. |
| 232 | * |
| 233 | * @return boolean |
| 234 | */ |
| 235 | public function delete() |
| 236 | { |
| 237 | $app = JFactory::getApplication(); |
| 238 | $user = JFactory::getUser(); |
| 239 | |
| 240 | /** |
| 241 | * Added token validation. |
| 242 | * Both GET and POST are supported. |
| 243 | * |
| 244 | * @since 1.7 |
| 245 | */ |
| 246 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 247 | { |
| 248 | // back to main list, missing CSRF-proof token |
| 249 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 250 | $this->cancel(); |
| 251 | |
| 252 | return false; |
| 253 | } |
| 254 | |
| 255 | $cid = $app->input->get('cid', array(), 'uint'); |
| 256 | |
| 257 | // check user permissions |
| 258 | if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.groups', 'com_vikappointments')) |
| 259 | { |
| 260 | // back to main list, not authorised to delete records |
| 261 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 262 | $this->cancel(); |
| 263 | |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | // delete selected records |
| 268 | $this->getGroupModel()->delete($cid); |
| 269 | |
| 270 | // back to main list |
| 271 | $this->cancel(); |
| 272 | |
| 273 | return true; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * Redirects the users to the main records list. |
| 278 | * |
| 279 | * @return void |
| 280 | */ |
| 281 | public function cancel() |
| 282 | { |
| 283 | $input = JFactory::getApplication()->input; |
| 284 | |
| 285 | // recover group ID from request |
| 286 | $id_group = $input->getUint('id_group'); |
| 287 | |
| 288 | // extract page type from request: |
| 289 | // - 1 for services (default) |
| 290 | // - 2 for employees |
| 291 | $type = $input->get('type', 1, 'uint'); |
| 292 | |
| 293 | $url = 'index.php?option=com_vikappointments&view=langgroups&type=' . $type; |
| 294 | |
| 295 | if ($id_group) |
| 296 | { |
| 297 | $url .= '&id_group=' . $id_group; |
| 298 | } |
| 299 | |
| 300 | $this->setRedirect($url); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Creates the correct database model. |
| 305 | * |
| 306 | * @param mixed $type An optional page type. If not specified, |
| 307 | * it will be retrieved from the request. |
| 308 | * |
| 309 | * @return JModel |
| 310 | */ |
| 311 | protected function getGroupModel($type = null) |
| 312 | { |
| 313 | if (!$type) |
| 314 | { |
| 315 | $input = JFactory::getApplication()->input; |
| 316 | |
| 317 | // extract page type from request: |
| 318 | // - 1 for services (default) |
| 319 | // - 2 for employees |
| 320 | $type = $input->get('type', 1, 'uint'); |
| 321 | } |
| 322 | |
| 323 | // use correct model according to the specified page type |
| 324 | $tbl = $type == 1 ? 'langgroup' : 'langempgroup'; |
| 325 | |
| 326 | return $this->getModel($tbl); |
| 327 | } |
| 328 | } |
| 329 |