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