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