imagecms /
ImageCMS
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | (defined('BASEPATH')) OR exit('No direct script access allowed'); |
||
| 4 | |||
| 5 | use CMSFactory\assetManager; |
||
| 6 | use Propel\Runtime\ActiveQuery\Criteria; |
||
| 7 | use Propel\Runtime\Exception\PropelException; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Image CMS |
||
| 11 | * Sample Module Admin |
||
| 12 | * @property Cms_admin $cms_admin |
||
| 13 | */ |
||
| 14 | class Admin extends BaseAdminController |
||
| 15 | { |
||
| 16 | |||
| 17 | protected $perPage = 10; |
||
| 18 | |||
| 19 | public function __construct() { |
||
| 20 | parent::__construct(); |
||
| 21 | |||
| 22 | $lang = new MY_Lang(); |
||
| 23 | $lang->load('callbacks'); |
||
| 24 | $this->perPage = $this->input->cookie('per_page') ?: $this->perPage; |
||
| 25 | assetManager::create()->setData(['ADMIN_URL' => site_url('/admin/components/run') . '/']); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Callbacks list |
||
| 30 | */ |
||
| 31 | public function index() { |
||
| 32 | /** Callbacks Pagination */ |
||
| 33 | if ($this->input->get('per_page')) { |
||
| 34 | $callbacksSession = [ |
||
| 35 | 'callback_url' => '?per_page=' . $this->input->get('per_page'), |
||
| 36 | ]; |
||
| 37 | $this->session->set_userdata($callbacksSession); |
||
| 38 | } else { |
||
| 39 | $this->session->unset_userdata('callback_url'); |
||
| 40 | } |
||
| 41 | $offset = $this->input->get('per_page'); |
||
| 42 | $model = SCallbacksQuery::create() |
||
| 43 | ->joinSCallbackStatuses(null, 'left join') |
||
| 44 | ->joinSCallbackThemes(null, 'left join'); |
||
| 45 | |||
| 46 | if ($this->input->get('filterID') > 0) { |
||
| 47 | $model = $model->filterById((int) $this->input->get('filterID')); |
||
| 48 | } |
||
| 49 | |||
| 50 | View Code Duplication | if ($user_name = $this->input->get('user_name')) { |
|
| 51 | $user_name = (false !== strpos($user_name, '%')) ? $user_name : '%' . $user_name . '%'; |
||
| 52 | $model->condition('name', 'SCallbacks.Name LIKE ?', $user_name); |
||
| 53 | $model->where(['name'], Criteria::LOGICAL_OR); |
||
| 54 | } |
||
| 55 | |||
| 56 | View Code Duplication | if ($phone = $this->input->get('phone')) { |
|
| 57 | $phone = (false !== strpos($phone, '%')) ? $phone : '%' . $phone . '%'; |
||
| 58 | $model->condition('phone', 'SCallbacks.Phone LIKE ?', $phone); |
||
| 59 | $model->where(['phone'], Criteria::LOGICAL_OR); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($this->input->get('ThemeId')) { |
||
| 63 | if ($this->input->get('ThemeId') > 0) { |
||
| 64 | $model = $model->filterByThemeId((int) $this->input->get('ThemeId')); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($this->input->get('ThemeId') === 'without') { |
||
| 68 | $model = $model->where('SCallbacks.ThemeId = ?', 0); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($this->input->get('StatusId') > 0) { |
||
| 73 | $model = $model->filterByStatusId((int) $this->input->get('StatusId')); |
||
| 74 | } |
||
| 75 | |||
| 76 | View Code Duplication | if ($this->input->get('created_from')) { |
|
| 77 | $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') >= ?', date('Y-m-d', strtotime($this->input->get('created_from')))); |
||
| 78 | } |
||
| 79 | |||
| 80 | View Code Duplication | if ($this->input->get('created_to')) { |
|
| 81 | $model = $model->where('FROM_UNIXTIME(SCallbacks.Date, \'%Y-%m-%d\') <= ?', date('Y-m-d', strtotime($this->input->get('created_to')))); |
||
| 82 | } |
||
| 83 | |||
| 84 | $model->orderById(Criteria::DESC); |
||
| 85 | |||
| 86 | // Count total orders |
||
| 87 | $totalCallbacks = $model->count(); |
||
| 88 | |||
| 89 | $model = $model |
||
| 90 | ->limit($this->perPage) |
||
| 91 | ->offset((int) $offset) |
||
| 92 | ->find(); |
||
| 93 | |||
| 94 | $callbackStatuses = SCallbackStatusesQuery::create()->setComment(__METHOD__)->joinWithI18n(MY_Controller::defaultLocale(), Criteria::RIGHT_JOIN) |
||
| 95 | ->where('SCallbackStatusesI18n.Locale = "' . MY_Controller::defaultLocale() . '"') |
||
| 96 | ->orderBy('IsDefault', Criteria::DESC) |
||
| 97 | ->orderById() |
||
| 98 | ->find(); |
||
| 99 | $callbackThemes = SCallbackThemesQuery::create()->setComment(__METHOD__)->joinWithI18n(MY_Controller::defaultLocale(), Criteria::JOIN)->orderByPosition()->find(); |
||
| 100 | |||
| 101 | // Create pagination |
||
| 102 | $pagination = $this->initPagination($totalCallbacks); |
||
| 103 | |||
| 104 | assetManager::create() |
||
| 105 | ->setData(compact('model', 'pagination', 'totalCallbacks', 'callbackStatuses', 'callbackThemes')) |
||
| 106 | ->renderAdmin('list'); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Create or update callback |
||
| 111 | * |
||
| 112 | * @param int|null $callbackId |
||
| 113 | * @throws PropelException |
||
| 114 | */ |
||
| 115 | public function update($callbackId = null) { |
||
| 116 | $model = SCallbacksQuery::create()->setComment(__METHOD__)->findPk((int) $callbackId); |
||
| 117 | |||
| 118 | $paginationBrand = $this->session->userdata('callback_url'); |
||
| 119 | $paginationBrand = $paginationBrand ?: null; |
||
| 120 | |||
| 121 | if ($model === null) { |
||
| 122 | $this->error404(lang('Error', 'admin')); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($this->input->post()) { |
||
| 126 | $this->form_validation->set_rules($model->rules()); |
||
| 127 | |||
| 128 | if ($this->form_validation->run($this) == FALSE) { |
||
| 129 | showMessage(validation_errors(), lang('Error'), 'r'); |
||
| 130 | } else { |
||
| 131 | $model->fromArray($this->input->post()); |
||
| 132 | if ($model->getStatusId() !== $this->input->post('StatusId')) { |
||
| 133 | $model->setUserId($this->dx_auth->get_user_id()); |
||
| 134 | } |
||
| 135 | $model->save(); |
||
| 136 | |||
| 137 | $this->lib_admin->log(lang('Callback edited', 'callbacks') . '. Id: ' . $callbackId); |
||
| 138 | showMessage(lang('Changes have been saved', 'callbacks')); |
||
| 139 | |||
| 140 | if ($this->input->post('action') == 'close') { |
||
| 141 | $redirect_url = '/admin/components/run/callbacks'. $paginationBrand; |
||
| 142 | } |
||
| 143 | |||
| 144 | if ($this->input->post('action') == 'edit') { |
||
| 145 | $redirect_url = '/admin/components/run/callbacks/update/' . $model->getId(); |
||
| 146 | } |
||
| 147 | |||
| 148 | pjax($redirect_url); |
||
| 149 | } |
||
| 150 | } else { |
||
| 151 | |||
| 152 | $statuses = SCallbackStatusesQuery::create() |
||
| 153 | ->joinWithI18n(MY_Controller::defaultLocale(), Criteria::LEFT_JOIN) |
||
| 154 | ->orderByIsDefault(Criteria::DESC) |
||
| 155 | ->orderById() |
||
| 156 | ->find(); |
||
| 157 | |||
| 158 | $themes = SCallbackThemesQuery::create() |
||
| 159 | ->joinWithI18n(MY_Controller::defaultLocale(), Criteria::LEFT_JOIN) |
||
| 160 | ->orderByPosition()->orderById() |
||
| 161 | ->find(); |
||
| 162 | |||
| 163 | assetManager::create() |
||
| 164 | ->setData(compact('model', 'statuses', 'themes', 'paginationBrand')) |
||
| 165 | ->renderAdmin('edit'); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Display list of callback statuses |
||
| 171 | * |
||
| 172 | * @return void |
||
| 173 | */ |
||
| 174 | View Code Duplication | public function statuses() { |
|
| 175 | $locale = self::defaultLocale(); |
||
| 176 | $model = SCallbackStatusesQuery::create() |
||
| 177 | ->joinWithI18n($locale, Criteria::JOIN) |
||
| 178 | ->orderBy('IsDefault', Criteria::DESC) |
||
| 179 | ->orderById(Criteria::ASC) |
||
| 180 | ->find(); |
||
| 181 | |||
| 182 | assetManager::create() |
||
| 183 | ->setData(compact('model', 'locale')) |
||
| 184 | ->renderAdmin('status_list'); |
||
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Create new status |
||
| 189 | * |
||
| 190 | * @throws PropelException |
||
| 191 | */ |
||
| 192 | public function createStatus() { |
||
| 193 | $model = new SCallbackStatuses(); |
||
| 194 | $locale = self::defaultLocale(); |
||
| 195 | |||
| 196 | if ($this->input->post()) { |
||
| 197 | $this->form_validation->set_rules($model->rules()); |
||
| 198 | |||
| 199 | if ($this->form_validation->run($this) == FALSE) { |
||
| 200 | showMessage(validation_errors(), '', 'r'); |
||
| 201 | } else { |
||
| 202 | $postData = $this->input->post(); |
||
| 203 | if (!$postData['IsDefault']) { |
||
| 204 | $postData['IsDefault'] = false; |
||
| 205 | } |
||
| 206 | $model->fromArray($postData); |
||
| 207 | $model->save(); |
||
| 208 | |||
| 209 | $this->lib_admin->log(lang('Status callback created', 'callbacks') . '. Id: ' . $model->getId()); |
||
| 210 | showMessage(lang('Position created', 'callbacks')); |
||
| 211 | |||
| 212 | if ($postData['action'] == 'new') { |
||
| 213 | $redirect_url = '/admin/components/run/callbacks/updateStatus/' . $model->getId(); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($postData['action'] == 'exit') { |
||
| 217 | $redirect_url = '/admin/components/run/callbacks/statuses'; |
||
| 218 | } |
||
| 219 | |||
| 220 | pjax($redirect_url); |
||
| 221 | } |
||
| 222 | } else { |
||
| 223 | assetManager::create() |
||
| 224 | ->setData(compact('model', 'locale')) |
||
| 225 | ->renderAdmin('create_status'); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Update new status |
||
| 231 | * |
||
| 232 | * @param int|null $statusId |
||
| 233 | * @param null|string $locale |
||
| 234 | * @throws PropelException |
||
| 235 | */ |
||
| 236 | public function updateStatus($statusId = null, $locale = null) { |
||
| 237 | $locale = $locale ?: self::defaultLocale(); |
||
| 238 | |||
| 239 | $model = SCallbackStatusesQuery::create()->setComment(__METHOD__)->findPk((int) $statusId); |
||
| 240 | |||
| 241 | if ($model === null) { |
||
| 242 | showMessage(lang('Such status does not exist', 'callbacks'), '404', 'r'); |
||
| 243 | } |
||
| 244 | |||
| 245 | if ($this->input->post()) { |
||
| 246 | $this->form_validation->set_rules($model->rules()); |
||
| 247 | |||
| 248 | if ($this->form_validation->run($this) == FALSE) { |
||
| 249 | showMessage(validation_errors()); |
||
| 250 | } else { |
||
| 251 | $postData = $this->input->post(); |
||
| 252 | if (!$postData['IsDefault']) { |
||
| 253 | unset($postData['IsDefault']); |
||
| 254 | } |
||
| 255 | |||
| 256 | $postData['Locale'] = $locale; |
||
| 257 | |||
| 258 | $model->fromArray($postData); |
||
| 259 | $model->save(); |
||
| 260 | |||
| 261 | $this->lib_admin->log(lang('Status callback edited', 'callbacks') . '. Id: ' . $statusId); |
||
| 262 | showMessage(lang('Changes have been saved', 'callbacks')); |
||
| 263 | |||
| 264 | if ($postData['action'] == 'close') { |
||
| 265 | $redirect_url = '/admin/components/run/callbacks/statuses'; |
||
| 266 | } |
||
| 267 | |||
| 268 | View Code Duplication | if ($postData['action'] == 'edit') { |
|
| 269 | $redirect_url = '/admin/components/run/callbacks/updateStatus/' . $model->getId() . '/' . $locale; |
||
| 270 | |||
| 271 | } |
||
| 272 | |||
| 273 | pjax($redirect_url); |
||
| 274 | } |
||
| 275 | View Code Duplication | } else { |
|
| 276 | $model->setLocale($locale); |
||
| 277 | $languages = $this->cms_admin->get_langs(true); |
||
| 278 | assetManager::create()->setData(compact('model', 'languages', 'locale')) |
||
| 279 | ->renderAdmin('edit_status'); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | public function setDefaultStatus() { |
||
| 284 | if ($this->input->post('id') && is_numeric($this->input->post('id'))) { |
||
| 285 | $model = SCallbackStatusesQuery::create()->setComment(__METHOD__)->findPk($this->input->post('id')); |
||
| 286 | if ($model) { |
||
| 287 | if ($model->getIsDefault() == FALSE) { |
||
| 288 | showMessage(lang('Default status was changed', 'callbacks')); |
||
| 289 | } |
||
| 290 | $model->setIsDefault(true); |
||
| 291 | $model->save(); |
||
| 292 | |||
| 293 | $message = lang('Callback default status changed. New default status ID:', 'callbacks') . ' ' . $model->getId(); |
||
| 294 | $this->lib_admin->log($message); |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | |||
| 299 | View Code Duplication | public function changeStatus() { |
|
| 300 | $callbackId = (int) $this->input->post('CallbackId'); |
||
| 301 | $statusId = (int) $this->input->post('StatusId'); |
||
| 302 | |||
| 303 | $model = SCallbacksQuery::create() |
||
| 304 | ->findPk($callbackId); |
||
| 305 | |||
| 306 | $newStatusId = SCallbackStatusesQuery::create()->setComment(__METHOD__)->joinWithI18n(MY_Controller::defaultLocale())->findOneById((int) $statusId); |
||
| 307 | |||
| 308 | if ($newStatusId && $model) { |
||
| 309 | $model->setStatusId($statusId); |
||
| 310 | $model->setUserId($this->dx_auth->get_user_id()); |
||
| 311 | $model->save(); |
||
| 312 | |||
| 313 | $message = lang('Callback status changed to', 'callbacks') . ' ' . $newStatusId->getText() . '. ' |
||
| 314 | . lang('Id:', 'callbacks') . ' ' |
||
| 315 | . $callbackId; |
||
| 316 | $this->lib_admin->log($message); |
||
| 317 | |||
| 318 | showMessage(lang("Callback's status was changed", 'callbacks')); |
||
| 319 | pjax('/admin/components/run/callbacks#callbacks_' . $this->input->post('StatusId')); |
||
| 320 | |||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | public function reorderThemes() { |
||
| 325 | $positions = $this->input->post('positions'); |
||
| 326 | if (count($positions) > 0) { |
||
| 327 | foreach ($positions as $pos => $id) { |
||
| 328 | SCallbackThemesQuery::create() |
||
| 329 | ->filterById($id) |
||
| 330 | ->update(['Position' => (int) $pos]); |
||
| 331 | } |
||
| 332 | showMessage(lang('Positions saved successfully', 'callbacks')); |
||
| 333 | } |
||
| 334 | } |
||
| 335 | |||
| 336 | View Code Duplication | public function changeTheme() { |
|
| 337 | $callbackId = (int) $this->input->post('CallbackId'); |
||
| 338 | $themeId = (int) $this->input->post('ThemeId'); |
||
| 339 | |||
| 340 | $model = SCallbacksQuery::create() |
||
| 341 | ->findPk($callbackId); |
||
| 342 | |||
| 343 | if ($model !== null) { |
||
| 344 | $model->setThemeId($themeId); |
||
| 345 | $model->setUserId($this->dx_auth->get_user_id()); |
||
| 346 | $model->save(); |
||
| 347 | |||
| 348 | $theme = SCallbackThemesI18nQuery::create()->setComment(__METHOD__)->filterById($themeId)->filterByLocale(MY_Controller::defaultLocale())->findOne(); |
||
| 349 | |||
| 350 | $message = lang('Callback theme changed to', 'callbacks') . ' ' . ($theme ? $theme->getText() : lang('Does not have', 'callbacks')) . '. ' |
||
| 351 | . lang('Id:', 'callbacks') . ' ' |
||
| 352 | . $callbackId; |
||
| 353 | $this->lib_admin->log($message); |
||
| 354 | |||
| 355 | showMessage(lang('Callback theme is changed', 'callbacks')); |
||
| 356 | } |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Delete callback |
||
| 361 | * |
||
| 362 | * @return void |
||
| 363 | * @throws PropelException |
||
| 364 | */ |
||
| 365 | public function deleteCallback() { |
||
| 366 | $id = $this->input->post('id'); |
||
| 367 | View Code Duplication | if (is_numeric($id)) { |
|
| 368 | SCallbacksQuery::create()->setComment(__METHOD__)->findPk($id)->delete(); |
||
| 369 | |||
| 370 | $this->lib_admin->log(lang('Callback was removed', 'callbacks') . '. Id: ' . $id); |
||
| 371 | showMessage(lang('Callback was removed', 'callbacks')); |
||
| 372 | } |
||
| 373 | |||
| 374 | View Code Duplication | if (is_array($id)) { |
|
| 375 | SCallbacksQuery::create()->setComment(__METHOD__)->findBy('id', $id)->delete(); |
||
| 376 | $this->lib_admin->log(lang('Callback(s) was removed', 'callbacks') . '. Id: ' . implode(', ', $id)); |
||
| 377 | showMessage(lang('Callback(s) was removed', 'callbacks')); |
||
| 378 | } |
||
| 379 | |||
| 380 | pjax('/admin/components/run/callbacks'); |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Delete status and related callbacks |
||
| 385 | * |
||
| 386 | * @return void |
||
| 387 | */ |
||
| 388 | public function deleteStatus() { |
||
| 389 | $id = (int) $this->input->post('id'); |
||
| 390 | $model = SCallbackStatusesQuery::create()->setComment(__METHOD__)->findPk($id); |
||
| 391 | $mainStatId = $this->db->where('is_default', '1')->get('shop_callbacks_statuses')->row()->id; |
||
| 392 | |||
| 393 | if ($model !== null) { |
||
| 394 | if ($model->getIsDefault() == true) { |
||
| 395 | showMessage(lang('Unable to remove default status', 'callbacks'), lang('Error', 'callbacks'), 'r'); |
||
| 396 | exit; |
||
| 397 | } |
||
| 398 | $this->db->where('status_id', $model->getId()) |
||
| 399 | ->update('shop_callbacks', ['status_id' => $mainStatId]); |
||
| 400 | |||
| 401 | $model->delete(); |
||
| 402 | SCallbackStatusesI18nQuery::create()->setComment(__METHOD__)->findById($id)->delete(); |
||
| 403 | |||
| 404 | $this->lib_admin->log(lang('Status callback was removed', 'callbacks') . '. Id: ' . $id); |
||
| 405 | showMessage(lang('Status was removed', 'callbacks')); |
||
| 406 | pjax('/admin/components/run/callbacks/statuses'); |
||
| 407 | } |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Display list of callback themes |
||
| 412 | * |
||
| 413 | * @return void |
||
| 414 | */ |
||
| 415 | View Code Duplication | public function themes() { |
|
| 416 | $model = SCallbackThemesQuery::create() |
||
| 417 | ->joinWithI18n(\MY_Controller::defaultLocale(), Criteria::JOIN) |
||
| 418 | ->orderByPosition() |
||
| 419 | ->orderById(Criteria::ASC) |
||
| 420 | ->find(); |
||
| 421 | $locale = self::defaultLocale(); |
||
| 422 | |||
| 423 | assetManager::create()->setData(compact('model', 'locale'))->renderAdmin('themes_list'); |
||
| 424 | } |
||
| 425 | |||
| 426 | public function createTheme() { |
||
| 427 | $model = new SCallbackThemes; |
||
| 428 | |||
| 429 | if ($this->input->post()) { |
||
| 430 | $this->form_validation->set_rules($model->rules()); |
||
| 431 | |||
| 432 | if ($this->form_validation->run($this) == FALSE) { |
||
| 433 | showMessage(validation_errors()); |
||
| 434 | } else { |
||
| 435 | $postData = $this->input->post(); |
||
| 436 | $locale = array_key_exists('Locale', $postData) ? $postData['Locale'] : self::defaultLocale(); |
||
| 437 | $postData['Locale'] = $locale; |
||
| 438 | |||
| 439 | $model->fromArray($postData); |
||
| 440 | $model->save(); |
||
| 441 | |||
| 442 | $last_theme_id = $this->db->order_by('id', 'desc')->get('shop_orders')->row()->id; |
||
| 443 | $this->lib_admin->log(lang('Topic callbacks created', 'callbacks') . '. Id: ' . $last_theme_id); |
||
| 444 | showMessage(lang('Topic started', 'callbacks')); |
||
| 445 | |||
| 446 | if ($postData['action'] == 'close') { |
||
| 447 | $redirect_url = '/admin/components/run/callbacks/themes'; |
||
| 448 | } |
||
| 449 | |||
| 450 | if ($postData['action'] == 'edit') { |
||
| 451 | $redirect_url = '/admin/components/run/callbacks/updateTheme/' . $model->getId(); |
||
| 452 | } |
||
| 453 | |||
| 454 | pjax($redirect_url); |
||
| 455 | } |
||
| 456 | } else { |
||
| 457 | $locale = self::defaultLocale(); |
||
| 458 | assetManager::create() |
||
| 459 | ->setData(compact('model', 'locale'))->renderAdmin('create_theme'); |
||
| 460 | } |
||
| 461 | } |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @param null|int $themeId |
||
| 465 | * @param null|string $locale |
||
| 466 | * @throws PropelException |
||
| 467 | */ |
||
| 468 | public function updateTheme($themeId = null, $locale = null) { |
||
| 469 | $locale = $locale ?: self::defaultLocale(); |
||
| 470 | |||
| 471 | $model = SCallbackThemesQuery::create()->setComment(__METHOD__)->findPk((int) $themeId); |
||
| 472 | |||
| 473 | if (!$model) { |
||
| 474 | $this->error404(lang('Error', 'callbacks')); |
||
| 475 | } |
||
| 476 | |||
| 477 | if ($this->input->post()) { |
||
| 478 | $this->form_validation->set_rules($model->rules()); |
||
| 479 | |||
| 480 | if ($this->form_validation->run($this) == FALSE) { |
||
| 481 | showMessage(validation_errors()); |
||
| 482 | } else { |
||
| 483 | $postData = $this->input->post(); |
||
| 484 | $postData['Locale'] = $locale; |
||
| 485 | |||
| 486 | $model->fromArray($postData); |
||
| 487 | $model->save(); |
||
| 488 | |||
| 489 | $this->lib_admin->log(lang('Topic callbacks edited', 'callbacks') . '. Id: ' . $themeId); |
||
| 490 | showMessage(lang('Changes have been saved', 'callbacks')); |
||
| 491 | |||
| 492 | if ($postData['action'] == 'close') { |
||
| 493 | $redirect_url = '/admin/components/run/callbacks/themes'; |
||
| 494 | } |
||
| 495 | |||
| 496 | View Code Duplication | if ($postData['action'] == 'edit') { |
|
| 497 | $redirect_url = '/admin/components/run/callbacks/updateTheme/' . $model->getId() . '/' . $locale; |
||
| 498 | } |
||
| 499 | |||
| 500 | pjax($redirect_url); |
||
| 501 | } |
||
| 502 | View Code Duplication | } else { |
|
| 503 | $model->setLocale($locale); |
||
| 504 | $languages = $this->cms_admin->get_langs(true); |
||
| 505 | |||
| 506 | assetManager::create() |
||
| 507 | ->setData(compact('model', 'languages', 'locale')) |
||
| 508 | ->renderAdmin('edit_theme'); |
||
| 509 | } |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Delete status and related callbacks |
||
| 514 | * |
||
| 515 | * @return void |
||
| 516 | * @throws PropelException |
||
| 517 | */ |
||
| 518 | public function deleteTheme() { |
||
| 519 | $id = (int) $this->input->post('id'); |
||
| 520 | $model = SCallbackThemesQuery::create()->setComment(__METHOD__)->findPk($id); |
||
| 521 | |||
| 522 | if ($model !== null) { |
||
| 523 | $this->db |
||
| 524 | ->where('status_id', $model->getId()) |
||
| 525 | ->update('shop_callbacks', ['theme_id' => '0']); |
||
| 526 | $model->delete(); |
||
| 527 | $this->lib_admin->log(lang('Topic callbacks deleted', 'callbacks') . '. Id: ' . $id); |
||
| 528 | showMessage(lang('Topic deleted', 'callbacks')); |
||
| 529 | pjax('/admin/components/run/callbacks/themes'); |
||
| 530 | } |
||
| 531 | } |
||
| 532 | |||
| 533 | protected function initPagination($totalCallbacks) { |
||
| 534 | $this->load->library('pagination'); |
||
| 535 | $config['base_url'] = site_url('/admin/components/run/callbacks/index?') . http_build_query($this->input->get()); |
||
|
0 ignored issues
–
show
|
|||
| 536 | $config['container'] = 'shopAdminPage'; |
||
| 537 | $config['uri_segment'] = 6; |
||
| 538 | $config['page_query_string'] = true; |
||
| 539 | $config['total_rows'] = $totalCallbacks; |
||
| 540 | $config['per_page'] = $this->perPage; |
||
| 541 | $config['separate_controls'] = true; |
||
| 542 | $config['full_tag_open'] = '<div class="pagination pull-left"><ul>'; |
||
| 543 | $config['full_tag_close'] = '</ul></div>'; |
||
| 544 | $config['controls_tag_open'] = '<div class="pagination pull-right"><ul>'; |
||
| 545 | $config['controls_tag_close'] = '</ul></div>'; |
||
| 546 | $config['next_link'] = lang('Next', 'callbacks') . ' >'; |
||
| 547 | $config['prev_link'] = '< ' . lang('Prev', 'callbacks'); |
||
| 548 | $config['cur_tag_open'] = '<li class="btn-primary active"><span>'; |
||
| 549 | $config['cur_tag_close'] = '</span></li>'; |
||
| 550 | $config['prev_tag_open'] = '<li>'; |
||
| 551 | $config['prev_tag_close'] = '</li>'; |
||
| 552 | $config['next_tag_open'] = '<li>'; |
||
| 553 | $config['next_tag_close'] = '</li>'; |
||
| 554 | $config['num_tag_close'] = '</li>'; |
||
| 555 | $config['num_tag_open'] = '<li>'; |
||
| 556 | $config['num_tag_close'] = '</li>'; |
||
| 557 | $config['last_tag_open'] = '<li>'; |
||
| 558 | $config['last_tag_close'] = '</li>'; |
||
| 559 | $config['first_tag_open'] = '<li>'; |
||
| 560 | $config['first_tag_close'] = '</li>'; |
||
| 561 | $this->pagination->num_links = 6; |
||
| 562 | $this->pagination->initialize($config); |
||
| 563 | return $this->pagination->create_links_ajax(); |
||
| 564 | } |
||
| 565 | |||
| 566 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.