PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 3.1.2
Event Tickets with Ticket Scanner v3.1.2
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / sasoEventtickets_Frontend.php
event-tickets-with-ticket-scanner Last commit date
3rd 1 week ago css 1 week ago img 1 week ago includes 1 week ago js 1 week ago languages 1 week ago ticket 1 week ago vendors 1 week ago SASO_EVENTTICKETS.php 1 week ago backend.js 1 week ago changelog-features.json 1 week ago changelog.txt 1 week ago db.php 1 week ago index.php 1 week ago init_file.php 1 week ago order_details.js 1 week ago pwa-sw.js 1 week ago readme.txt 1 week ago saso-eventtickets-validator.js 1 week ago sasoEventtickets_AdminSettings.php 1 week ago sasoEventtickets_Authtoken.php 1 week ago sasoEventtickets_Base.php 1 week ago sasoEventtickets_Core.php 1 week ago sasoEventtickets_Frontend.php 1 week ago sasoEventtickets_Messenger.php 1 week ago sasoEventtickets_Options.php 1 week ago sasoEventtickets_PDF.php 1 week ago sasoEventtickets_Seating.php 1 week ago sasoEventtickets_Ticket.php 1 week ago sasoEventtickets_TicketBadge.php 1 week ago sasoEventtickets_TicketDesigner.php 1 week ago sasoEventtickets_TicketQR.php 1 week ago ticket_events.js 1 week ago ticket_scanner.js 1 week ago validator.js 1 week ago version-notices.json 1 week ago vollstart-cross-promo.php 1 week ago wc_backend.js 1 week ago wc_frontend.js 1 week ago woocommerce-hooks.php 1 week ago
sasoEventtickets_Frontend.php
393 lines
1 <?php
2 include_once(plugin_dir_path(__FILE__)."init_file.php");
3 class sasoEventtickets_Frontend {
4 private $MAIN;
5
6 public function __construct($MAIN) {
7 $this->MAIN = $MAIN;
8 }
9
10 public function executeJSON($a, $data=[]) {
11 try {
12 switch (trim($a)) {
13 case "checkCode":
14 $ret = $this->checkCode($data);
15 break;
16 case "getOptions":
17 $ret = $this->getOptions();
18 break;
19 case "registerToCode":
20 $ret = $this->registerToCode($data);
21 break;
22 case "premium":
23 $ret = $this->executeJSONPremium($data);
24 break;
25 default:
26 throw new Exception(sprintf(esc_html__('function "%s" not implemented', 'event-tickets-with-ticket-scanner'), $a));
27 }
28 } catch(Exception $e) {
29 return wp_send_json_error(['msg'=>$e->getMessage()]);
30 }
31 return wp_send_json_success($ret);
32 }
33
34 private function executeJSONPremium($data) {
35 if (!$this->MAIN->isPremium() || !method_exists($this->MAIN->getPremiumFunctions(), 'executeFrontendJSON')) {
36 throw new Exception("#9001a premium is not active");
37 }
38 if (!isset($data['d'])) throw new Exception("#9002a premium action is missing");
39 return $this->MAIN->getPremiumFunctions()->executeFrontendJSON($data['d'], $data);
40 }
41
42 private function checkIfOnlyLoggedInIsAffected($data) {
43 if ($this->MAIN->getOptions()->isOptionCheckboxActive('onlyForLoggedInWPuser') && !is_user_logged_in()) {
44 $v = trim($this->MAIN->getOptions()->getOptionValue('onlyForLoggedInWPuserMessage'));
45 throw new Exception($v);
46 }
47 return $data;
48 }
49
50 public function isUsed($codeObj) {
51 $ret = false;
52 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
53 if (!empty($metaObj['used']['reg_request'])) {
54 $ret = true;
55 }
56 $ret = apply_filters( $this->MAIN->_add_filter_prefix.'frontend_isUsed', $ret );
57 return $ret;
58 }
59 public function markAsUsed($codeObj, $force=false) {
60 if ($force || $this->MAIN->getOptions()->isOptionCheckboxActive('oneTimeUseOfRegisterCode')) {
61 if ($codeObj['aktiv'] == 1) {
62 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
63 // check ob nicht schon used
64 if (!empty($metaObj['used']['reg_request'])) {
65 $codeObj['_valid'] = 5; // used
66 } else {
67 $confirmedCount = isset($metaObj['confirmedCount']) ? intval($metaObj['confirmedCount']) : 0;
68 $confirmedCount++; // da erst am ende der Count erhöht wird, hier schon +1 machen
69 if ($force) {
70 $optionCount = 1;
71 } else {
72 // setze als used
73 $optionCount = intval($this->MAIN->getOptions()->getOptionValue('oneTimeUseOfRegisterAmount'));
74 if ($optionCount < 1) $optionCount = 1;
75 // check if code has list
76 if ($codeObj['list_id'] > 0) {
77 // lade liste , um auf code list ebene einen abweichenden Wert zu prüfen
78 $listObj = $this->MAIN->getCore()->getListById($codeObj['list_id']);
79 $listObjMeta = [];
80 // check if code has in metaObj a value set and if it is > 0
81 if (isset($listObj["meta"]) && $listObj["meta"] != "") {
82 $listObjMeta = array_replace_recursive($listObjMeta, json_decode($listObj['meta'], true));
83 if (isset($listObjMeta['oneTimeUseOfRegisterAmount'])) {
84 $_optionCount = intval($listObjMeta['oneTimeUseOfRegisterAmount']);
85 if ($_optionCount > 0) $optionCount = $_optionCount;
86 }
87 }
88 }
89 }
90 if ($optionCount <= $confirmedCount) {
91 $metaObj = $this->addNewUsedEntryToMetaObject($metaObj);
92 $codeObj['meta'] = $this->MAIN->getCore()->json_encode_with_error_handling($metaObj);
93 $this->MAIN->getDB()->update("codes", ["meta"=>$codeObj['meta']], ['id'=>$codeObj['id']]);
94 $this->MAIN->getCore()->triggerWebhooks(6, $codeObj);
95 }
96 }
97 }
98 }
99 do_action( $this->MAIN->_do_action_prefix.'frontend_markAsUsed', $codeObj );
100 return $codeObj;
101 }
102
103 private function checkTicket($codeObj) {
104 if ($codeObj != null && isset($codeObj['order_id']) && $codeObj['order_id'] > 0) {
105 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
106 if (isset($metaObj['woocommerce'])
107 && $metaObj['woocommerce']['order_id'] > 0
108 && isset($metaObj['wc_ticket'])
109 && $metaObj['wc_ticket']['is_ticket'] == 1) {
110 if ($metaObj['wc_ticket']['redeemed_date'] != "") {
111 $codeObj['_valid'] = 8; // ticket redeemed
112 }
113 }
114 }
115 $codeObj = apply_filters( $this->MAIN->_add_filter_prefix.'frontend_checkTicket', $codeObj );
116 return $codeObj;
117 }
118
119 private function addNewUsedEntryToMetaObject($metaObj) {
120 // darf auf used setzen, die letzte IP wird genutzt.
121 if (!isset($metaObj['used'])) $metaObj['used'] = [];
122 $metaObj['used']['reg_request'] = wp_date("Y-m-d H:i:s");
123 $metaObj['used']['reg_request_tz'] = wp_timezone_string();
124 $metaObj['used']['reg_ip'] = $this->MAIN->getCore()->getRealIpAddr();
125 if ($this->MAIN->getOptions()->isOptionCheckboxActive('oneTimeUseOfRegisterCodeWPuser')) {
126 $metaObj['used']['reg_userid'] = get_current_user_id();
127 }
128 $metaObj = apply_filters( $this->MAIN->_add_filter_prefix.'frontend_addNewUsedEntryToMetaObject', $metaObj );
129 return $metaObj;
130 }
131
132 private function addJSRedirectToObject($codeObj) {
133 $url = $this->MAIN->getTicketHandler()->getUserRedirectURLForCode($codeObj);
134
135 // füge die in das codeobj ein
136 if (!empty($url)) {
137 $optionBtnLabel = esc_attr($this->MAIN->getOptions()->getOptionValue('userJSRedirectBtnLabel'));
138 if(!isset($codeObj['_retObject'])) $codeObj['_retObject'] = [];
139 $codeObj['_retObject']['userJSRedirect'] = ['url'=>$url, 'btnlabel'=>$optionBtnLabel];
140 }
141
142 return $codeObj;
143 }
144
145 private function getJSRedirect($codeObj) {
146 if ($this->MAIN->getOptions()->isOptionCheckboxActive('userJSRedirectActiv')) {
147 if ($codeObj['_valid'] == 1) {
148 $codeObj = $this->addJSRedirectToObject($codeObj);
149 } else if ($codeObj['_valid'] == 3) { // is registered already
150 if ($this->MAIN->getOptions()->isOptionCheckboxActive('userJSRedirectIfSameUserRegistered')) { //
151 $codeObj = $this->addJSRedirectToObject($codeObj);
152 }
153 }
154 }
155 return $codeObj;
156 }
157
158 public function countConfirmedStatus($codeObj, $force=false) {
159 if (isset($codeObj['aktiv']) && $codeObj['aktiv'] == 1) {
160 if ((isset($codeObj['_valid']) && $codeObj['_valid'] == 1) || $force) {
161 $metaObj = [];
162 if (isset($codeObj["metaObj"])) {
163 $metaObj = $codeObj["metaObj"];
164 } else {
165 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
166 }
167 $confirmedCount = isset($metaObj['confirmedCount']) ? intval($metaObj['confirmedCount']) : 0;
168 if ($confirmedCount == 0) {
169 $metaObj['validation']['first_success'] = wp_date("Y-m-d H:i:s");
170 $metaObj['validation']['first_success_tz'] = wp_timezone_string();
171 $metaObj['validation']['first_ip'] = $this->MAIN->getCore()->getRealIpAddr();
172 }
173 $metaObj['validation']['last_success'] = wp_date("Y-m-d H:i:s");
174 $metaObj['validation']['last_success_tz'] = wp_timezone_string();
175
176 $metaObj['confirmedCount'] = $confirmedCount + 1;
177 $codeObj['meta'] = $this->MAIN->getCore()->json_encode_with_error_handling($metaObj);
178 $this->MAIN->getDB()->update("codes", ["meta"=>$codeObj['meta']], ['id'=>$codeObj['id']]);
179 if (isset($codeObj["metaObj"])) {
180 $codeObj["metaObj"] = $metaObj;
181 }
182 }
183 }
184 do_action( $this->MAIN->_do_action_prefix.'frontend_countConfirmedStatus', $codeObj, $force );
185 return $codeObj;
186 }
187
188 private function setStatusMessages($codeObj) {
189 if(!isset($codeObj['_retObject'])) $codeObj['_retObject'] = [];
190 // Success states: 1=valid, 3=registered, 4=expired(info), 5=used
191 $successStates = [1, 3, 4, 5];
192 $isSuccess = in_array($codeObj['_valid'], $successStates);
193
194 $codeObj['_retObject']['message'] = [
195 'ok' => $isSuccess,
196 'text' => $this->MAIN->getOptions()->getOptionValue('textValidationMessage' . $codeObj['_valid'])
197 ];
198 if (isset($codeObj['_retObject']['message']['text']) && !empty($codeObj['_retObject']['message']['text'])) {
199 $codeObj['_retObject']['message']['text'] = $this->MAIN->getCore()->replaceURLParameters($codeObj['_retObject']['message']['text'], $codeObj);
200 }
201 $codeObj = apply_filters( $this->MAIN->_add_filter_prefix.'frontend_setStatusMessages', $codeObj );
202 return $codeObj;
203 }
204
205 private function displayMessageValue($codeObj) {
206 if ($this->MAIN->getOptions()->isOptionCheckboxActive('displayUserRegistrationOfCode')) {
207 if ($codeObj['_valid'] == 3) {
208 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
209 if (isset($metaObj['user']) && isset($metaObj['user']['value'])) {
210 if(!isset($codeObj['_retObject'])) $codeObj['_retObject'] = [];
211 $text = "";
212 if (isset($codeObj['_retObject']['message']) && !empty($codeObj['_retObject']['message']['text'])) $text = $codeObj['_retObject']['message']['text']."<br>";
213 $preText = $this->MAIN->getOptions()->getOptionValue('displayUserRegistrationPreText');
214 $afterText = $this->MAIN->getOptions()->getOptionValue('displayUserRegistrationAfterText');
215 if (!empty($preText)) $text .= $preText."<br>";
216 $text .= htmlentities($metaObj['user']['value']);
217 if (!empty($afterText)) $text .= "<br>".$afterText;
218 $codeObj['_retObject']['message'] = ['ok'=>true, 'text'=>$text];
219 }
220 }
221 }
222
223 if ($codeObj['_valid'] == 1) {
224 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
225
226 $date_format = $this->MAIN->getOptions()->getOptionDateFormat();
227
228 if ($codeObj['list_id'] != 0) {
229 if ($this->MAIN->getOptions()->isOptionCheckboxActive('displayCodeListDescriptionIfValid')) {
230 // hole code list
231 $listObj = $this->MAIN->getCore()->getListById($codeObj['list_id']);
232 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObjectList($listObj['meta']);
233 // setze message
234 if (isset($metaObj['desc']) && !empty($metaObj['desc'])) {
235 if(!isset($codeObj['_retObject'])) $codeObj['_retObject'] = [];
236 $text = "";
237 if (isset($codeObj['_retObject']['message']) && !empty($codeObj['_retObject']['message']['text'])) $text = $codeObj['_retObject']['message']['text']."<br>";
238 $text .= htmlentities($metaObj['desc']);
239 $codeObj['_retObject']['message'] = ['ok'=>true, 'text'=>$text, 'color'=>'', 'weight'=>'normal']; // normale schriftfarbe
240 }
241 }
242 }
243
244 if ($this->MAIN->getOptions()->isOptionCheckboxActive('displayCodeInfoFirstCheck')) {
245 $label = $this->MAIN->getOptions()->getOptionValue('displayCodeInfoFirstCheckLabel');
246 if (!empty($label) && strpos($label, '{VALIDATION-FIRST_SUCCESS}') === false ) {
247 $label .= " {VALIDATION-FIRST_SUCCESS}";
248 }
249 // Use date_i18n with gmt=true - first_success is stored in local time, gmt=true prevents timezone conversion but still translates month/day names
250 $label = str_replace('{VALIDATION-FIRST_SUCCESS}', date_i18n($date_format, strtotime($metaObj['validation']['first_success']), true), $label);
251 $label = str_replace('{VALIDATION-FIRST_SUCCESS_TZ}', $metaObj['validation']['first_success_tz'], $label);
252 $codeObj['_retObject']['message']['text'] .= "<br>".$label;
253 }
254
255 if ($this->MAIN->getOptions()->isOptionCheckboxActive('displayCodeInfoLastCheck')) {
256 $label = $this->MAIN->getOptions()->getOptionValue('displayCodeInfoLastCheckLabel');
257 if (!empty($label) && strpos($label, '{VALIDATION-LAST_SUCCESS}') === false ) {
258 $label .= " {VALIDATION-LAST_SUCCESS}";
259 }
260 // Use date_i18n with gmt=true - last_success is stored in local time, gmt=true prevents timezone conversion but still translates month/day names
261 $label = str_replace('{VALIDATION-LAST_SUCCESS}', date_i18n($date_format, strtotime($metaObj['validation']['last_success']), true), $label);
262 $label = str_replace('{VALIDATION-LAST_SUCCESS_TZ}', $metaObj['validation']['last_success_tz'], $label);
263 $codeObj['_retObject']['message']['text'] .= "<br>".$label;
264 }
265
266 if ($this->MAIN->getOptions()->isOptionCheckboxActive('displayCodeInfoConfirmedCount')) {
267 $label = $this->MAIN->getOptions()->getOptionValue('displayCodeInfoConfirmedCountLabel');
268 if (!empty($label) && strpos($label, '{CONFIRMEDCOUNT}') === false ) {
269 $label .= " {CONFIRMEDCOUNT}";
270 }
271 $label = str_replace('{CONFIRMEDCOUNT}', intval($metaObj['confirmedCount']), $label);
272 $codeObj['_retObject']['message']['text'] .= "<br>".$label;
273 }
274 }
275
276 if ($codeObj['_valid'] == 7) {
277 $codeObj['_retObject']['message'] = ['ok'=>false, 'text'=>$this->MAIN->getOptions()->getOptionValue('textValidationMessage7')];
278 }
279
280 if (isset($codeObj['_retObject']['message']['text']) && !empty($codeObj['_retObject']['message']['text'])) {
281 $codeObj['_retObject']['message']['text'] = $this->MAIN->getCore()->replaceURLParameters($codeObj['_retObject']['message']['text'], $codeObj);
282 }
283 $codeObj = apply_filters( $this->MAIN->_add_filter_prefix.'frontend_displayMessageValue', $codeObj );
284 return $codeObj;
285 }
286
287 public function checkCode($data) {
288 if (!isset($data['code']) || trim($data['code']) == "") throw new Exception("#1001 code parameter is missing");
289
290 $data = apply_filters($this->MAIN->_add_filter_prefix.'beforeCheckCodePre', $data);
291 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'beforeCheckCodePre')) {
292 $data = $this->MAIN->getPremiumFunctions()->beforeCheckCodePre($data);
293 }
294
295 $data = $this->checkIfOnlyLoggedInIsAffected($data);
296
297 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'beforeCheckCode')) {
298 $data = $this->MAIN->getPremiumFunctions()->beforeCheckCode($data);
299 }
300 $data = apply_filters($this->MAIN->_add_filter_prefix.'beforeCheckCode', $data);
301
302 $valid = 1;
303 $codeObj = [];
304 try {
305 $codeObj = $this->MAIN->getCore()->retrieveCodeByCode($data['code'], false);
306 $codeObj['_data_code'] = urlencode(trim($data['code']));
307 if ($codeObj['aktiv'] != 1) $valid = 2;
308 if ($codeObj['aktiv'] == 2) $valid = 7; // stolen
309
310 if ($valid == 1 && $codeObj['cvv'] != "") {
311 $valid = 6; // ask for CVV
312 if (isset($data['cvv']) && $data['cvv'] != "") {
313 if (strtoupper($data['cvv']) == strtoupper($codeObj['cvv'])) {
314 $valid = 1;
315 }
316 }
317 }
318
319 if ($valid == 1) {
320 if($this->MAIN->getCore()->checkCodeExpired($codeObj)) {
321 $valid = 4;
322 } else if($this->MAIN->getCore()->isCodeIsRegistered($codeObj)) {
323 $valid = 3;
324 }
325 }
326 } catch (Exception $e) {
327 $valid = 0; // not found
328 }
329 $codeObj['_valid'] = $valid;
330 $codeObj['_data_code'] = urlencode(trim($data['code']));
331
332 $codeObj = $this->setStatusMessages($codeObj); // muss später nochmal ausgeführt werden, falls sich das valid nochmal ändert
333
334 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'afterCheckCodePre')) {
335 $codeObj = $this->MAIN->getPremiumFunctions()->afterCheckCodePre($codeObj);
336 }
337 $codeObj = apply_filters($this->MAIN->_add_filter_prefix.'afterCheckCodePre', $codeObj);
338
339 if (count($codeObj) > 1 && isset($codeObj['id']) && !empty($codeObj['id'])) {
340 if ($codeObj['_valid'] != 6) { // cvv check request
341 // codeObj is found
342 $codeObj = $this->markAsUsed($codeObj);
343 $codeObj = $this->checkTicket($codeObj);
344 $codeObj = $this->getJSRedirect($codeObj);
345 $codeObj = $this->countConfirmedStatus($codeObj);
346 $codeObj = $this->setStatusMessages($codeObj); // nochmal, falls sich das valid nochmal geändert hat
347 $codeObj = $this->displayMessageValue($codeObj);
348 }
349 }
350
351 $this->MAIN->getCore()->triggerWebhooks($codeObj['_valid'], $codeObj);
352
353 if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'afterCheckCode')) {
354 $codeObj = $this->MAIN->getPremiumFunctions()->afterCheckCode($codeObj);
355 }
356 $codeObj = apply_filters($this->MAIN->_add_filter_prefix.'afterCheckCode', $codeObj);
357
358 $ret = ['valid'=>$codeObj['_valid']];
359 if (isset($codeObj['_retObject'])) $ret['retObject'] = $codeObj['_retObject'];
360 return $ret;
361 }
362
363 public function getOptions() {
364 return $this->MAIN->getOptions()->getOptionsOnlyPublic();
365 }
366
367 private function registerToCode($data) {
368 if(!isset($data['code'])) throw new Exception("#9201 code parameter missing");
369 if(!isset($data['value'])) throw new Exception("#9202 value parameter missing");
370 $codeObj = $this->MAIN->getCore()->retrieveCodeByCode($data['code']);
371 if ($codeObj['aktiv'] != 1) throw new Exception("#9205 ticket number not correct");
372 if ($this->MAIN->getCore()->checkCodeExpired($codeObj)) throw new Exception("#9206 ticket expired");
373 if ($this->MAIN->getCore()->isCodeIsRegistered($codeObj)) throw new Exception("#9207 ticket already taken - cannot register user to this ticket");
374 // speicher registrierung
375 $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObject($codeObj['meta'], $codeObj);
376 $metaObj['user']['value'] = htmlentities($data['value']);
377 $metaObj['user']['reg_ip'] = $this->MAIN->getCore()->getRealIpAddr();
378 $metaObj['user']['reg_approved'] = 1; // auto approval
379 $metaObj['user']['reg_request'] = wp_date("Y-m-d H:i:s");
380 $metaObj['user']['reg_request_tz'] = wp_timezone_string();
381 $metaObj['user']['reg_userid'] = 0;
382 if ($this->MAIN->getOptions()->isOptionCheckboxActive('allowUserRegisterCodeWPuserid')) {
383 $metaObj['user']['reg_userid'] = get_current_user_id();
384 }
385 $codeObj['meta'] = $this->MAIN->getCore()->json_encode_with_error_handling($metaObj);
386 $this->MAIN->getDB()->update("codes", ["meta"=>$codeObj['meta'], "user_id"=>$metaObj['user']['reg_userid']], ['id'=>$codeObj['id']]);
387 // send webhook if activated
388 $this->MAIN->getCore()->triggerWebhooks(7, $codeObj);
389 do_action( $this->MAIN->_do_action_prefix.'frontend_registerToCode', $data, $codeObj );
390 return $metaObj;
391 }
392 }
393 ?>