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
city.php
356 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 city controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerCity 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.city.data', array()); |
| 35 | |
| 36 | // check user permissions |
| 37 | if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.countries', '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_state = $app->input->get('id_state', 0, 'uint'); |
| 47 | |
| 48 | $url = 'index.php?option=com_vikappointments&view=managecity&id_state=' . $id_state; |
| 49 | |
| 50 | if ($tmpl = $app->input->get('tmpl')) |
| 51 | { |
| 52 | // propagate specified tmpl |
| 53 | $url .= '&tmpl=' . $tmpl; |
| 54 | } |
| 55 | |
| 56 | $this->setRedirect($url); |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Task used to access the management page of an existing record. |
| 63 | * |
| 64 | * @return boolean |
| 65 | */ |
| 66 | public function edit() |
| 67 | { |
| 68 | $app = JFactory::getApplication(); |
| 69 | $user = JFactory::getUser(); |
| 70 | |
| 71 | // unset user state for being recovered again |
| 72 | $app->setUserState('vap.city.data', array()); |
| 73 | |
| 74 | // check user permissions |
| 75 | if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.countries', 'com_vikappointments')) |
| 76 | { |
| 77 | // back to main list, not authorised to edit records |
| 78 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 79 | $this->cancel(); |
| 80 | |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | $cid = $app->input->getUint('cid', array(0)); |
| 85 | |
| 86 | $url = 'index.php?option=com_vikappointments&view=managecity&cid[]=' . $cid[0]; |
| 87 | |
| 88 | if ($tmpl = $app->input->get('tmpl')) |
| 89 | { |
| 90 | // propagate specified tmpl |
| 91 | $url .= '&tmpl=' . $tmpl; |
| 92 | } |
| 93 | |
| 94 | $this->setRedirect($url); |
| 95 | |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Task used to save the record data set in the request. |
| 101 | * After saving, the user is redirected to the main list. |
| 102 | * |
| 103 | * @return void |
| 104 | */ |
| 105 | public function saveclose() |
| 106 | { |
| 107 | if ($this->save()) |
| 108 | { |
| 109 | $this->cancel(); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Task used to save the record data set in the request. |
| 115 | * After saving, the user is redirected to the creation |
| 116 | * page of a new record. |
| 117 | * |
| 118 | * @return void |
| 119 | */ |
| 120 | public function savenew() |
| 121 | { |
| 122 | if ($this->save()) |
| 123 | { |
| 124 | $app = JFactory::getApplication(); |
| 125 | |
| 126 | $id_state = $app->input->get('id_state', 0, 'uint'); |
| 127 | |
| 128 | $this->setRedirect('index.php?option=com_vikappointments&task=state.add&id_state=' . $id_state); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Task used to save the record data set in the request. |
| 134 | * After saving, the user is redirected to the management |
| 135 | * page of the record that has been saved. |
| 136 | * |
| 137 | * @param boolean $copy True to save the record as a copy. |
| 138 | * |
| 139 | * @return boolean |
| 140 | */ |
| 141 | public function save($copy = false) |
| 142 | { |
| 143 | $app = JFactory::getApplication(); |
| 144 | $input = $app->input; |
| 145 | $user = JFactory::getUser(); |
| 146 | |
| 147 | /** |
| 148 | * Added token validation. |
| 149 | * |
| 150 | * @since 1.7 |
| 151 | */ |
| 152 | if (!JSession::checkToken()) |
| 153 | { |
| 154 | // back to main list, missing CSRF-proof token |
| 155 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 156 | $this->cancel(); |
| 157 | |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | $args = array(); |
| 162 | $args['city_name'] = $input->getString('city_name'); |
| 163 | $args['city_2_code'] = $input->getString('city_2_code'); |
| 164 | $args['city_3_code'] = $input->getString('city_3_code'); |
| 165 | $args['latitude'] = $input->getString('latitude'); |
| 166 | $args['longitude'] = $input->getString('longitude'); |
| 167 | $args['published'] = $input->getUint('published', 0); |
| 168 | $args['id_state'] = $input->getUint('id_state', 0); |
| 169 | $args['id'] = $input->getUint('id', 0); |
| 170 | |
| 171 | $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create'); |
| 172 | |
| 173 | // check user permissions |
| 174 | if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.countries', 'com_vikappointments')) |
| 175 | { |
| 176 | // back to main list, not authorised to create/edit records |
| 177 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 178 | $this->cancel(); |
| 179 | |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | $tmpl = $input->get('tmpl'); |
| 184 | |
| 185 | // get city model |
| 186 | $city = $this->getModel(); |
| 187 | |
| 188 | // try to save arguments |
| 189 | $id = $city->save($args); |
| 190 | |
| 191 | if (!$id) |
| 192 | { |
| 193 | // get string error |
| 194 | $error = $city->getError(null, true); |
| 195 | |
| 196 | // display error message |
| 197 | $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error'); |
| 198 | |
| 199 | $url = 'index.php?option=com_vikappointments&view=managecity'; |
| 200 | |
| 201 | if ($args['id']) |
| 202 | { |
| 203 | $url .= '&cid[]=' . $args['id']; |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | $url .= '&id_state=' . $args['id_state']; |
| 208 | } |
| 209 | |
| 210 | if ($tmpl) |
| 211 | { |
| 212 | // propagate specified tmpl |
| 213 | $url .= '&tmpl=' . $tmpl; |
| 214 | } |
| 215 | |
| 216 | // redirect to new/edit page |
| 217 | $this->setRedirect($url); |
| 218 | |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | $url = 'index.php?option=com_vikappointments&task=city.edit&cid[]=' . $id; |
| 223 | |
| 224 | if ($tmpl) |
| 225 | { |
| 226 | // propagate specified tmpl |
| 227 | $url .= '&tmpl=' . $tmpl; |
| 228 | } |
| 229 | |
| 230 | // display generic successful message |
| 231 | $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 232 | |
| 233 | // redirect to edit page |
| 234 | $this->setRedirect($url); |
| 235 | |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Deletes a list of records set in the request. |
| 241 | * |
| 242 | * @return boolean |
| 243 | */ |
| 244 | public function delete() |
| 245 | { |
| 246 | $app = JFactory::getApplication(); |
| 247 | $user = JFactory::getUser(); |
| 248 | |
| 249 | /** |
| 250 | * Added token validation. |
| 251 | * Both GET and POST are supported. |
| 252 | * |
| 253 | * @since 1.7 |
| 254 | */ |
| 255 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 256 | { |
| 257 | // back to main list, missing CSRF-proof token |
| 258 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 259 | $this->cancel(); |
| 260 | |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | $cid = $app->input->get('cid', array(), 'uint'); |
| 265 | |
| 266 | // check user permissions |
| 267 | if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.countries', 'com_vikappointments')) |
| 268 | { |
| 269 | // back to main list, not authorised to delete records |
| 270 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 271 | $this->cancel(); |
| 272 | |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | // delete selected records |
| 277 | $this->getModel()->delete($cid); |
| 278 | |
| 279 | // back to main list |
| 280 | $this->cancel(); |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * Publishes the selected records. |
| 287 | * |
| 288 | * @return boolean |
| 289 | */ |
| 290 | public function publish() |
| 291 | { |
| 292 | $app = JFactory::getApplication(); |
| 293 | $user = JFactory::getUser(); |
| 294 | |
| 295 | /** |
| 296 | * Added token validation. |
| 297 | * Both GET and POST are supported. |
| 298 | * |
| 299 | * @since 1.7 |
| 300 | */ |
| 301 | if (!JSession::checkToken() && !JSession::checkToken('get')) |
| 302 | { |
| 303 | // back to main list, missing CSRF-proof token |
| 304 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 305 | $this->cancel(); |
| 306 | |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | $cid = $app->input->get('cid', array(), 'uint'); |
| 311 | $task = $app->input->get('task', null); |
| 312 | |
| 313 | $state = $task == 'unpublish' ? 0 : 1; |
| 314 | |
| 315 | // check user permissions |
| 316 | if (!$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.countries', 'com_vikappointments')) |
| 317 | { |
| 318 | // back to main list, not authorised to edit records |
| 319 | $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error'); |
| 320 | $this->cancel(); |
| 321 | |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | // change state of selected records |
| 326 | $this->getModel()->publish($cid, $state); |
| 327 | |
| 328 | // back to main list |
| 329 | $this->cancel(); |
| 330 | |
| 331 | return true; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Redirects the users to the main records list. |
| 336 | * |
| 337 | * @return void |
| 338 | */ |
| 339 | public function cancel() |
| 340 | { |
| 341 | $input = JFactory::getApplication()->input; |
| 342 | |
| 343 | $id_state = $input->get('id_state', 0, 'uint'); |
| 344 | |
| 345 | $url = 'index.php?option=com_vikappointments&view=cities&id_state=' . $id_state; |
| 346 | |
| 347 | if ($tmpl = $input->get('tmpl')) |
| 348 | { |
| 349 | // propagate specified tmpl |
| 350 | $url .= '&tmpl=' . $tmpl; |
| 351 | } |
| 352 | |
| 353 | $this->setRedirect($url); |
| 354 | } |
| 355 | } |
| 356 |