function format($address, $new_line = "\n") { global $osC_Database; $address_format = ''; if (is_numeric($address)) { $Qaddress = $osC_Database->query('select ab.entry_firstname as firstname, ab.entry_lastname as lastname, ab.entry_company as company, ab.entry_street_address as street_address, ab.entry_suburb as suburb, ab.entry_city as city, ab.entry_postcode as postcode, ab.entry_state as state, ab.entry_zone_id as zone_id, ab.entry_country_id as country_id, ab.entry_telephone as telephone_number, z.zone_code as zone_code, c.countries_name as country_title from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id), :table_countries c where ab.address_book_id = :address_book_id and ab.entry_country_id = c.countries_id'); $Qaddress->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); $Qaddress->bindTable(':table_zones', TABLE_ZONES); $Qaddress->bindTable(':table_countries', TABLE_COUNTRIES); $Qaddress->bindInt(':address_book_id', $address); $Qaddress->execute(); $address = $Qaddress->toArray(); } $firstname = $lastname = ''; if (isset($address['firstname']) && !empty($address['firstname'])) { $firstname = $address['firstname']; $lastname = $address['lastname']; } elseif (isset($address['name']) && !empty($address['name'])) { $firstname = $address['name']; } $state = $address['state']; $state_code = $address['zone_code']; if (isset($address['zone_id']) && is_numeric($address['zone_id']) && $address['zone_id'] > 0) { $state = osC_Address::getZoneName($address['zone_id']); $state_code = osC_Address::getZoneCode($address['zone_id']); } $country = $address['country_title']; if (empty($country) && isset($address['country_id']) && is_numeric($address['country_id']) && $address['country_id'] > 0) { $country = osC_Address::getCountryName($address['country_id']); } if (isset($address['format'])) { $address_format = $address['format']; } elseif (isset($address['country_id']) && is_numeric($address['country_id']) && $address['country_id'] > 0) { $address_format = osC_Address::getFormat($address['country_id']); } if (empty($address_format)) { $address_format = ":name\n:street_address\n:postcode :city\n:country"; } if (defined('DISPLAY_TELEPHONE_NUMBER') && (int) DISPLAY_TELEPHONE_NUMBER == 1) { if (strpos($address_format, 'telephone_number') == false) { $address_format .= "\n:telephone_number"; } } $find_array = array('/\\:name\\b/', '/\\:street_address\\b/', '/\\:suburb\\b/', '/\\:city\\b/', '/\\:postcode\\b/', '/\\:state\\b/', '/\\:state_code\\b/', '/\\:country\\b/', '/\\:telephone_number\\b/'); $replace_array = array(osc_output_string_protected($firstname . ' ' . $lastname), osc_output_string_protected($address['street_address']), osc_output_string_protected($address['suburb']), osc_output_string_protected($address['city']), osc_output_string_protected($address['postcode']), osc_output_string_protected($state), osc_output_string_protected($state_code), osc_output_string_protected($country), osc_output_string_protected($address['telephone_number'])); $formated = preg_replace($find_array, $replace_array, $address_format); if (ACCOUNT_COMPANY > -1 && !empty($address['company'])) { $company = osc_output_string_protected($address['company']); $formated = $company . $new_line . $formated; } if ($new_line != "\n") { $formated = str_replace("\n", $new_line, $formated); } return $formated; }
function insert() { global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart, $osC_Tax; if (isset($_SESSION['prepOrderID'])) { $_prep = explode('-', $_SESSION['prepOrderID']); if ($_prep[0] == $osC_ShoppingCart->getCartID()) { return $_prep[1]; // order_id } else { if (osC_Order::getStatusID($_prep[1]) === 4) { osC_Order::remove($_prep[1]); } } } $customer_address = osC_AddressBook::getEntry($osC_Customer->getDefaultAddressID())->toArray(); $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_state_code, customers_country, customers_country_iso2, customers_country_iso3, customers_telephone, customers_email_address, customers_address_format, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_state_code, delivery_country, delivery_country_iso2, delivery_country_iso3, delivery_address_format, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_state_code, billing_country, billing_country_iso2, billing_country_iso3, billing_address_format, payment_method, payment_module, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_state_code, :customers_country, :customers_country_iso2, :customers_country_iso3, :customers_telephone, :customers_email_address, :customers_address_format, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_state_code, :delivery_country, :delivery_country_iso2, :delivery_country_iso3, :delivery_address_format, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_state_code, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)'); $Qorder->bindTable(':table_orders', TABLE_ORDERS); $Qorder->bindInt(':customers_id', $osC_Customer->getID()); $Qorder->bindValue(':customers_name', $osC_Customer->getName()); $Qorder->bindValue(':customers_company', $customer_address['entry_company']); $Qorder->bindValue(':customers_street_address', $customer_address['entry_street_address']); $Qorder->bindValue(':customers_suburb', $customer_address['entry_suburb']); $Qorder->bindValue(':customers_city', $customer_address['entry_city']); $Qorder->bindValue(':customers_postcode', $customer_address['entry_postcode']); $Qorder->bindValue(':customers_state', $customer_address['entry_state']); $Qorder->bindValue(':customers_state_code', osC_Address::getZoneCode($customer_address['entry_zone_id'])); $Qorder->bindValue(':customers_country', osC_Address::getCountryName($customer_address['entry_country_id'])); $Qorder->bindValue(':customers_country_iso2', osC_Address::getCountryIsoCode2($customer_address['entry_country_id'])); $Qorder->bindValue(':customers_country_iso3', osC_Address::getCountryIsoCode3($customer_address['entry_country_id'])); $Qorder->bindValue(':customers_telephone', $customer_address['entry_telephone']); $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress()); $Qorder->bindValue(':customers_address_format', osC_Address::getFormat($customer_address['entry_country_id'])); $Qorder->bindValue(':customers_ip_address', osc_get_ip_address()); $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname')); $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company')); $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address')); $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb')); $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city')); $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode')); $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state')); $Qorder->bindValue(':delivery_state_code', $osC_ShoppingCart->getShippingAddress('zone_code')); $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title')); $Qorder->bindValue(':delivery_country_iso2', $osC_ShoppingCart->getShippingAddress('country_iso_code_2')); $Qorder->bindValue(':delivery_country_iso3', $osC_ShoppingCart->getShippingAddress('country_iso_code_3')); $Qorder->bindValue(':delivery_address_format', $osC_ShoppingCart->getShippingAddress('format')); $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname')); $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company')); $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address')); $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb')); $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city')); $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode')); $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state')); $Qorder->bindValue(':billing_state_code', $osC_ShoppingCart->getBillingAddress('zone_code')); $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title')); $Qorder->bindValue(':billing_country_iso2', $osC_ShoppingCart->getBillingAddress('country_iso_code_2')); $Qorder->bindValue(':billing_country_iso3', $osC_ShoppingCart->getBillingAddress('country_iso_code_3')); $Qorder->bindValue(':billing_address_format', $osC_ShoppingCart->getBillingAddress('format')); $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title')); $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode()); $Qorder->bindInt(':orders_status', 4); $Qorder->bindValue(':currency', $osC_Currencies->getCode()); $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode())); $Qorder->execute(); $insert_id = $osC_Database->nextID(); foreach ($osC_ShoppingCart->getOrderTotals() as $module) { $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)'); $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); $Qtotals->bindInt(':orders_id', $insert_id); $Qtotals->bindValue(':title', $module['title']); $Qtotals->bindValue(':text', $module['text']); $Qtotals->bindValue(':value', $module['value']); $Qtotals->bindValue(':class', $module['code']); $Qtotals->bindInt(':sort_order', $module['sort_order']); $Qtotals->execute(); } $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)'); $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); $Qstatus->bindInt(':orders_id', $insert_id); $Qstatus->bindInt(':orders_status_id', 4); $Qstatus->bindInt(':customer_notified', '0'); $Qstatus->bindValue(':comments', isset($_SESSION['comments']) ? $_SESSION['comments'] : ''); $Qstatus->execute(); foreach ($osC_ShoppingCart->getProducts() as $products) { $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :products_tax, :products_quantity)'); $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); $Qproducts->bindInt(':orders_id', $insert_id); $Qproducts->bindInt(':products_id', osc_get_product_id($products['id'])); $Qproducts->bindValue(':products_model', $products['model']); $Qproducts->bindValue(':products_name', $products['name']); $Qproducts->bindValue(':products_price', $products['price']); $Qproducts->bindValue(':products_tax', $osC_Tax->getTaxRate($products['tax_class_id'])); $Qproducts->bindInt(':products_quantity', $products['quantity']); $Qproducts->execute(); $order_products_id = $osC_Database->nextID(); if ($osC_ShoppingCart->isVariant($products['item_id'])) { foreach ($osC_ShoppingCart->getVariant($products['item_id']) as $variant) { /* HPDL if (DOWNLOAD_ENABLED == '1') { $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id'); $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS); $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES); $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD); $Qattributes->bindInt(':products_id', $products['id']); $Qattributes->bindInt(':options_id', $attributes['options_id']); $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']); $Qattributes->bindInt(':popt_language_id', $osC_Language->getID()); $Qattributes->bindInt(':poval_language_id', $osC_Language->getID()); $Qattributes->execute(); } */ $Qvariant = $osC_Database->query('insert into :table_orders_products_variants (orders_id, orders_products_id, group_title, value_title) values (:orders_id, :orders_products_id, :group_title, :value_title)'); $Qvariant->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS); $Qvariant->bindInt(':orders_id', $insert_id); $Qvariant->bindInt(':orders_products_id', $order_products_id); $Qvariant->bindValue(':group_title', $variant['group_title']); $Qvariant->bindValue(':value_title', $variant['value_title']); $Qvariant->execute(); /*HPDL if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) { $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)'); $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD); $Qopd->bindInt(':orders_id', $insert_id); $Qopd->bindInt(':orders_products_id', $order_products_id); $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename')); $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays')); $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount')); $Qopd->execute(); } */ } } } $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id; return $insert_id; }