PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / empsettings.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 1 month ago confirmapp.php 2 years ago empattachser.php 4 years ago empeditcoupon.php 4 years ago empeditcustfield.php 4 years ago empeditlocation.php 4 years ago empeditpay.php 4 years ago empeditprofile.php 5 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 2 years ago employeesearch.php 2 years ago employeeslist.php 4 years ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 1 year ago index.html 6 years ago modules.php 1 year ago order.php 5 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 1 year ago servicesearch.php 2 years ago subscriptions.php 4 years ago subscrpayment.php 1 year ago userprofile.php 5 months ago waitinglist.php 4 years ago
empsettings.php
130 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.employee.area.controller');
15
16 /**
17 * Employee area edit settings controller.
18 *
19 * @since 1.6
20 */
21 class VikAppointmentsControllerEmpsettings extends VAPEmployeeAreaController
22 {
23 /**
24 * Task used to save the record data set in the request.
25 * After saving, the user is redirected to the main list.
26 *
27 * @return void
28 *
29 * @since 1.7
30 */
31 public function saveclose()
32 {
33 if ($this->save())
34 {
35 $this->setRedirect('index.php?option=com_vikappointments&view=emplogin');
36 }
37 }
38
39 /**
40 * Save employee settings.
41 *
42 * @return void
43 */
44 public function save()
45 {
46 $app = JFactory::getApplication();
47 $input = $app->input;
48 $auth = VAPEmployeeAuth::getInstance();
49
50 // always redirect to edit page
51 $this->setRedirect('index.php?option=com_vikappointments&view=empsettings');
52
53 /**
54 * Added token validation.
55 *
56 * @since 1.7
57 */
58 if (!JSession::checkToken())
59 {
60 // back to main list, missing CSRF-proof token
61 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
62
63 return false;
64 }
65
66 // check user permissions
67 if (!$auth->isEmployee())
68 {
69 // back to main list, not authorised to edit records
70 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
71
72 return false;
73 }
74
75 // get settings
76 $args = array();
77 $args['listlimit'] = $input->getUint('listlimit', 5);
78 $args['listposition'] = $input->getUint('listposition', 1);
79 $args['listordering'] = $input->getString('listordering', 'ASC');
80 $args['numcals'] = $input->getUint('numcals', 6);
81 $args['firstmonth'] = $input->getUint('firstmonth', 0);
82 $args['zip_field_id'] = $input->getUint('zip_field_id', 0);
83 $args['zipcodesfrom'] = $input->get('zip_code_from', array(), 'string');
84 $args['zipcodesto'] = $input->get('zip_code_to', array(), 'string');
85 $args['synckey'] = $input->getString('synckey', '');
86 $args['timezone'] = $input->getString('timezone', '');
87
88 // get settings model
89 $model = $this->getModel('empsettingsman');
90
91 // try to save arguments
92 $id = $model->save($args);
93
94 if (!$id)
95 {
96 // get string error
97 $error = $model->getError(null, true);
98
99 if ($error)
100 {
101 // display error message
102 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
103 }
104
105 return false;
106 }
107
108 $employee = $auth->getEmployee();
109
110 /**
111 * Update the listable status of the employee.
112 * This action is allowed only in case the employee account is not expired.
113 *
114 * @since 1.7.5
115 */
116 if ($employee['active_to'] != 1 || $employee['active_to_date'] >= JFactory::getDate())
117 {
118 $saved = $this->getModel('employee')->save([
119 'id' => $employee['id'],
120 'listable' => $input->getUint('listable', 0),
121 ]);
122 }
123
124 // display generic successful message
125 $app->enqueueMessage(JText::translate('VAPEMPSETTINGSUPDATED'));
126
127 return true;
128 }
129 }
130