PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / langcustomf.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
langcustomf.php
280 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 custom field language controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerLangcustomf 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 // unset user state for being recovered again
34 $app->setUserState('vap.langcustomf.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
38 {
39 // back to main list, not authorised to create records
40 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
41 $this->cancel();
42
43 return false;
44 }
45
46 $id_customf = $app->input->getUint('id_customf');
47
48 $this->setRedirect('index.php?option=com_vikappointments&view=managelangcustomf&id_customf=' . $id_customf);
49
50 return true;
51 }
52
53 /**
54 * Task used to access the management page of an existing record.
55 *
56 * @return boolean
57 */
58 public function edit()
59 {
60 $app = JFactory::getApplication();
61 $user = JFactory::getUser();
62
63 // unset user state for being recovered again
64 $app->setUserState('vap.langcustomf.data', array());
65
66 // check user permissions
67 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
68 {
69 // back to main list, not authorised to edit records
70 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
71 $this->cancel();
72
73 return false;
74 }
75
76 $cid = $app->input->getUint('cid', array(0));
77
78 $this->setRedirect('index.php?option=com_vikappointments&view=managelangcustomf&cid[]=' . $cid[0]);
79
80 return true;
81 }
82
83 /**
84 * Task used to save the record data set in the request.
85 * After saving, the user is redirected to the main list.
86 *
87 * @return void
88 */
89 public function saveclose()
90 {
91 if ($this->save())
92 {
93 $this->cancel();
94 }
95 }
96
97 /**
98 * Task used to save the record data set in the request.
99 * After saving, the user is redirected to the creation
100 * page of a new record.
101 *
102 * @return void
103 */
104 public function savenew()
105 {
106 if ($this->save())
107 {
108 $input = JFactory::getApplication()->input;
109
110 // recover custom field ID from request
111 $id_customf = $input->getUint('id_customf');
112
113 $url = 'index.php?option=com_vikappointments&task=langcustomf.add';
114
115 if ($id_customf)
116 {
117 $url .= '&id_customf=' . $id_customf;
118 }
119
120 $this->setRedirect($url);
121 }
122 }
123
124 /**
125 * Task used to save the record data set in the request.
126 * After saving, the user is redirected to the management
127 * page of the record that has been saved.
128 *
129 * @return boolean
130 */
131 public function save()
132 {
133 $app = JFactory::getApplication();
134 $input = $app->input;
135 $user = JFactory::getUser();
136
137 /**
138 * Added token validation.
139 *
140 * @since 1.7
141 */
142 if (!JSession::checkToken())
143 {
144 // back to main list, missing CSRF-proof token
145 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
146 $this->cancel();
147
148 return false;
149 }
150
151 $args = array();
152 $args['name'] = $input->get('name', '', 'string');
153 $args['choose'] = $input->get('choose', array(), 'string');
154 $args['poplink'] = $input->get('poplink', '', 'string');
155 $args['description'] =JComponentHelper::filterText( $input->get('description', '', 'raw'));
156 $args['id'] = $input->get('id', 0, 'uint');
157 $args['id_customf'] = $input->get('id_customf', 0, 'uint');
158 $args['tag'] = $input->get('tag', '', 'string');
159
160 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
161
162 // check user permissions
163 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
164 {
165 // back to main list, not authorised to create/edit records
166 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
167 $this->cancel();
168
169 return false;
170 }
171
172 // get db model
173 $langcustomf = $this->getModel();
174
175 // try to save arguments
176 $id = $langcustomf->save($args);
177
178 if (!$id)
179 {
180 // get string error
181 $error = $langcustomf->getError(null, true);
182
183 // display error message
184 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
185
186 $url = 'index.php?option=com_vikappointments&view=managelangcustomf';
187
188 if ($args['id'])
189 {
190 $url .= '&cid[]=' . $args['id'];
191 }
192 else
193 {
194 $url .= '&id_customf=' . $args['id_customf'];
195 }
196
197 // redirect to new/edit page
198 $this->setRedirect($url);
199
200 return false;
201 }
202
203 // display generic successful message
204 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
205
206 // redirect to edit page
207 $this->setRedirect('index.php?option=com_vikappointments&task=langcustomf.edit&cid[]=' . $id);
208
209 return true;
210 }
211
212 /**
213 * Deletes a list of records set in the request.
214 *
215 * @return boolean
216 */
217 public function delete()
218 {
219 $app = JFactory::getApplication();
220 $user = JFactory::getUser();
221
222 /**
223 * Added token validation.
224 * Both GET and POST are supported.
225 *
226 * @since 1.7
227 */
228 if (!JSession::checkToken() && !JSession::checkToken('get'))
229 {
230 // back to main list, missing CSRF-proof token
231 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
232 $this->cancel();
233
234 return false;
235 }
236
237 $cid = $app->input->get('cid', array(), 'uint');
238
239 // check user permissions
240 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.custfields', 'com_vikappointments'))
241 {
242 // back to main list, not authorised to delete records
243 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
244 $this->cancel();
245
246 return false;
247 }
248
249 // delete selected records
250 $this->getModel()->delete($cid);
251
252 // back to main list
253 $this->cancel();
254
255 return true;
256 }
257
258 /**
259 * Redirects the users to the main records list.
260 *
261 * @return void
262 */
263 public function cancel()
264 {
265 $input = JFactory::getApplication()->input;
266
267 // recover custom field ID from request
268 $id_customf = $input->getUint('id_customf');
269
270 $url = 'index.php?option=com_vikappointments&view=langcustomf';
271
272 if ($id_customf)
273 {
274 $url .= '&id_customf=' . $id_customf;
275 }
276
277 $this->setRedirect($url);
278 }
279 }
280