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 / exportres.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
exportres.php
233 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 export appointments controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerExportres 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
32 $data = array();
33 $type = $app->input->get('type', 'appointment');
34 $cid = $app->input->get('cid', array(), 'uint');
35
36 if ($type)
37 {
38 $data['type'] = $type;
39 }
40
41 if ($cid)
42 {
43 $data['cid'] = $cid;
44 }
45
46 // unset user state for being recovered again
47 $app->setUserState('vap.exportres.data', $data);
48
49 $this->setRedirect('index.php?option=com_vikappointments&view=exportres');
50
51 return true;
52 }
53
54 /**
55 * Task used to save the record data set in the request.
56 * After saving, the user is redirected to the management
57 * page of the record that has been saved.
58 *
59 * @return boolean
60 */
61 public function save()
62 {
63 $app = JFactory::getApplication();
64 $input = $app->input;
65 $user = JFactory::getUser();
66
67 /**
68 * Added token validation.
69 *
70 * @since 1.7
71 */
72 if (!JSession::checkToken())
73 {
74 // back to main list, missing CSRF-proof token
75 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
76 $this->cancel();
77
78 return false;
79 }
80
81 $driver = $input->get('driver', '', 'string');
82 $type = $input->get('type', 'appointment', 'string');
83 $filename = $input->get('filename', '', 'string');
84
85 $args = array();
86 $args['fromdate'] = $input->get('fromdate', '', 'string');
87 $args['todate'] = $input->get('todate', '', 'string');
88 $args['cid'] = $input->get('cid', array(), 'uint');
89 $args['id_employee'] = $input->get('id_employee', 0, 'uint');
90 $args['admin'] = true;
91
92 /**
93 * Reformat dates in UTC according to the user locale.
94 *
95 * @since 1.7
96 */
97 $args['fromdate'] = VAPDateHelper::getSqlDateLocale($args['fromdate'], 0, 0, 0);
98 $args['todate'] = VAPDateHelper::getSqlDateLocale( $args['todate'], 23, 59, 59);
99
100 switch ($type)
101 {
102 case 'appointment':
103 $rule = 'core.access.reservations';
104 break;
105
106 default:
107 $rule = 'core.admin';
108 }
109
110 // check user permissions
111 if (!$user->authorise($rule, 'com_vikappointments'))
112 {
113 // back to main list, not authorised to create/edit records
114 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
115 $this->cancel();
116
117 return false;
118 }
119
120 VAPLoader::import('libraries.order.export.factory');
121
122 try
123 {
124 // get driver instance ready to the usage
125 $driver = VAPOrderExportFactory::getDriver($driver, $type, $args);
126
127 // save driver parameters before exporting, otherwise
128 // the database update won't be performed
129 $driver->saveParams();
130
131 // download the exported data
132 $driver->download();
133 }
134 catch (Exception $e)
135 {
136 // display error message
137 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $e->getMessage()), 'error');
138
139 $url = 'index.php?option=com_vikappointments&view=exportres&type=' . $type;
140
141 // redirect to new/edit page
142 $this->setRedirect($url);
143
144 return false;
145 }
146
147 // do not go ahead to avoid including template resources
148 $app->close();
149 }
150
151 /**
152 * Redirects the users to the main records list.
153 *
154 * @return void
155 */
156 public function cancel()
157 {
158 $app = JFactory::getApplication();
159
160 $type = $app->input->get('type', 'appointment');
161
162 switch ($type)
163 {
164 case 'appointment':
165 $view = 'reservations';
166 break;
167
168 default:
169 $view = $type;
170 }
171
172 $this->setRedirect('index.php?option=com_vikappointments&view=' . $view);
173 }
174
175 /**
176 * AJAX end-point used to retrieve the configuration
177 * of the selected driver.
178 *
179 * @return void
180 */
181 public function getdriverformajax()
182 {
183 $input = JFactory::getApplication()->input;
184
185 /**
186 * Added token validation.
187 *
188 * @since 1.7
189 */
190 if (!JSession::checkToken())
191 {
192 // missing CSRF-proof token
193 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
194 }
195
196 $driver = $input->getString('driver');
197 $type = $input->getString('type', 'appointment');
198
199 VAPLoader::import('libraries.order.export.factory');
200
201 // get driver instance
202 $driver = VAPOrderExportFactory::getInstance($driver, $type);
203
204 // get configuration form
205 $form = $driver->getForm();
206
207 // get configuration params
208 $params = $driver->getParams();
209
210 // build display data
211 $data = array(
212 'fields' => $form,
213 'params' => $params,
214 'prefix' => 'export_',
215 );
216
217 // render form by using the payment fields layout
218 $html = JLayoutHelper::render('form.fields', $data);
219
220 // get driver description
221 $description = $driver->getDescription();
222
223 if ($description)
224 {
225 // include description within the form
226 $html = VAPApplication::getInstance()->alert($description, 'info') . $html;
227 }
228
229 // send HTML form to caller
230 $this->sendJSON(json_encode($html));
231 }
232 }
233