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 / apilog.php
apilog.php
132 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 API log controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerApilog extends VAPControllerAdmin
22 {
23 /**
24 * Deletes a list of records set in the request.
25 *
26 * @return boolean
27 */
28 public function delete()
29 {
30 $app = JFactory::getApplication();
31 $cid = $app->input->get('cid', array(), 'string');
32
33 /**
34 * Added token validation.
35 * Both GET and POST are supported.
36 *
37 * @since 1.7
38 */
39 if (!JSession::checkToken() && !JSession::checkToken('get'))
40 {
41 // back to main list, missing CSRF-proof token
42 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
43 $this->cancel();
44
45 return false;
46 }
47
48 // check user permissions
49 if (!JFactory::getUser()->authorise('core.delete', 'com_vikappointments') || !VAPFactory::getApi()->isEnabled())
50 {
51 // back to main list, not authorised to delete records
52 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
53 $this->cancel();
54
55 return false;
56 }
57
58 // delete selected records
59 $res = $this->getModel()->delete($cid);
60
61 // back to main list
62 $this->cancel();
63
64 return true;
65 }
66
67 /**
68 * Truncates the table.
69 *
70 * @return boolean
71 */
72 public function truncate()
73 {
74 $app = JFactory::getApplication();
75
76 /**
77 * Added token validation.
78 * Both GET and POST are supported.
79 *
80 * @since 1.7
81 */
82 if (!JSession::checkToken() && !JSession::checkToken('get'))
83 {
84 // back to main list, missing CSRF-proof token
85 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
86 $this->cancel();
87
88 return false;
89 }
90
91 // check user permissions
92 if (!JFactory::getUser()->authorise('core.delete', 'com_vikappointments'))
93 {
94 // back to main list, not authorised to delete records
95 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
96 $this->cancel();
97
98 return false;
99 }
100
101 // filter logs by login
102 $id_login = $app->input->getUint('id_login');
103
104 // truncate all records
105 $res = $this->getModel()->truncate($id_login);
106
107 // back to main list
108 $this->cancel();
109
110 return true;
111 }
112
113 /**
114 * Redirects the users to the main records list.
115 *
116 * @return void
117 */
118 public function cancel()
119 {
120 $id_login = JFactory::getApplication()->input->getUint('id_login', 0);
121
122 $url = 'index.php?option=com_vikappointments&view=apilogs';
123
124 if ($id_login)
125 {
126 $url .= '&id_login=' . $id_login;
127 }
128
129 $this->setRedirect($url);
130 }
131 }
132