PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / closure.php
vikappointments / admin / controllers Last commit date
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
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 = JFactory::getDate(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