PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / exportres.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
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