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_Authtoken.php
166 lines
| 1 | <?php |
| 2 | include_once(plugin_dir_path(__FILE__)."init_file.php"); |
| 3 | class sasoEventtickets_Authtoken { |
| 4 | public static $authtoken_param = "auth"; |
| 5 | |
| 6 | private $MAIN = null; |
| 7 | |
| 8 | public static function Instance() { |
| 9 | static $inst = null; |
| 10 | if ($inst === null) { |
| 11 | $inst = new sasoEventtickets_Authtoken(); |
| 12 | } |
| 13 | return $inst; |
| 14 | } |
| 15 | |
| 16 | private function __construct() { |
| 17 | global $sasoEventtickets; |
| 18 | $this->MAIN = $sasoEventtickets; |
| 19 | } |
| 20 | |
| 21 | public function checkAccessForAuthtoken($code) { |
| 22 | $code = trim($code); |
| 23 | if (empty($code)) return false; |
| 24 | $sql = "select id from ".$this->MAIN->getDB()->getTabelle("authtokens")." where code = %s and aktiv = 1"; |
| 25 | $d = $this->MAIN->getDB()->_db_datenholen_prepared($sql, [$code]); |
| 26 | if (count($d) == 0) return false; |
| 27 | return apply_filters( $this->MAIN->_add_filter_prefix.'authtoken_checkAccessForAuthtoken', true, $code ); |
| 28 | } |
| 29 | |
| 30 | public function isProductAllowedByAuthToken($authtoken, $product_ids=[]) { |
| 31 | if (!is_array($product_ids)) { |
| 32 | $product_ids = [$product_ids]; |
| 33 | } |
| 34 | |
| 35 | if (count($product_ids) == 0) return true; |
| 36 | |
| 37 | $tokenObj = $this->getAuthtokenByCode($authtoken); |
| 38 | $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObjectAuthtoken($tokenObj['meta']); |
| 39 | |
| 40 | if (empty($metaObj["ticketscanner"]["bound_to_products"])) return true; // no product_ids set up |
| 41 | |
| 42 | $allowed_product_ids = explode(",", $metaObj["ticketscanner"]["bound_to_products"]); |
| 43 | $allowed_product_ids = array_map("intval", $allowed_product_ids); |
| 44 | |
| 45 | foreach($product_ids as $product_id) { |
| 46 | $product_id = intval($product_id); |
| 47 | if (!in_array($product_id, $allowed_product_ids)) return false; |
| 48 | } |
| 49 | return apply_filters( $this->MAIN->_add_filter_prefix.'authtoken_isProductAllowedByAuthToken', true, $authtoken, $product_ids ); |
| 50 | } |
| 51 | |
| 52 | public function getAuthtokens() { |
| 53 | $sql = "select * from ".$this->MAIN->getDB()->getTabelle("authtokens")." order by name asc"; |
| 54 | $tokens = $this->MAIN->getDB()->_db_datenholen($sql); |
| 55 | foreach($tokens as $idx => $value) { |
| 56 | $tokens[$idx]["metaObj"] = $this->MAIN->getCore()->encodeMetaValuesAndFillObjectAuthtoken($value['meta']); |
| 57 | $tokens[$idx]["meta"] = $this->MAIN->getCore()->json_encode_with_error_handling($tokens[$idx]["metaObj"]); |
| 58 | } |
| 59 | return $tokens; |
| 60 | } |
| 61 | |
| 62 | public function getAuthtokenByCode($code) { |
| 63 | $code = trim($code); |
| 64 | if (empty($code)) throw new Exception("#510 auth token not valid"); |
| 65 | $sql = "select * from ".$this->MAIN->getDB()->getTabelle("authtokens")." where code = %s and aktiv = 1"; |
| 66 | $d = $this->MAIN->getDB()->_db_datenholen_prepared($sql, [$code]); |
| 67 | if (count($d) == 0) throw new Exception("#509 auth token not found"); |
| 68 | return $d[0]; |
| 69 | } |
| 70 | |
| 71 | public function getAuthtoken($data) { |
| 72 | if (!isset($data['id'])) throw new Exception("#504 id parameter is missing"); |
| 73 | $sql = "select * from ".$this->MAIN->getDB()->getTabelle("authtokens")." where id = ".intval($data['id']); |
| 74 | $ret = $this->MAIN->getDB()->_db_datenholen($sql); |
| 75 | if (count($ret) == 0) throw new Exception("#505 auth token not found"); |
| 76 | return $ret[0]; |
| 77 | } |
| 78 | |
| 79 | public function addAuthtoken($data) { |
| 80 | if (!isset($data['name']) || trim($data['name']) == "") throw new Exception("#501 name parameter missing - cannot add a new auth token"); |
| 81 | if (!$this->MAIN->getBase()->_isMaxReachedForAuthtokens($this->MAIN->getDB()->_db_getRecordCountOfTable('authtokens'))) throw new Exception("#508 too many authtokens. Unlimited authtokens only with premium"); |
| 82 | $tokenObj = ['meta'=>'']; |
| 83 | $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObjectAuthtoken($tokenObj['meta']); |
| 84 | |
| 85 | $felder = ["name"=>strip_tags($data['name']), "time"=>wp_date("Y-m-d H:i:s")]; |
| 86 | $felder['code'] = strtoupper(base64_encode(get_site_url())."_".md5(time()."-".uniqid())); |
| 87 | $felder['areacode'] = "ticketscanner"; |
| 88 | $felder['aktiv'] = isset($data['aktiv']) ? intval($data['aktiv']) : 1; |
| 89 | $felder['time'] = wp_date("Y-m-d H:i:s"); |
| 90 | |
| 91 | $metaObj = $this->setMetaDataForAuthtokens($data, $metaObj); |
| 92 | |
| 93 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'setFelderAuthtokenEdit')) { |
| 94 | $felder = $this->MAIN->getPremiumFunctions()->setFelderAuthtokenEdit($felder, $data, $tokenObj, $metaObj); |
| 95 | } |
| 96 | if (isset($felder['meta']) && !empty($felder['meta'])) { // evtl gesetzt vom premium plugin |
| 97 | $f_meta = json_decode($felder['meta'], true); |
| 98 | $f_meta["desc"] = strip_tags($f_meta["desc"]); |
| 99 | $metaObj = array_replace_recursive($metaObj, $f_meta); |
| 100 | } |
| 101 | $felder["meta"] = $this->MAIN->getCore()->json_encode_with_error_handling($metaObj); |
| 102 | |
| 103 | $ret = -1; |
| 104 | try { |
| 105 | $ret = $this->MAIN->getDB()->insert("authtokens", $felder); |
| 106 | } catch(Exception $e) { |
| 107 | throw new Exception("#502 ".__("Could not create authtoken. Auth token code exists already.", 'event-tickets-with-ticket-scanner')); |
| 108 | } |
| 109 | do_action( $this->MAIN->_do_action_prefix.'authtoken_addAuthtoken', $data, $ret ); |
| 110 | return $ret; |
| 111 | } |
| 112 | |
| 113 | public function editAuthtoken($data) { |
| 114 | if (!isset($data['id']) || intval($data['id']) == 0) throw new Exception("#506 id parameter missing - cannot edit auth token"); |
| 115 | if (isset($data['name']) && trim($data['name']) == "") throw new Exception("#507 name parameter missing - cannot edit auth token"); |
| 116 | $tokenObj = $this->getAuthtoken($data); |
| 117 | $metaObj = $this->MAIN->getCore()->encodeMetaValuesAndFillObjectAuthtoken($tokenObj['meta']); |
| 118 | $felder = []; |
| 119 | |
| 120 | if (isset($data['name']) && trim($data['name']) != "") $felder["name"] = strip_tags($data['name']); |
| 121 | if (isset($data['aktiv'])) $felder["aktiv"] = intval($data['aktiv']); |
| 122 | $felder['changed'] = wp_date("Y-m-d H:i:s"); |
| 123 | |
| 124 | $metaObj = $this->setMetaDataForAuthtokens($data, $metaObj); |
| 125 | |
| 126 | if ($this->MAIN->isPremium() && method_exists($this->MAIN->getPremiumFunctions(), 'setFelderAuthtokenEdit')) { |
| 127 | $felder = $this->MAIN->getPremiumFunctions()->setFelderAuthtokenEdit($felder, $data, $tokenObj, $metaObj); |
| 128 | } |
| 129 | if (isset($felder['meta']) && !empty($felder['meta'])) { // evtl gesetzt vom premium plugin |
| 130 | $f_meta = json_decode($felder['meta'], true); |
| 131 | $f_meta["desc"] = strip_tags($f_meta["desc"]); |
| 132 | $metaObj = array_replace_recursive($metaObj, $f_meta); |
| 133 | } |
| 134 | $felder["meta"] = $this->MAIN->getCore()->json_encode_with_error_handling($metaObj); |
| 135 | |
| 136 | $where = ["id"=>intval($data['id'])]; |
| 137 | $ret = $this->MAIN->getDB()->update("authtokens", $felder, $where); |
| 138 | do_action( $this->MAIN->_do_action_prefix.'authtoken_editAuthtoken', $data, $ret ); |
| 139 | return $ret; |
| 140 | } |
| 141 | |
| 142 | public function removeAuthtoken($data) { |
| 143 | if (!isset($data['id'])) throw new Exception("#507 id parameter is missing - cannot remove auth token"); |
| 144 | $sql = "delete from ".$this->MAIN->getDB()->getTabelle("authtokens")." where id = ".intval($data['id']); |
| 145 | $ret = $this->MAIN->getDB()->_db_query($sql); |
| 146 | do_action( $this->MAIN->_do_action_prefix.'authtoken_removeAuthtoken', $data, $ret ); |
| 147 | return $ret; |
| 148 | } |
| 149 | |
| 150 | private function setMetaDataForAuthtokens($data, $metaObj) { |
| 151 | if (isset($data['meta'])) { |
| 152 | if (isset($data['meta']['desc'])) { |
| 153 | $metaObj['desc'] = strip_tags(trim($data['meta']['desc'])); |
| 154 | } |
| 155 | if (isset($data['meta']['ticketscanner']) && isset($data['meta']['ticketscanner']['bound_to_products'])) { |
| 156 | $metaObj['ticketscanner']['bound_to_products'] = strip_tags(trim($data['meta']['ticketscanner']['bound_to_products'])); |
| 157 | } |
| 158 | // der rotz hier ist BS und funktioniert nicht, da wieder data.meta genutzt wird |
| 159 | //$this->MAIN->getCore()->alignArrays($metaObj, $data["meta"]); |
| 160 | //$metaObj = array_merge($metaObj, $data["meta"]); |
| 161 | } |
| 162 | return $metaObj; |
| 163 | } |
| 164 | |
| 165 | } |
| 166 | ?> |