/** * Derived from JTable * Records in this table do not need to exist, so we might need to create a record even * if the primary key is set. Therefore we need to overload the store() function. * Technic to inject params as table attributes and to encrypt data * @author Max Milbers * @copyright for derived parts, (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @see libraries/joomla/database/JTable#store($updateNulls) */ function store($updateNulls = false) { $this->setLoggableFieldsForStore(); if ($this->_cryptedFields) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } foreach ($this->_cryptedFields as $field) { if (isset($this->{$field})) { $this->{$field} = tsmCrypt::encrypt($this->{$field}); } } } $this->storeParams(); if (!empty($this->asset_id)) { $currentAssetId = $this->asset_id; } // The asset id field is managed privately by this class. if ($this->_trackAssets) { unset($this->asset_id); } $tblKey = $this->_tbl_key; if (!empty($this->{$tblKey})) { $_qry = 'SELECT `' . $tblKey . '` ' . 'FROM `' . $this->_tbl . '` ' . 'WHERE `' . $tblKey . '` = "' . $this->{$tblKey} . '" '; $this->_db->setQuery($_qry); $this->{$tblKey} = $this->_db->loadResult(); } if (!empty($this->{$tblKey})) { $ok = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); } else { $ok = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); } //reset Params if (isset($this->_tmpParams) and is_array($this->_tmpParams)) { foreach ($this->_tmpParams as $k => $v) { $this->{$k} = $v; } } $this->_tmpParams = false; // If the store failed return false. if (!$ok) { $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg())); vmError($e); return false; } // If the table is not set to track assets return true. if (!$this->_trackAssets) { return true; } if ($this->_locked) { $this->_unlock(); } $parentId = $this->_getAssetParentId(); $name = $this->_getAssetName(); $title = $this->_getAssetTitle(); $asset = JTable::getInstance('Asset', 'JTable', array('dbo' => $this->getDbo())); $asset->loadByName($name); // Re-inject the asset id. $this->asset_id = $asset->id; // Check for an error. if ($error = $asset->getError()) { vmError($error); return false; } // Specify how a new or moved node asset is inserted into the tree. if (empty($this->asset_id) || $asset->parent_id != $parentId) { $asset->setLocation($parentId, 'last-child'); } // Prepare the asset to be stored. $asset->parent_id = $parentId; $asset->name = $name; $asset->title = $title; if ($this->_rules instanceof JAccessRules) { $asset->rules = (string) $this->_rules; } if (!$asset->check() || !$asset->store($updateNulls)) { vmError($asset->getError()); return false; } // Create an asset_id or heal one that is corrupted. if (empty($this->asset_id) || $currentAssetId != $this->asset_id && !empty($this->asset_id)) { // Update the asset_id field in this table. $this->asset_id = (int) $asset->id; $query = $this->_db->getQuery(true); $query->update($this->_db->quoteName($this->_tbl)); $query->set('asset_id = ' . (int) $this->asset_id); $query->where($this->_db->quoteName($tblKey) . ' = ' . (int) $this->{$tblKey}); $this->_db->setQuery($query); if (!$this->_db->execute()) { $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED_UPDATE_ASSET_ID', $this->_db->getErrorMsg())); vmError($e); return false; } } return $ok; }
function createInvoiceNumber($orderDetails, &$invoiceNumber) { $orderDetails = (array) $orderDetails; $db = JFactory::getDBO(); if (!isset($orderDetails['tsmart_order_id'])) { vmWarn('createInvoiceNumber $orderDetails has no tsmart_order_id ', $orderDetails); vmdebug('createInvoiceNumber $orderDetails has no tsmart_order_id ', $orderDetails); } $q = 'SELECT * FROM `#__tsmart_invoices` WHERE `tsmart_order_id`= "' . $orderDetails['tsmart_order_id'] . '" '; // AND `order_status` = "'.$orderDetails->order_status.'" '; $db->setQuery($q); $result = $db->loadAssoc(); if (!class_exists('ShopFunctions')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'; } if (!$result or empty($result['invoice_number'])) { $data['tsmart_order_id'] = $orderDetails['tsmart_order_id']; $data['order_status'] = $orderDetails['order_status']; $data['tsmart_vendor_id'] = $orderDetails['tsmart_vendor_id']; JPluginHelper::importPlugin('vmshopper'); JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); // plugin returns invoice number, 0 if it does not want an invoice number to be created by Vm $plg_datas = $dispatcher->trigger('plgVmOnUserInvoice', array($orderDetails, &$data)); if (!isset($data['invoice_number'])) { // check the default configuration $orderstatusForInvoice = tsmConfig::get('inv_os', array('C')); if (!is_array($orderstatusForInvoice)) { $orderstatusForInvoice = array($orderstatusForInvoice); } //for backward compatibility 2.0.8e $pdfInvoice = (int) tsmConfig::get('pdf_invoice', 0); // backwards compatible $force_create_invoice = vRequest::getCmd('create_invoice', -1); // florian : added if pdf invoice are enabled if (in_array($orderDetails['order_status'], $orderstatusForInvoice) or $pdfInvoice == 1 or $force_create_invoice == $orderDetails['order_create_invoice_pass']) { $q = 'SELECT COUNT(1) FROM `#__tsmart_invoices` WHERE `tsmart_vendor_id`= "' . $orderDetails['tsmart_vendor_id'] . '" '; // AND `order_status` = "'.$orderDetails->order_status.'" '; $db->setQuery($q); $count = $db->loadResult() + 1; if (empty($data['invoice_number'])) { $date = date("Y-m-d"); if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $data['invoice_number'] = str_replace('-', '', substr($date, 2, 8)) . tsmCrypt::getHumanToken(4) . '0' . $count; } } else { return false; } } $table = $this->getTable('invoices'); $table->bindChecknStore($data); $invoiceNumber = array($table->invoice_number, $table->created_on); } elseif (ShopFunctions::InvoiceNumberReserved($result['invoice_number'])) { $invoiceNumber = array($result['invoice_number'], $result['created_on']); return true; } else { $invoiceNumber = array($result['invoice_number'], $result['created_on']); } return true; }
public static function getBgManagerId() { if (!isset(self::$_cuId)) { $cuId = JFactory::getSession()->get('vmAdminID', null); //echo $cuId; if ($cuId) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $cuId = tsmCrypt::decrypt($cuId); if (empty($cuId)) { $cuId = null; } } self::$_cuId = $cuId; } return self::$_cuId; }
/** * Retrieve the detail record for the current $id if the data has not already been loaded. * * @author RickG */ function getShipment($id = 0) { if (!empty($id)) { $this->_id = (int) $id; } if (empty($this->_cache[$this->_id])) { $this->_cache[$this->_id] = $this->getTable('shipmentmethods'); $this->_cache[$this->_id]->load((int) $this->_id); if (empty($this->_cache[$this->_id]->tsmart_vendor_id)) { if (!class_exists('tsmartModelVendor')) { require VMPATH_ADMIN . DS . 'models' . DS . 'vendor.php'; } $this->_cache[$this->_id]->tsmart_vendor_id = tsmartModelVendor::getLoggedVendor(); } if ($this->_cache[$this->_id]->shipment_jplugin_id) { JPluginHelper::importPlugin('vmshipment'); $dispatcher = JDispatcher::getInstance(); $blind = 0; $retValue = $dispatcher->trigger('plgVmDeclarePluginParamsShipmentVM3', array(&$this->_cache[$this->_id])); } if (!empty($this->_cache[$this->_id]->_varsToPushParam)) { tsmTable::bindParameterable($this->_cache[$this->_id], 'shipment_params', $this->_cache[$this->_id]->_varsToPushParam); } //We still need this, because the table is already loaded, but the keys are set later if ($this->_cache[$this->_id]->getCryptedFields()) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } if (isset($this->_cache[$this->_id]->modified_on)) { $date = JFactory::getDate($this->_cache[$this->_id]->modified_on); $date = $date->toUnix(); } else { $date = 0; } foreach ($this->_cache[$this->_id]->getCryptedFields() as $field) { if (isset($this->_cache[$this->_id]->{$field})) { $this->_cache[$this->_id]->{$field} = tsmCrypt::decrypt($this->_cache[$this->_id]->{$field}, $date); } } } /* Add the shipmentcarreir shoppergroups */ $q = 'SELECT `tsmart_shoppergroup_id` FROM #__tsmart_shipmentmethod_shoppergroups WHERE `tsmart_shipmentmethod_id` = "' . $this->_id . '"'; $this->_db->setQuery($q); $this->_cache[$this->_id]->tsmart_shoppergroup_ids = $this->_db->loadColumn(); if (empty($this->_cache[$this->_id]->tsmart_shoppergroup_ids)) { $this->_cache[$this->_id]->tsmart_shoppergroup_ids = 0; } } return $this->_cache[$this->_id]; }
public function save() { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $session = JFactory::getSession(); $sessionData = new stdClass(); $sessionData->selected_method = $this->_selected_method; // card information $sessionData->cc_type = $this->_cc_type; $sessionData->cc_number = tsmCrypt::encrypt($this->_cc_number); $sessionData->cc_cvv = tsmCrypt::encrypt($this->_cc_cvv); $sessionData->cc_expire_month = $this->_cc_expire_month; $sessionData->cc_expire_year = $this->_cc_expire_year; $sessionData->cc_valid = $this->_cc_valid; //Customer settings $sessionData->autobilling_max_amount = $this->_autobilling_max_amount; //PayPal Express $sessionData->token = $this->_token; $sessionData->payer_id = $this->_payer_id; $sessionData->first_name = $this->_first_name; $sessionData->last_name = $this->_last_name; $sessionData->payer_email = $this->_payer_email; // $sessionData->txn_id = $this->_txn_id; // $sessionData->txn_type = $this->_txn_type; // $sessionData->payment_status = $this->_payment_status; // $sessionData->pending_reason = $this->_pending_reason; $session->set('paypal', json_encode($sessionData), 'vm'); }
/** * Decides if the rating/review should be shown on the FE * @author Max Milbers */ private function show($product_id, $show) { //dont show if ($show == 'none') { return false; } else { if ($show == 'all') { return true; } else { if ($show == 'registered') { $user = JFactory::getUser(); return !empty($user->id); } else { if ($show == 'bought') { if (empty($product_id)) { return false; } if (isset($this->_productBought[$product_id])) { return $this->_productBought[$product_id]; } if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $key = tsmCrypt::encrypt('productBought' . $product_id); $count = JFactory::getApplication()->input->cookie->getString($key, false); if ($count) { //check, somehow broken, atm $v = tsmCrypt::encrypt($key); if ($v != $count) { $count = false; } } if (!$count) { $user = JFactory::getUser(); $rr_os = tsmConfig::get('rr_os', array('C')); if (!is_array($rr_os)) { $rr_os = array($rr_os); } $db = JFactory::getDBO(); $q = 'SELECT COUNT(*) as total FROM `#__tsmart_orders` AS o LEFT JOIN `#__tsmart_order_items` AS oi '; $q .= 'ON `o`.`tsmart_order_id` = `oi`.`tsmart_order_id` '; $q .= 'WHERE o.tsmart_user_id > 0 AND o.tsmart_user_id = "' . $user->id . '" AND oi.tsmart_product_id = "' . $product_id . '" '; $q .= 'AND o.order_status IN (\'' . implode("','", $rr_os) . '\') '; $db->setQuery($q); $count = $db->loadResult(); } if ($count) { $this->_productBought[$product_id] = true; return true; } else { $this->_productBought[$product_id] = false; return false; } } } } } }
/** * Change the shopper * * @author Maik Künnemann */ public function changeShopper() { vRequest::vmCheckToken() or jexit('Invalid Token'); $app = JFactory::getApplication(); $redirect = vRequest::getString('redirect', false); if ($redirect) { $red = $redirect; } else { $red = JRoute::_('index.php?option=com_virtuemart&view=cart'); } $id = vmAccess::getBgManagerId(); $current = JFactory::getUser(); $manager = vmAccess::manager('user'); if (!$manager) { $app->enqueueMessage(tsmText::sprintf('COM_VIRTUEMART_CART_CHANGE_SHOPPER_NO_PERMISSIONS', $current->name . ' (' . $current->username . ')'), 'error'); $app->redirect($red); return false; } $userID = vRequest::getCmd('userID'); if ($manager and !empty($userID) and $userID != $current->id) { if ($userID == $id) { } else { if (vmAccess::manager('user', $userID)) { //if($newUser->authorise('core.admin', 'com_virtuemart') or $newUser->authorise('vm.user', 'com_virtuemart')){ $app->enqueueMessage(tsmText::sprintf('COM_VIRTUEMART_CART_CHANGE_SHOPPER_NO_PERMISSIONS', $current->name . ' (' . $current->username . ')'), 'error'); $app->redirect($red); } } } $searchShopper = vRequest::getString('searchShopper'); if (!empty($searchShopper)) { $this->display(); return false; } //update session $session = JFactory::getSession(); $adminID = $session->get('vmAdminID'); if (!isset($adminID)) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $session->set('vmAdminID', tsmCrypt::encrypt($current->id)); } $newUser = JFactory::getUser($userID); $session->set('user', $newUser); //update cart data $cart = VirtueMartCart::getCart(); $usermodel = tmsModel::getModel('user'); $data = $usermodel->getUserAddressList(vRequest::getCmd('userID'), 'BT'); if (isset($data[0])) { foreach ($data[0] as $k => $v) { $data[$k] = $v; } } $cart->BT['email'] = $newUser->email; $cart->ST = 0; $cart->STsameAsBT = 1; $cart->selected_shipto = 0; $cart->virtuemart_shipmentmethod_id = 0; $cart->saveAddressInCart($data, 'BT'); $msg = tsmText::sprintf('COM_VIRTUEMART_CART_CHANGED_SHOPPER_SUCCESSFULLY', $newUser->name . ' (' . $newUser->username . ')'); if (empty($userID)) { $red = JRoute::_('index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT'); $msg = tsmText::sprintf('COM_VIRTUEMART_CART_CHANGED_SHOPPER_SUCCESSFULLY', ''); } $app->enqueueMessage($msg, 'info'); $app->redirect($red); }
function getMd($cryptedMd) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $decryptedMd = tsmCrypt::decrypt($cryptedMd); $md = json_decode($decryptedMd, true); return $md; }
function _getAuthorizeNetFromSession() { if (!class_exists('tsmCrypt')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'tsmcrypt.php'; } $session = JFactory::getSession(); $authorizenetSession = $session->get('authorizenet', 0, 'vm'); if (!empty($authorizenetSession)) { $authorizenetData = (object) json_decode($authorizenetSession, true); $this->_cc_type = $authorizenetData->cc_type; $this->_cc_number = tsmCrypt::decrypt($authorizenetData->cc_number); $this->_cc_cvv = tsmCrypt::decrypt($authorizenetData->cc_cvv); $this->_cc_expire_month = $authorizenetData->cc_expire_month; $this->_cc_expire_year = $authorizenetData->cc_expire_year; $this->_cc_valid = $authorizenetData->cc_valid; } }
private function getRetourParams($cryptedParams) { if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $cryptedParams = base64_decode($cryptedParams); $params = tsmCrypt::decrypt($cryptedParams); $paramsArray = explode(":", $params); $retourParams['virtuemart_paymentmethod_id'] = $paramsArray[0]; $retourParams['order_number'] = $paramsArray[1]; $retourParams['context'] = $paramsArray[2]; return $retourParams; }
public static function getFormToken($fNew = false) { $sess = JFactory::getSession(); $user = JFactory::getUser(); if (empty($user->id)) { $user->id = 0; } if (!class_exists('tsmCrypt')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'tsmcrypt.php'; } $token = $sess->get('session.token'); if ($token === null || $fNew) { $token = tsmCrypt::getToken(); $sess->set('session.token', $token); } $hash = self::getHash($user->id . $token); return $hash; }