view.html.php
141 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 | /** |
| 15 | * VikAppointments city management view. |
| 16 | * |
| 17 | * @since 1.5 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanagecity extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $app = JFactory::getApplication(); |
| 29 | $input = $app->input; |
| 30 | $dbo = JFactory::getDbo(); |
| 31 | |
| 32 | $ids = $input->getUint('cid', array()); |
| 33 | $type = $ids ? 'edit' : 'new'; |
| 34 | |
| 35 | $city = null; |
| 36 | |
| 37 | if ($type == 'edit') |
| 38 | { |
| 39 | $q = $dbo->getQuery(true) |
| 40 | ->select('*') |
| 41 | ->from($dbo->qn('#__vikappointments_cities')) |
| 42 | ->where($dbo->qn('id') . ' = ' . $ids[0]); |
| 43 | |
| 44 | $dbo->setQuery($q, 0, 1); |
| 45 | $city = $dbo->loadObject(); |
| 46 | } |
| 47 | |
| 48 | if (empty($city)) |
| 49 | { |
| 50 | $city = (object) $this->getBlankItem(); |
| 51 | } |
| 52 | |
| 53 | // use city data stored in user city |
| 54 | $this->injectUserStateData($city, 'vap.city.data'); |
| 55 | |
| 56 | // load state name |
| 57 | $q = $dbo->getQuery(true) |
| 58 | ->select($dbo->qn(array('s.state_name', 'c.country_2_code'))) |
| 59 | ->from($dbo->qn('#__vikappointments_states', 's')) |
| 60 | ->leftjoin($dbo->qn('#__vikappointments_countries', 'c') . ' ON ' . $dbo->qn('c.id') . ' = ' . $dbo->qn('s.id_country')) |
| 61 | ->where($dbo->qn('s.id') . ' = ' . $city->id_state); |
| 62 | |
| 63 | $dbo->setQuery($q, 0, 1); |
| 64 | $state = $dbo->loadObject(); |
| 65 | |
| 66 | if (!$state) |
| 67 | { |
| 68 | // state not found, back to list |
| 69 | $app->redirect('index.php?option=com_vikappointments&view=countries'); |
| 70 | exit; |
| 71 | } |
| 72 | |
| 73 | // set the toolbar |
| 74 | $this->addToolBar($type, $state->state_name); |
| 75 | |
| 76 | $this->city = $city; |
| 77 | $this->state = $state; |
| 78 | |
| 79 | $this->isTmpl = $input->get('tmpl') == 'component'; |
| 80 | |
| 81 | // display the template |
| 82 | parent::display($tpl); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns a blank item. |
| 87 | * |
| 88 | * @return array A blank item for new requests. |
| 89 | */ |
| 90 | protected function getBlankItem() |
| 91 | { |
| 92 | $input = JFactory::getApplication()->input; |
| 93 | |
| 94 | return array( |
| 95 | 'id' => 0, |
| 96 | 'city_name' => '', |
| 97 | 'city_2_code' => '', |
| 98 | 'city_3_code' => '', |
| 99 | 'latitude' => '', |
| 100 | 'longitude' => '', |
| 101 | 'published' => 1, |
| 102 | 'id_state' => $input->getUint('id_state', 0), |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Setting the toolbar. |
| 108 | * |
| 109 | * @return void |
| 110 | */ |
| 111 | protected function addToolBar($type, $state_name) |
| 112 | { |
| 113 | // add menu title and some buttons to the page |
| 114 | if ($type == 'edit') |
| 115 | { |
| 116 | JToolBarHelper::title(JText::sprintf('VAPMAINTITLEEDITCITY', $state_name), 'vikappointments'); |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | JToolBarHelper::title(JText::sprintf('VAPMAINTITLENEWCITY', $state_name), 'vikappointments'); |
| 121 | } |
| 122 | |
| 123 | $user = JFactory::getUser(); |
| 124 | |
| 125 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 126 | || $user->authorise('core.create', 'com_vikappointments')) |
| 127 | { |
| 128 | JToolbarHelper::apply('city.save', JText::translate('VAPSAVE')); |
| 129 | JToolbarHelper::save('city.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 130 | } |
| 131 | |
| 132 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 133 | && $user->authorise('core.create', 'com_vikappointments')) |
| 134 | { |
| 135 | JToolbarHelper::save2new('city.savenew', JText::translate('VAPSAVEANDNEW')); |
| 136 | } |
| 137 | |
| 138 | JToolBarHelper::cancel('city.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 139 | } |
| 140 | } |
| 141 |