PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / exportres.php
vikappointments / admin / controllers Last commit date
analytics.php 2 days ago apiban.php 2 days ago apilog.php 2 days ago apiplugin.php 2 days ago apiuser.php 2 days ago backup.php 2 days ago calendar.php 2 days ago city.php 2 days ago closure.php 2 days ago configapp.php 2 days ago configcldays.php 2 days ago configcron.php 2 days ago configemp.php 2 days ago configsmsapi.php 2 days ago configuration.php 2 days ago conversion.php 2 days ago country.php 2 days ago coupon.php 2 days ago coupongroup.php 2 days ago cronjob.php 2 days ago cronjoblog.php 2 days ago customer.php 2 days ago customf.php 2 days ago dashboard.php 2 days ago emplocwdays.php 2 days ago employee.php 2 days ago emprates.php 2 days ago export.php 2 days ago exportres.php 2 days ago file.php 2 days ago findreservation.php 2 days ago group.php 2 days ago import.php 2 days ago index.html 2 days ago invoice.php 2 days ago langcustomf.php 2 days ago langemployee.php 2 days ago langgroup.php 2 days ago langmedia.php 2 days ago langoption.php 2 days ago langoptiongroup.php 2 days ago langpackage.php 2 days ago langpackgroup.php 2 days ago langpayment.php 2 days ago langservice.php 2 days ago langstatuscode.php 2 days ago langsubscr.php 2 days ago langtax.php 2 days ago location.php 2 days ago mailtext.php 2 days ago makerecurrence.php 2 days ago media.php 2 days ago multiorder.php 2 days ago option.php 2 days ago optiongroup.php 2 days ago package.php 2 days ago packgroup.php 2 days ago packorder.php 2 days ago payment.php 2 days ago rate.php 2 days ago reportsemp.php 2 days ago reportsser.php 2 days ago reservation.php 2 days ago restriction.php 2 days ago review.php 2 days ago service.php 2 days ago serworkday.php 2 days ago state.php 2 days ago statuscode.php 2 days ago subscription.php 2 days ago subscrorder.php 2 days ago tag.php 2 days ago tax.php 2 days ago usernote.php 2 days ago waitinglist.php 2 days ago webhook.php 2 days ago wizard.php 2 days 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