PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / views / managestate / view.html.php
vikappointments / admin / views / managestate Last commit date
tmpl 2 days ago index.html 2 days ago view.html.php 2 days ago
view.html.php
137 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 state management view.
16 *
17 * @since 1.5
18 */
19 class VikAppointmentsViewmanagestate 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 $state = null;
36
37 if ($type == 'edit')
38 {
39 $q = $dbo->getQuery(true)
40 ->select('*')
41 ->from($dbo->qn('#__vikappointments_states'))
42 ->where($dbo->qn('id') . ' = ' . $ids[0]);
43
44 $dbo->setQuery($q, 0, 1);
45 $state = $dbo->loadObject();
46 }
47
48 if (empty($state))
49 {
50 $state = (object) $this->getBlankItem();
51 }
52
53 // use state data stored in user state
54 $this->injectUserStateData($state, 'vap.state.data');
55
56 // load country name
57 $q = $dbo->getQuery(true)
58 ->select($dbo->qn('country_name'))
59 ->from($dbo->qn('#__vikappointments_countries'))
60 ->where($dbo->qn('id') . ' = ' . $state->id_country);
61
62 $dbo->setQuery($q, 0, 1);
63 $countryName = $dbo->loadResult();
64
65 if (!$countryName)
66 {
67 // country not found, back to list
68 $app->redirect('index.php?option=com_vikappointments&view=countries');
69 exit;
70 }
71
72 // set the toolbar
73 $this->addToolBar($type, $countryName);
74
75 $this->state = $state;
76
77 $this->isTmpl = $input->get('tmpl') == 'component';
78
79 // display the template
80 parent::display($tpl);
81 }
82
83 /**
84 * Returns a blank item.
85 *
86 * @return array A blank item for new requests.
87 */
88 protected function getBlankItem()
89 {
90 $input = JFactory::getApplication()->input;
91
92 return array(
93 'id' => 0,
94 'state_name' => '',
95 'state_2_code' => '',
96 'state_3_code' => '',
97 'published' => 1,
98 'id_country' => $input->getUint('id_country', 0),
99 );
100 }
101
102 /**
103 * Setting the toolbar.
104 *
105 * @return void
106 */
107 protected function addToolBar($type, $country_name)
108 {
109 // add menu title and some buttons to the page
110 if ($type == 'edit')
111 {
112 JToolBarHelper::title(JText::sprintf('VAPMAINTITLEEDITSTATE', $country_name), 'vikappointments');
113 }
114 else
115 {
116 JToolBarHelper::title(JText::sprintf('VAPMAINTITLENEWSTATE', $country_name), 'vikappointments');
117 }
118
119 $user = JFactory::getUser();
120
121 if ($user->authorise('core.edit', 'com_vikappointments')
122 || $user->authorise('core.create', 'com_vikappointments'))
123 {
124 JToolbarHelper::apply('state.save', JText::translate('VAPSAVE'));
125 JToolbarHelper::save('state.saveclose', JText::translate('VAPSAVEANDCLOSE'));
126 }
127
128 if ($user->authorise('core.edit', 'com_vikappointments')
129 && $user->authorise('core.create', 'com_vikappointments'))
130 {
131 JToolbarHelper::save2new('state.savenew', JText::translate('VAPSAVEANDNEW'));
132 }
133
134 JToolBarHelper::cancel('state.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL');
135 }
136 }
137