PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.17
VikAppointments Services Booking Calendar v1.2.17
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / closure.php
vikappointments / admin / controllers Last commit date
analytics.php 5 months ago apiban.php 5 months ago apilog.php 5 months ago apiplugin.php 5 months ago apiuser.php 5 months ago backup.php 5 months ago calendar.php 5 months ago city.php 5 months ago closure.php 5 months ago configapp.php 5 months ago configcldays.php 5 months ago configcron.php 5 months ago configemp.php 5 months ago configsmsapi.php 5 months ago configuration.php 5 months ago conversion.php 5 months ago country.php 5 months ago coupon.php 5 months ago coupongroup.php 5 months ago cronjob.php 5 months ago cronjoblog.php 5 months ago customer.php 5 months ago customf.php 5 months ago dashboard.php 5 months ago emplocwdays.php 5 months ago employee.php 5 months ago emprates.php 5 months ago export.php 5 months ago exportres.php 5 months ago file.php 5 months ago findreservation.php 5 months ago group.php 5 months ago import.php 5 months ago index.html 5 months ago invoice.php 5 months ago langcustomf.php 5 months ago langemployee.php 5 months ago langgroup.php 5 months ago langmedia.php 5 months ago langoption.php 5 months ago langoptiongroup.php 5 months ago langpackage.php 5 months ago langpackgroup.php 5 months ago langpayment.php 5 months ago langservice.php 5 months ago langstatuscode.php 5 months ago langsubscr.php 5 months ago langtax.php 5 months ago location.php 5 months ago mailtext.php 5 months ago makerecurrence.php 5 months ago media.php 5 months ago multiorder.php 5 months ago option.php 5 months ago optiongroup.php 5 months ago package.php 5 months ago packgroup.php 5 months ago packorder.php 5 months ago payment.php 5 months ago rate.php 5 months ago reportsemp.php 5 months ago reportsser.php 5 months ago reservation.php 5 months ago restriction.php 5 months ago review.php 5 months ago service.php 5 months ago serworkday.php 5 months ago state.php 5 months ago statuscode.php 5 months ago subscription.php 5 months ago subscrorder.php 5 months ago tag.php 5 months ago tax.php 5 months ago usernote.php 5 months ago waitinglist.php 5 months ago webhook.php 5 months ago wizard.php 5 months ago
closure.php
232 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 closure controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerClosure 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 $data = array();
34
35 $ids = $app->input->get('cid', array(), 'uint');
36
37 if ($ids)
38 {
39 $from = $app->input->get('from');
40
41 if ($from == 'employees')
42 {
43 // use the specified IDs as employees
44 $data['id_employees'] = $ids;
45 }
46 else
47 {
48 // we are probably editing a closure
49 return $this->edit();
50 }
51 }
52
53 // unset user state for being recovered again
54 $app->setUserState('vap.closure.data', $data);
55
56 // check user permissions
57 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.reservations', 'com_vikappointments'))
58 {
59 // back to main list, not authorised to create records
60 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
61 $this->cancel();
62
63 return false;
64 }
65
66 $this->setRedirect('index.php?option=com_vikappointments&view=manageclosure');
67
68 return true;
69 }
70
71 /**
72 * Task used to access the management page of an existing record.
73 *
74 * @return boolean
75 */
76 public function edit()
77 {
78 $app = JFactory::getApplication();
79 $user = JFactory::getUser();
80
81 // unset user state for being recovered again
82 $app->setUserState('vap.closure.data', array());
83
84 // check user permissions
85 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.reservations', 'com_vikappointments'))
86 {
87 // back to main list, not authorised to edit records
88 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
89 $this->cancel();
90
91 return false;
92 }
93
94 $cid = $app->input->getUint('cid', array(0));
95
96 $this->setRedirect('index.php?option=com_vikappointments&view=manageclosure&cid[]=' . $cid[0]);
97
98 return true;
99 }
100
101 /**
102 * Task used to save the record data set in the request.
103 * After saving, the user is redirected to the main list.
104 *
105 * @return void
106 */
107 public function saveclose()
108 {
109 if ($this->save())
110 {
111 $this->cancel();
112 }
113 }
114
115 /**
116 * Task used to save the record data set in the request.
117 * After saving, the user is redirected to the creation
118 * page of a new record.
119 *
120 * @return void
121 */
122 public function savenew()
123 {
124 if ($this->save())
125 {
126 $this->setRedirect('index.php?option=com_vikappointments&task=closure.add');
127 }
128 }
129
130 /**
131 * Task used to save the record data set in the request.
132 * After saving, the user is redirected to the management
133 * page of the record that has been saved.
134 *
135 * @param boolean $copy True to save the record as a copy.
136 *
137 * @return boolean
138 */
139 public function save($copy = false)
140 {
141 $app = JFactory::getApplication();
142 $input = $app->input;
143 $user = JFactory::getUser();
144
145 /**
146 * Added token validation.
147 *
148 * @since 1.7
149 */
150 if (!JSession::checkToken())
151 {
152 // back to main list, missing CSRF-proof token
153 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
154 $this->cancel();
155
156 return false;
157 }
158
159 $args = array();
160 $args['id_employees'] = $input->getUint('id_employees', array());
161 $args['id_employee'] = $input->getUint('id_employee', 0);
162 $args['fromdate'] = $input->getString('fromdate', '');
163 $args['fromtime'] = $input->getUint('fromtime', 0);
164 $args['totime'] = $input->getUint('totime', 0);
165 $args['id'] = $input->getUint('id', 0);
166
167 // convert formatted date into UTC military
168 $date = new JDate(VAPDateHelper::date2sql($args['fromdate']));
169 // adjust to local timezone
170 $date->setTimezone(JFactory::getUser()->getTimezone());
171 // reformat date without time
172 $args['fromdate'] = $date->format('Y-m-d', true);
173
174 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
175
176 // check user permissions
177 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.reservations', 'com_vikappointments'))
178 {
179 // back to main list, not authorised to create/edit records
180 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
181 $this->cancel();
182
183 return false;
184 }
185
186 // get closure model
187 $closure = $this->getModel();
188
189 // try to save arguments
190 $id = $closure->save($args);
191
192 if (!$id)
193 {
194 // get string error
195 $error = $closure->getError(null, true);
196
197 // display error message
198 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
199
200 $url = 'index.php?option=com_vikappointments&view=manageclosure';
201
202 if ($args['id'])
203 {
204 $url .= '&cid[]=' . $args['id'];
205 }
206
207 // redirect to new/edit page
208 $this->setRedirect($url);
209
210 return false;
211 }
212
213 // display generic successful message
214 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
215
216 // redirect to edit page
217 $this->setRedirect('index.php?option=com_vikappointments&task=closure.edit&cid[]=' . $id);
218
219 return true;
220 }
221
222 /**
223 * Redirects the users to the main records list.
224 *
225 * @return void
226 */
227 public function cancel()
228 {
229 $this->setRedirect('index.php?option=com_vikappointments&view=reservations');
230 }
231 }
232