function fn_buy_together_update_chain($item_id, $product_id, $item_data, $auth, $lang_code = CART_LANGUAGE) { if (empty($product_id) || $product_id == 0) { return false; } SecurityHelper::sanitizeObjectData('buy_together_chain', $item_data); $show_notice = true; $item_data['product_id'] = $product_id; if (!empty($item_data['products'])) { foreach ($item_data['products'] as $key => $product) { // Delete products with empty amount if (empty($product['amount']) || intval($product['amount']) == 0) { unset($item_data['products'][$key]); continue; } $item_data['products'][$key]['modifier'] = floatval($item_data['products'][$key]['modifier']); $is_restricted = false; fn_set_hook('buy_together_restricted_product', $product['product_id'], $auth, $is_restricted, $show_notice); if ($is_restricted) { unset($item_data['products'][$key]); } } $item_data['products'] = serialize($item_data['products']); } else { $item_data['products'] = array(); } if (!empty($item_data['date_from'])) { $item_data['date_from'] = fn_parse_date($item_data['date_from']); } if (!empty($item_data['date_to'])) { $item_data['date_to'] = fn_parse_date($item_data['date_to']); } if (empty($item_id) || $item_id == 0) { //Create a new chain $item_id = db_query("INSERT INTO ?:buy_together ?e", $item_data); if (empty($item_id)) { return false; } $_data = array(); $_data['chain_id'] = $item_id; $_data['name'] = !empty($item_data['name']) ? $item_data['name'] : ''; $_data['description'] = !empty($item_data['description']) ? $item_data['description'] : ''; foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:buy_together_descriptions ?e", $_data); } } else { //Update already existing chain $_data = array(); $_data['chain_id'] = $item_id; $_data['name'] = !empty($item_data['name']) ? $item_data['name'] : ''; $_data['description'] = !empty($item_data['description']) ? $item_data['description'] : ''; db_query("UPDATE ?:buy_together SET ?u WHERE chain_id = ?i", $item_data, $item_id); db_query("UPDATE ?:buy_together_descriptions SET ?u WHERE chain_id = ?i AND lang_code = ?s", $_data, $item_id, $lang_code); } return $item_id; }
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE) { // news title required if (empty($news_data['news'])) { return false; } $_data = $news_data; $_data['date'] = fn_parse_date($news_data['date']); if (isset($_data['localization'])) { $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } if (empty($news_id)) { $create = true; $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data); if (empty($news_id)) { return false; } // Adding descriptions foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:news_descriptions ?e", $_data); } } else { if (!empty($news_data['block_id'])) { fn_add_items_to_block($news_data['block_id'], $news_data['add_items'], $news_id, 'news'); } db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id); // update news descriptions $_data = $news_data; db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code); } // Log news update/add fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id)); fn_set_hook('update_news', $news_data, $news_id, $lang_code); return $news_id; }
foreach ($packages as $products) { foreach ($products['data']['products'] as $product) { if (!empty($product['product_type']) && $product['product_type'] == 18) { $settings_shipping_spsr['insurance_type'] = 'INS'; } } } } if ($settings_shipping_spsr['insurance_type'] == 'INS') { $total_invoices_cost_ins += $invoice['cost']; } if ($settings_shipping_spsr['insurance_type'] == 'VAL') { $total_invoices_cost_val += $invoice['cost']; } if (!empty($spsr_invoice['delivery_date'])) { $spsr_invoice['delivery_date'] = date('Y-m-d', fn_parse_date($spsr_invoice['delivery_date'])) . 'T00:00:00.000'; } $invoice_for_xml = array('Action' => "N", 'ShipRefNum' => $invoice['ship_ref_num'], 'PickUpType' => $spsr_invoice['pick_up_type'], 'ProductCode' => $spsr_invoice['invoice_product_code'], 'FullDescription' => fn_html_escape($invoice_full_desc), 'PiecesCount' => count($packages), 'DeliveryDate' => $spsr_invoice['delivery_date'], 'DeliveryTime' => $spsr_invoice['delivery_time'], 'InsuranceType' => $additional_params['insurance_type'], 'InsuranceSum' => $invoice['cost']); if ($settings_shipping_spsr['cod'] == 1) { $invoice_for_xml['CODGoodsSum'] = $invoice['cost'] + $invoice['invoice_shipping_cost']; $invoice_for_xml['CODDeliverySum'] = $invoice['invoice_shipping_cost']; $total_invoices_cost_cod += $invoice_for_xml['CODGoodsSum']; } $invoice_xml = RusSpsr::invoiceXml($invoice_for_xml, $pieces_xml, $shipper_xml, $receiver_xml, $additional_services_xml, $sms_xml); $save_data['invoices'][$shipment_id] = $invoice; $save_data['invoices'][$shipment_id]['shipper'] = $shipper_for_xml; $save_data['invoices'][$shipment_id]['receiver_xml'] = $receiver_for_xml; $save_data['invoices'][$shipment_id]['invoice_for_xml'] = $invoice_for_xml; $invoices_xml = array_merge($invoices_xml, $invoice_xml); } else { unset($invoices[$invoice_key]);
function fn_update_product_filter($filter_data, $filter_id, $lang_code = DESCR_SL) { if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) { if (!empty($filter_id) && !fn_check_company_id('product_filters', 'filter_id', $filter_id)) { fn_company_access_denied_notification(); return false; } if (!empty($filter_id)) { unset($filter_data['company_id']); } } // Parse filter type if (strpos($filter_data['filter_type'], 'FF-') === 0 || strpos($filter_data['filter_type'], 'RF-') === 0 || strpos($filter_data['filter_type'], 'DF-') === 0) { $filter_data['feature_id'] = str_replace(array('RF-', 'FF-', 'DF-'), '', $filter_data['filter_type']); $filter_data['feature_type'] = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $filter_data['feature_id']); } else { $filter_data['field_type'] = str_replace(array('R-', 'B-'), '', $filter_data['filter_type']); $filter_fields = fn_get_product_filter_fields(); } if (isset($filter_data['display_more_count']) && isset($filter_data['display_count']) && $filter_data['display_more_count'] < $filter_data['display_count']) { $filter_data['display_more_count'] = $filter_data['display_count']; } if (!empty($filter_id)) { db_query('UPDATE ?:product_filters SET ?u WHERE filter_id = ?i', $filter_data, $filter_id); db_query('UPDATE ?:product_filter_descriptions SET ?u WHERE filter_id = ?i AND lang_code = ?s', $filter_data, $filter_id, $lang_code); } else { $filter_data['filter_id'] = $filter_id = db_query('INSERT INTO ?:product_filters ?e', $filter_data); foreach (fn_get_translation_languages() as $filter_data['lang_code'] => $_d) { db_query("INSERT INTO ?:product_filter_descriptions ?e", $filter_data); } } $delete_all_ranges = false; // if filter has ranges if (!empty($filter_data['feature_type']) && strpos('ODN', $filter_data['feature_type']) !== false || !empty($filter_data['field_type']) && !empty($filter_fields[$filter_data['field_type']]['is_range'])) { $range_ids = array(); foreach ($filter_data['ranges'] as $k => $range) { if (!empty($filter_data['feature_type']) && $filter_data['feature_type'] == 'D') { $range['to'] = fn_parse_date($filter_data['dates_ranges'][$k]['to']); $range['from'] = fn_parse_date($filter_data['dates_ranges'][$k]['from']); } $range['filter_id'] = $filter_id; if (!empty($filter_data['feature_id'])) { $range['feature_id'] = $filter_data['feature_id']; } if (!empty($range['range_id'])) { db_query("UPDATE ?:product_filter_ranges SET ?u WHERE range_id = ?i", $range, $range['range_id']); db_query('UPDATE ?:product_filter_ranges_descriptions SET ?u WHERE range_id = ?i AND lang_code = ?s', $range, $range['range_id'], $lang_code); } elseif ((!empty($range['from']) || !empty($range['to'])) && !empty($range['range_name'])) { $range['range_id'] = db_query("INSERT INTO ?:product_filter_ranges ?e", $range); foreach (fn_get_translation_languages() as $range['lang_code'] => $_d) { db_query("INSERT INTO ?:product_filter_ranges_descriptions ?e", $range); } } if (!empty($range['range_id'])) { $range_ids[] = $range['range_id']; } } if (!empty($range_ids)) { $deleted_ranges = db_get_fields("SELECT range_id FROM ?:product_filter_ranges WHERE filter_id = ?i AND range_id NOT IN (?n)", $filter_id, $range_ids); if (!empty($deleted_ranges)) { db_query("DELETE FROM ?:product_filter_ranges WHERE range_id IN (?n)", $deleted_ranges); db_query("DELETE FROM ?:product_filter_ranges_descriptions WHERE range_id IN (?n)", $deleted_ranges); } } else { $delete_all_ranges = true; } } else { $delete_all_ranges = true; } if ($delete_all_ranges) { $deleted_ranges = db_get_fields("SELECT range_id FROM ?:product_filter_ranges WHERE filter_id = ?i", $filter_id); db_query("DELETE FROM ?:product_filter_ranges WHERE filter_id = ?i", $filter_id); db_query("DELETE FROM ?:product_filter_ranges_descriptions WHERE range_id IN (?n)", $deleted_ranges); } fn_set_hook('update_product_filter', $filter_data, $filter_id, $lang_code); return $filter_id; }
function fn_create_periods($params) { $period_name = empty($params['period']) ? null : $params['period']; $available_periods = array(DateTimeHelper::PERIOD_TODAY, DateTimeHelper::PERIOD_YESTERDAY, DateTimeHelper::PERIOD_THIS_WEEK, DateTimeHelper::PERIOD_LAST_WEEK, DateTimeHelper::PERIOD_THIS_MONTH, DateTimeHelper::PERIOD_LAST_MONTH, DateTimeHelper::PERIOD_THIS_YEAR, DateTimeHelper::PERIOD_LAST_YEAR, DateTimeHelper::PERIOD_DAY_AGO_TILL_NOW, DateTimeHelper::PERIOD_WEEK_AGO_TILL_NOW, DateTimeHelper::PERIOD_MONTH_AGO_TILL_NOW); if (in_array($period_name, $available_periods)) { $period = DateTimeHelper::getPeriod($period_name); $time_from = $period['from']->getTimestamp(); $time_to = $period['to']->getTimestamp(); } elseif ($period_name == 'HC' && isset($params['last_days'])) { $period = DateTimeHelper::createCustomPeriod("-{$params['last_days']} day", 'now'); $time_from = $period['from']->getTimestamp(); $time_to = $period['to']->getTimestamp(); } else { $time_from = empty($params['time_from']) ? 0 : fn_parse_date($params['time_from']); $time_to = empty($params['time_to']) ? TIME : fn_parse_date($params['time_to'], true); } Tygh::$app['view']->assign('time_from', $time_from); Tygh::$app['view']->assign('time_to', $time_to); return array($time_from, $time_to); }
function fn_create_periods($params) { $today = getdate(TIME); $period = !empty($params['period']) ? $params['period'] : null; $time_from = !empty($params['time_from']) ? fn_parse_date($params['time_from']) : 0; $time_to = !empty($params['time_to']) ? fn_parse_date($params['time_to'], true) : TIME; // Current dates if ($period == 'D') { $time_from = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']); $time_to = TIME; } elseif ($period == 'W') { $wday = empty($today['wday']) ? "6" : ($today['wday'] == 1 ? "0" : $today['wday'] - 1); $wstart = getdate(strtotime("-{$wday} day")); $time_from = mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']); $time_to = TIME; } elseif ($period == 'M') { $time_from = mktime(0, 0, 0, $today['mon'], 1, $today['year']); $time_to = TIME; } elseif ($period == 'Y') { $time_from = mktime(0, 0, 0, 1, 1, $today['year']); $time_to = TIME; // Last dates } elseif ($period == 'LD') { $today = getdate(strtotime("-1 day")); $time_from = mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']); $time_to = mktime(23, 59, 59, $today['mon'], $today['mday'], $today['year']); } elseif ($period == 'LW') { $today = getdate(strtotime("-1 week")); $wday = empty($today['wday']) ? 6 : ($today['wday'] == 1 ? 0 : $today['wday'] - 1); $wstart = getdate(strtotime("-{$wday} day", mktime(0, 0, 0, $today['mon'], $today['mday'], $today['year']))); $time_from = mktime(0, 0, 0, $wstart['mon'], $wstart['mday'], $wstart['year']); $wend = getdate(strtotime("+6 day", $time_from)); $time_to = mktime(23, 59, 59, $wend['mon'], $wend['mday'], $wend['year']); } elseif ($period == 'LM') { $today = getdate(strtotime("-1 month")); $time_from = mktime(0, 0, 0, $today['mon'], 1, $today['year']); $time_to = mktime(23, 59, 59, $today['mon'], date('t', strtotime("-1 month")), $today['year']); } elseif ($period == 'LY') { $today = getdate(strtotime("-1 year")); $time_from = mktime(0, 0, 0, 1, 1, $today['year']); $time_to = mktime(23, 59, 59, 12, 31, $today['year']); // Last dates } elseif ($period == 'HH') { $today = getdate(strtotime("-23 hours")); $time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']); $time_to = TIME; } elseif ($period == 'HW') { $today = getdate(strtotime("-6 day")); $time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']); $time_to = TIME; } elseif ($period == 'HM') { $today = getdate(strtotime("-29 day")); $time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']); $time_to = TIME; } elseif ($period == 'HC') { $today = getdate(strtotime('-' . $params['last_days'] . ' day')); $time_from = mktime($today['hours'], $today['minutes'], $today['seconds'], $today['mon'], $today['mday'], $today['year']); $time_to = TIME; } Registry::get('view')->assign('time_from', $time_from); Registry::get('view')->assign('time_to', $time_to); return array($time_from, $time_to); }
function fn_banners_update_banner($data, $banner_id, $lang_code = DESCR_SL) { if (isset($data['timestamp'])) { $data['timestamp'] = fn_parse_date($data['timestamp']); } $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); if (!empty($banner_id)) { db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id); db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code); $banner_image_id = fn_get_banner_image_id($banner_id, $lang_code); $banner_image_exist = !empty($banner_image_id); $banner_is_multilang = Registry::get('addons.banners.banner_multilang') == 'Y'; $image_is_update = fn_banners_need_image_update(); if ($banner_is_multilang) { if ($banner_image_exist && $image_is_update) { fn_delete_image_pairs($banner_image_id, 'promo'); db_query("DELETE FROM ?:banner_images WHERE banner_id = ?i AND lang_code = ?s", $banner_id, $lang_code); $banner_image_exist = false; } } else { if (isset($data['url'])) { db_query("UPDATE ?:banner_descriptions SET url = ?s WHERE banner_id = ?i", $data['url'], $banner_id); } } if ($image_is_update && !$banner_image_exist) { $banner_image_id = db_query("INSERT INTO ?:banner_images (banner_id, lang_code) VALUE(?i, ?s)", $banner_id, $lang_code); } $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code); if (!$banner_is_multilang && !$banner_image_exist) { fn_banners_image_all_links($banner_id, $pair_data, $lang_code); } } else { $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data); foreach (Languages::getAll() as $data['lang_code'] => $v) { db_query("REPLACE INTO ?:banner_descriptions ?e", $data); } if (fn_banners_need_image_update()) { $data_banner_image = array('banner_id' => $banner_id, 'lang_code' => $lang_code); $banner_image_id = db_get_next_auto_increment_id('banner_images'); $pair_data = fn_attach_image_pairs('banners_main', 'promo', $banner_image_id, $lang_code); if (!empty($pair_data)) { db_query("INSERT INTO ?:banner_images ?e", $data_banner_image); fn_banners_image_all_links($banner_id, $pair_data, $lang_code); } } } return $banner_id; }
function fn_update_product($product_data, $product_id = 0, $lang_code = CART_LANGUAGE) { $_data = $product_data; if (!empty($product_data['timestamp'])) { $_data['timestamp'] = fn_parse_date($product_data['timestamp']); // Minimal data for product record } if (!empty($product_data['avail_since'])) { $_data['avail_since'] = fn_parse_date($product_data['avail_since']); } if (isset($product_data['tax_ids'])) { $_data['tax_ids'] = empty($product_data['tax_ids']) ? '' : fn_create_set($product_data['tax_ids']); } if (isset($product_data['localization'])) { $_data['localization'] = empty($product_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } if (isset($product_data['usergroup_ids'])) { $_data['usergroup_ids'] = empty($product_data['usergroup_ids']) ? '' : implode(',', $_data['usergroup_ids']); } if (Registry::get('settings.General.allow_negative_amount') == 'N' && isset($_data['amount'])) { $_data['amount'] = abs($_data['amount']); } // add new product if (empty($product_id)) { $create = true; // product title can't be empty if (empty($product_data['product'])) { return false; } $product_id = db_query("INSERT INTO ?:products ?e", $_data); if (empty($product_id)) { return false; } // // Adding same product descriptions for all cart languages // $_data = $product_data; $_data['product_id'] = $product_id; $_data['product'] = trim($_data['product'], " -"); foreach ((array) Registry::get('languages') as $_data['lang_code'] => $_v) { db_query("INSERT INTO ?:product_descriptions ?e", $_data); } // update product } else { if (isset($product_data['product']) && empty($product_data['product'])) { unset($product_data['product']); } db_query("UPDATE ?:products SET ?u WHERE product_id = ?i", $_data, $product_id); $_data = $product_data; if (!empty($_data['product'])) { $_data['product'] = trim($_data['product'], " -"); } db_query("UPDATE ?:product_descriptions SET ?u WHERE product_id = ?i AND lang_code = ?s", $_data, $product_id, $lang_code); } // Log product add/update fn_log_event('products', !empty($create) ? 'create' : 'update', array('product_id' => $product_id)); if (!empty($product_data['product_features'])) { $i_data = array('product_id' => $product_id, 'lang_code' => $lang_code); foreach ($product_data['product_features'] as $feature_id => $value) { // Check if feature is applicable for this product $id_paths = db_get_fields("SELECT ?:categories.id_path FROM ?:products_categories LEFT JOIN ?:categories ON ?:categories.category_id = ?:products_categories.category_id WHERE product_id = ?i", $product_id); $_params = array('category_ids' => array_unique(explode('/', implode('/', $id_paths))), 'feature_id' => $feature_id); list($_feature) = fn_get_product_features($_params); if (empty($_feature)) { $_feature = db_get_field("SELECT description FROM ?:product_features_descriptions WHERE feature_id = ?i AND lang_code = ?s", $feature_id, CART_LANGUAGE); $_product = db_get_field("SELECT product FROM ?:product_descriptions WHERE product_id = ?i AND lang_code = ?s", $product_id, CART_LANGUAGE); fn_set_notification('E', fn_get_lang_var('error'), str_replace(array('[feature_name]', '[product_name]'), array($_feature, $_product), fn_get_lang_var('product_feature_cannot_assigned'))); continue; } $i_data['feature_id'] = $feature_id; unset($i_data['value']); unset($i_data['variant_id']); unset($i_data['value_int']); $feature_type = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $feature_id); // Delete variants in current language if ($feature_type == 'T') { db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i AND lang_code = ?s", $feature_id, $product_id, $lang_code); } else { db_query("DELETE FROM ?:product_features_values WHERE feature_id = ?i AND product_id = ?i", $feature_id, $product_id); } if ($feature_type == 'D') { $i_data['value_int'] = fn_parse_date($value); } elseif ($feature_type == 'M') { if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) { $value = empty($value) ? array() : $value; $value[] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]); } if (!empty($value)) { foreach ($value as $variant_id) { foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) { // insert for all languages $i_data['variant_id'] = $variant_id; db_query("REPLACE INTO ?:product_features_values ?e", $i_data); } } } continue; } elseif (in_array($feature_type, array('S', 'N', 'E'))) { if (!empty($product_data['add_new_variant'][$feature_id]['variant'])) { $i_data['variant_id'] = fn_add_feature_variant($feature_id, $product_data['add_new_variant'][$feature_id]); } elseif (!empty($value) && $value != 'disable_select') { if ($feature_type == 'N') { $i_data['value_int'] = db_get_field("SELECT variant FROM ?:product_feature_variant_descriptions WHERE variant_id = ?i AND lang_code = ?s", $value, CART_LANGUAGE); } $i_data['variant_id'] = $value; } else { continue; } } else { if ($value == '') { continue; } if ($feature_type == 'O') { $i_data['value_int'] = $value; } else { $i_data['value'] = $value; } } if ($feature_type != 'T') { // feature values are common for all languages, except text (T) foreach (Registry::get('languages') as $i_data['lang_code'] => $_d) { db_query("REPLACE INTO ?:product_features_values ?e", $i_data); } } else { // for text feature, update current language only $i_data['lang_code'] = $lang_code; db_query("INSERT INTO ?:product_features_values ?e", $i_data); } } } // Update product prices if (isset($product_data['price'])) { if (!isset($product_data['prices'])) { $product_data['prices'] = array(); $skip_price_delete = true; } $_price = array('price' => abs($product_data['price']), 'lower_limit' => 1); array_unshift($product_data['prices'], $_price); } if (!empty($product_data['prices'])) { if (empty($skip_price_delete)) { db_query("DELETE FROM ?:product_prices WHERE product_id = ?i", $product_id); } foreach ($product_data['prices'] as $v) { if (!empty($v['lower_limit'])) { $v['product_id'] = $product_id; db_query("REPLACE INTO ?:product_prices ?e", $v); } } } if (!empty($product_data['popularity'])) { $_data = array('product_id' => $product_id, 'total' => intval($product_data['popularity'])); db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE total = ?i", $_data, $product_data['popularity']); } fn_set_hook('update_product', $product_data, $product_id, $lang_code); return $product_id; }
function fn_store_profile_fields($user_data, $object_id, $object_type) { // Delete existing fields if ($object_type == 'UP') { db_query("DELETE FROM ?:profile_fields_data WHERE (object_id = ?i AND object_type = ?s) OR (object_id = ?i AND object_type = ?s)", $object_id['U'], 'U', $object_id['P'], 'P'); } else { db_query("DELETE FROM ?:profile_fields_data WHERE object_id = ?i AND object_type = ?s", $object_id, $object_type); } if (!empty($user_data['fields'])) { $fields_info = db_get_hash_array("SELECT field_id, field_type, section FROM ?:profile_fields WHERE field_id IN (?n)", 'field_id', array_keys($user_data['fields'])); $_data = array(); foreach ($user_data['fields'] as $field_id => $value) { if ($object_type == 'UP') { $_data['object_type'] = $fields_info[$field_id]['section'] == 'C' ? 'U' : 'P'; $_data['object_id'] = $fields_info[$field_id]['section'] == 'C' ? $object_id['U'] : $object_id['P']; } else { $_data['object_type'] = $object_type; $_data['object_id'] = $object_id; } $_data['field_id'] = $field_id; $_data['value'] = $fields_info[$field_id]['field_type'] == 'D' ? fn_parse_date($value) : $value; db_query("REPLACE INTO ?:profile_fields_data ?e", $_data); } } return true; }
function fn_send_form($page_id, $form_values) { $result = false; if (!empty($form_values)) { $page_data = fn_get_page_data($page_id); if (!empty($page_data['form']['elements'])) { $result = true; $attachments = array(); $fb_files = fn_filter_uploaded_data('fb_files'); if (!empty($fb_files)) { foreach ($fb_files as $k => $v) { $attachments[$v['name']] = $v['path']; $form_values[$k] = $v['name']; } } $max_length = 0; $sender = ''; foreach ($page_data['form']['elements'] as $k => $v) { if (($l = strlen($v['description'])) > $max_length) { $max_length = $l; } // Check if sender email exists if ($v['element_type'] == FORM_EMAIL) { $sender = $form_values[$k]; } if ($v['element_type'] == FORM_DATE) { $form_values[$k] = fn_parse_date($form_values[$k]); } if ($v['element_type'] == FORM_REFERER) { $form_values[$k] = $_SESSION['auth']['referer']; } if ($v['element_type'] == FORM_IP_ADDRESS) { $ip = fn_get_ip(); $form_values[$k] = $ip['host']; } } $max_length += 2; if ($result == true) { $from = 'default_company_support_department'; $is_html = true; fn_set_hook('send_form', $page_data, $form_values, $result, $from, $sender, $attachments, $is_html); if ($result == true) { Mailer::sendMail(array('to' => $page_data['form']['general'][FORM_RECIPIENT], 'from' => $from, 'reply_to' => $sender, 'data' => array('max_length' => $max_length, 'elements' => $page_data['form']['elements'], 'form_title' => $page_data['page'], 'form_values' => $form_values), 'attachments' => $attachments, 'tpl' => 'addons/form_builder/form.tpl', 'is_html' => $is_html), 'A'); } } } } return $result; }
function fn_send_form($page_id, $form_values) { if (!empty($form_values)) { $page_data = fn_get_page_data($page_id); if (empty($page_data['form']['elements'])) { return false; } $attachments = array(); $fb_files = fn_filter_uploaded_data('fb_files'); if (!empty($fb_files)) { foreach ($fb_files as $k => $v) { $attachments[$v['name']] = $v['path']; $form_values[$k] = $v['name']; } } $max_length = 0; $sender = ''; foreach ($page_data['form']['elements'] as $k => $v) { if (($l = strlen($v['description'])) > $max_length) { $max_length = $l; } if ($v['element_type'] == FORM_EMAIL_CONFIRM) { if (!is_array($form_values[$k]) || $form_values[$k][0] != $form_values[$k][1] || empty($form_values[$k][0]) || $form_values[$k][1]) { return false; } $form_values[$k] = $form_values[$k][0]; } // Check if sender email exists if ($v['element_type'] == FORM_EMAIL || $v['element_type'] == FORM_EMAIL_CONFIRM) { $sender = $form_values[$k]; } if ($v['element_type'] == FORM_DATE) { $form_values[$k] = fn_parse_date($form_values[$k]); } if ($v['element_type'] == FORM_REFERER) { $form_values[$k] = $_SESSION['auth']['referer']; } if ($v['element_type'] == FORM_IP_ADDRESS) { $ip = fn_get_ip(); $form_values[$k] = $ip['host']; } } $max_length += 2; fn_set_hook('send_form', $page_data, $form_values); Registry::get('view_mail')->assign('max_length', $max_length); Registry::get('view_mail')->assign('elements', $page_data['form']['elements']); Registry::get('view_mail')->assign('form_title', $page_data['page']); Registry::get('view_mail')->assign('form_values', $form_values); fn_send_mail($page_data['form']['general'][FORM_RECIPIENT], Registry::get('settings.Company.company_support_department'), 'addons/form_builder/form_subject.tpl', 'addons/form_builder/form_body.tpl', $attachments, CART_LANGUAGE, $sender); } return false; }
function fn_se_prepare_request_params($params) { $restrict_by = $query_by = $union = array(); // // Hide products with empty categories and wrong usergroup categories // $restrict_by['empty_categories'] = 'N'; $restrict_by['category_usergroup_ids'] = join('|', $_SESSION['auth']['usergroup_ids']); // // Filters // $filter_fields = fn_get_product_filter_fields(); $advanced_variant_ids = $simple_variant_ids = $av_ids = $ranges_ids = $fields_ids = $slider_vals = array(); if (!empty($params['features_hash'])) { list($av_ids, $ranges_ids, $fields_ids, $slider_vals) = fn_parse_features_hash($params['features_hash']); } if (!empty($params['multiple_variants']) && !empty($params['advanced_filter'])) { $simple_variant_ids = $params['multiple_variants']; } if (!empty($av_ids)) { $features_variants_ids = db_get_hash_single_array("SELECT feature_id, GROUP_CONCAT(variant_id) as variant_ids FROM ?:product_feature_variants WHERE variant_id IN (?n) GROUP BY feature_id", array('feature_id', 'variant_ids'), $av_ids); foreach ($features_variants_ids as $feature_id => $variant_ids) { $restrict_by['feature_' . $feature_id] = str_replace(',', '|', $variant_ids); } } if (!empty($simple_variant_ids)) { $features_variants_ids = db_get_hash_single_array("SELECT feature_id, GROUP_CONCAT(variant_id) as variant_ids FROM ?:product_feature_variants WHERE variant_id IN (?n) GROUP BY feature_id", array('feature_id', 'variant_ids'), $simple_variant_ids); foreach ($features_variants_ids as $feature_id => $variant_ids) { $restrict_by['feature_' . $feature_id] = $variant_ids; } } // Feature ranges if (!empty($params['custom_range'])) { foreach ($params['custom_range'] as $feature_id => $v) { $is_from = isset($v['from']) && fn_string_not_empty($v['from']); $is_to = isset($v['to']) && fn_string_not_empty($v['to']); if ($is_from || $is_to) { if (!empty($v['type'])) { if ($v['type'] == 'D') { $v['from'] = fn_parse_date($v['from']); $v['to'] = fn_parse_date($v['to']); } } $restrict_by['feature_' . $feature_id] = ($is_from ? $v['from'] : '') . ',' . ($is_to ? $v['to'] : ''); } } } // Product field ranges if (!empty($params['field_range'])) { foreach ($params['field_range'] as $field_type => $v) { $structure = $filter_fields[$field_type]; if (!empty($structure) && (!empty($v['from']) || !empty($v['to']))) { if ($field_type == 'P') { // price $v['cur'] = !empty($v['cur']) ? $v['cur'] : CART_SECONDARY_CURRENCY; if (empty($v['orig_cur'])) { // saving the first user-entered values // will be always search by it $v['orig_from'] = $v['from']; $v['orig_to'] = $v['to']; $v['orig_cur'] = $v['cur']; $params['field_range'][$field_type] = $v; } if ($v['orig_cur'] != CART_PRIMARY_CURRENCY) { // calc price in primary currency $cur_prim_coef = Registry::get('currencies.' . $v['orig_cur'] . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $search_from = round($v['orig_from'] * floatval($cur_prim_coef), $decimals); $search_to = round($v['orig_to'] * floatval($cur_prim_coef), $decimals); } else { $search_from = $v['orig_from']; $search_to = $v['orig_to']; } // if user switch the currency, calc new values for displaying in filter if ($v['cur'] != CART_SECONDARY_CURRENCY) { if (CART_SECONDARY_CURRENCY == $v['orig_cur']) { $v['from'] = $v['orig_from']; $v['to'] = $v['orig_to']; } else { $prev_coef = Registry::get('currencies.' . $v['cur'] . '.coefficient'); $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $v['from'] = floor(floatval($v['from']) * floatval($prev_coef) / floatval($cur_coef)); $v['to'] = ceil(floatval($v['to']) * floatval($prev_coef) / floatval($cur_coef)); } $v['cur'] = CART_SECONDARY_CURRENCY; $params['field_range'][$field_type] = $v; } } $params["{$structure['db_field']}_from"] = trim(isset($search_from) ? $search_from : $v['from']); $params["{$structure['db_field']}_to"] = trim(isset($search_to) ? $search_to : $v['to']); } } } foreach ($ranges_ids as $range_id) { $range = db_get_row("SELECT * FROM ?:product_filter_ranges WHERE range_id = ?i", $range_id); if (!empty($range)) { $feature = 'feature_' . $range['feature_id']; $restrict_by[$feature] = empty($restrict_by[$feature]) ? "{$range['from']},{$range['to']}" : $restrict_by[$feature] . "|{$range['from']},{$range['to']}"; } } foreach ($fields_ids as $range_id => $field_type) { $feature = $filter_fields[$field_type]['db_field']; if ($field_type == 'S') { $restrict_by[$feature] = empty($restrict_by[$feature]) ? $range_id : $restrict_by[$feature] . "|{$range_id}"; } if ($field_type == 'F') { $restrict_by[$feature] = $range_id == '1' ? 'Y' : 'N'; } } // Slider ranges $slider_vals = empty($params['slider_vals']) ? $slider_vals : $params['slider_vals']; if (!empty($slider_vals)) { foreach ($slider_vals as $field_type => $vals) { if (!empty($filter_fields[$field_type])) { if ($field_type == 'P') { $currency = !empty($vals[2]) ? $vals[2] : CART_PRIMARY_CURRENCY; if ($currency != CART_PRIMARY_CURRENCY) { $coef = Registry::get('currencies.' . $currency . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $vals[0] = round(floatval($vals[0]) * floatval($coef), $decimals); $vals[1] = round(floatval($vals[1]) * floatval($coef), $decimals); } } $structure = $filter_fields[$field_type]; $params["{$structure['db_field']}_from"] = $vals[0]; $params["{$structure['db_field']}_to"] = $vals[1]; } } } // Checkbox features if (!empty($params['ch_filters']) && !fn_is_empty($params['ch_filters'])) { foreach ($params['ch_filters'] as $key => $value) { if (is_string($key) && !empty($filter_fields[$key])) { $restrict_by[$filter_fields[$key]['db_field']] = $value == 'A' ? 'Y|N' : $value; } else { if (!empty($value)) { $feature_id = $key; $restrict_by['feature_' . $feature_id] = $value == 'A' ? 'Y|N' : $value; } } } } // // Visibility // if (AREA == 'C') { $restrict_by['status'] = 'A'; if (!fn_allowed_for('ULTIMATE:FREE')) { $restrict_by['usergroup_ids'] = join('|', $_SESSION['auth']['usergroup_ids']); } if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && AREA == 'C') { $restrict_by['amount'] = '1,'; } // // Company_id // if (!fn_allowed_for('ULTIMATE') && !isset($restrict_by['company_id'])) { if (Registry::get('runtime.company_id') && isset($params['company_id'])) { $restrict_by['company_id'] = Registry::get('runtime.company_id'); } if (isset($params['company_id']) && $params['company_id'] != '') { $restrict_by['company_id'] = $params['company_id']; } } } // // Filters coditions for facets request // if (!empty($params['filters_category_id'])) { $c_condition = ''; if (AREA == 'C') { $_c_statuses = array('A', 'H'); // Show enabled categories $cids = db_get_fields("SELECT a.category_id FROM ?:categories as a WHERE a.category_id IN (?n) AND a.status IN (?a)", $params['filters_category_id'], $_c_statuses); $c_condition = db_quote('AND a.status IN (?a) AND (' . fn_find_array_in_set($_SESSION['auth']['usergroup_ids'], 'a.usergroup_ids', true) . ')', $_c_statuses); } if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') { $sub_categories_ids = db_get_fields("SELECT a.category_id FROM ?:categories as a LEFT JOIN ?:categories as b ON b.category_id IN (?n) WHERE a.id_path LIKE CONCAT(b.id_path, '/%') ?p", $params['filters_category_id'], $c_condition); $sub_categories_ids = fn_array_merge($cids, $sub_categories_ids, false); $restrict_by['category_id'] = join('|', $sub_categories_ids); } else { $restrict_by['category_id'] = join('|', $cids); } } // // Timestamp // if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $restrict_by['timestamp'] = "{$params['time_from']},{$params['time_to']}"; } // // Price Union // if (!fn_allowed_for('"ULTIMATE:FREE"')) { if (count($_SESSION['auth']['usergroup_ids']) > 1) { foreach ($_SESSION['auth']['usergroup_ids'] as $usergroup_id) { $_prices[] = 'price_' . $usergroup_id; } $union['price']['min'] = join('|', $_prices); } } // // Price // $is_price_from = isset($params['price_from']) && fn_is_numeric($params['price_from']); $is_price_to = isset($params['price_to']) && fn_is_numeric($params['price_to']); if ($is_price_from || $is_price_to) { $restrict_by['price'] = ($is_price_from ? $params['price_from'] : '') . ',' . ($is_price_to ? $params['price_to'] : ''); } // // Weight // $is_weight_from = isset($params['weight_from']) && fn_is_numeric($params['weight_from']); $is_weight_to = isset($params['weight_to']) && fn_is_numeric($params['weight_to']); if ($is_weight_from || $is_weight_to) { $restrict_by['weight'] = ($is_weight_from ? $params['weight_from'] : '') . ',' . ($is_weight_to ? $params['weight_to'] : ''); } // // Amount // $is_amount_from = isset($params['amount_from']) && fn_is_numeric($params['amount_from']); $is_amount_to = isset($params['amount_to']) && fn_is_numeric($params['amount_to']); if ($is_amount_from || $is_amount_to) { $restrict_by['amount'] = ($is_amount_from ? $params['amount_from'] : '') . ',' . ($is_amount_to ? $params['amount_to'] : ''); } // // Popularity // $is_popularity_from = isset($params['popularity_from']) && fn_is_numeric($params['popularity_from']); $is_popularity_to = isset($params['popularity_to']) && fn_is_numeric($params['popularity_to']); if ($is_popularity_from || $is_popularity_to) { $restrict_by['popularity'] = ($is_popularity_from ? $params['popularity_from'] : '') . ',' . ($is_popularity_to ? $params['popularity_to'] : ''); } if (!empty($params['free_shipping'])) { $restrict_by['free_shipping'] = $params['free_shipping']; } if (isset($params['pcode']) && fn_string_not_empty($params['pcode'])) { $query_by['product_code'] = trim($params['pcode']); } return array($restrict_by, $query_by, $union); }
} elseif ($mode == 'm_delete') { $params = $_REQUEST['courier_ids']; if (!empty($params)) { foreach ($params as $c) { $c = explode('||', $c); $id = $c[0]; $owner_id = $c[1]; fn_spsr_delete_courier($id, $owner_id); } } $suffix = ".manage"; } elseif ($mode == 'update') { $params = $_REQUEST['spsr_courier']; if (!empty($params)) { RusSpsr::WALogin(); $date = date('Y-m-d', fn_parse_date($params['necesserydate'])) . 'T00:00:00.000'; $service = $params['service']; $placescount = 1; $address = explode('||', $params['sbor_addr']); $sboraddr_id = $address[0]; $sboraddr_owner_id = $address[1]; $fio = $address[2]; $city = $address[3]; $receiver_city = RusSpsr::WAGetCities(array('city' => $city)); $data = array('date' => $date, 'time' => $params['necesserytime'], 'receiver_city_id' => $receiver_city['City_ID'], 'receiver_city_owner_id' => $receiver_city['City_owner_ID'], 'mode' => $service, 'fio' => $fio, 'sboraddr_id' => $sboraddr_id, 'sboraddr_owner_id' => $sboraddr_owner_id, 'order_type' => 0, 'placescount' => $params['placescount'], 'weight' => $params['weight'], 'length' => $params['length'], 'width' => $params['width'], 'depth' => $params['depth'], 'description' => $params['description']); $order_id = RusSpsr::WACreateOrder($data); if (!empty($order_id)) { fn_set_notification('N', __('notice'), __('shippings.spsr.order_add') . ' : ' . $order_id); } else { fn_set_notification('E', __('notice'), __('shippings.spsr.not_order_add') . ' : ' . RusSpsr::$last_error); }
function fn_update_event($event_data, $event_id = 0) { $event_data['start_date'] = fn_parse_date($event_data['start_date']); $event_data['end_date'] = fn_parse_date($event_data['end_date'], true); if ($event_data['start_date'] > TIME) { $event_data['status'] = 'A'; } elseif ($event_data['end_date'] < TIME) { $event_data['status'] = 'F'; } else { $event_data['status'] = 'P'; } $_data = $event_data; $_data['user_id'] = $_SESSION['auth']['user_id']; if (empty($event_id)) { $event_id = db_query("INSERT INTO ?:giftreg_events ?e", $_data); } else { db_query("UPDATE ?:giftreg_events SET ?u WHERE event_id = ?i", $_data, $event_id); } fn_update_event_subscribers($event_data, $event_id); // Generate access key for editing this event if (AREA == 'C') { $access_key = fn_event_generate_ekey($event_id, true); } // Generate access key for event subscribers (for private event) if ($_data['type'] == 'U') { fn_event_generate_ekey($event_id); } if (!empty($event_data['fields'])) { $_data = array('event_id' => $event_id); db_query("DELETE FROM ?:giftreg_event_fields WHERE event_id = ?i", $event_id); foreach ($event_data['fields'] as $field_id => $value) { if (substr_count($value, '/') == 2) { // FIXME: it's date field $value = fn_parse_date($value); } $_data['field_id'] = $field_id; $_data['value'] = $value; db_query("INSERT INTO ?:giftreg_event_fields ?e", $_data); } } fn_set_hook('update_event', $event_data, $event_id); return array($event_id, empty($access_key) ? '' : $access_key); }
<?php /*************************************************************************** * * * (c) 2004 Vladimir V. Kalynyak, Alexey V. Vinokurov, Ilya M. Shalnev * * * * This is commercial software, only users who have purchased a valid * * license and accept to the terms of the License Agreement can install * * and use this program. * * * **************************************************************************** * PLEASE READ THE FULL TEXT OF THE SOFTWARE LICENSE AGREEMENT IN THE * * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE. * ****************************************************************************/ if (!defined('BOOTSTRAP')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (($mode == 'customer_info' || $mode == 'add_profile') && !empty($_REQUEST['user_data']['birthday'])) { $_REQUEST['user_data']['birthday'] = fn_parse_date($_REQUEST['user_data']['birthday']); } }
function fn_update_promotion($data, $promotion_id, $lang_code = DESCR_SL) { if (!empty($data['conditions']['conditions'])) { $data['conditions_hash'] = fn_promotion_serialize($data['conditions']['conditions']); $data['users_conditions_hash'] = fn_promotion_serialize_users_conditions($data['conditions']['conditions']); } else { $data['conditions_hash'] = $data['users_conditions_hash'] = ''; } $data['conditions'] = empty($data['conditions']) ? array() : $data['conditions']; $data['bonuses'] = empty($data['bonuses']) ? array() : $data['bonuses']; fn_promotions_check_group_conditions($data['conditions']); if ($data['bonuses']) { foreach ($data['bonuses'] as $k => $v) { if (empty($v['bonus'])) { unset($data['bonuses'][$k]); } } } $data['conditions'] = serialize($data['conditions']); $data['bonuses'] = serialize($data['bonuses']); $from_date = $data['from_date']; $to_date = $data['to_date']; $data['from_date'] = !empty($from_date) ? fn_parse_date($from_date) : 0; $data['to_date'] = !empty($to_date) ? fn_parse_date($to_date, true) : 0; if (!empty($data['to_date']) && $data['to_date'] < $data['from_date']) { // protection from incorrect date range (special for isergi :)) $data['from_date'] = fn_parse_date($to_date); $data['to_date'] = fn_parse_date($from_date, true); } if (!empty($promotion_id)) { db_query("UPDATE ?:promotions SET ?u WHERE promotion_id = ?i", $data, $promotion_id); db_query('UPDATE ?:promotion_descriptions SET ?u WHERE promotion_id = ?i AND lang_code = ?s', $data, $promotion_id, $lang_code); } else { $promotion_id = $data['promotion_id'] = db_query("REPLACE INTO ?:promotions ?e", $data); foreach (fn_get_translation_languages() as $data['lang_code'] => $_v) { db_query("REPLACE INTO ?:promotion_descriptions ?e", $data); } } return $promotion_id; }
public static function WAGetOrders($from, $to) { $sid = self::$sid; $url = self::$url; $extra = self::$extra; $icn = self::$icn; $login = self::$login; $from = date('Y-m-d', fn_parse_date($from)) . 'T00:00:00.000'; $to = date('Y-m-d', fn_parse_date($to)) . 'T00:00:00.000'; $xml = <<<EOT <root xmlns="http://spsr.ru/webapi/DataEditManagment/GetOrders/1.0" > <p:Params Name="WAGetOrders" Ver="1.0" xmlns:p="http://spsr.ru/webapi/WA/1.0" /> <Login SID="{$sid}"/> <GetOrders ICN="{$icn}" Login="******" FromDT="{$from}" ToDT="{$to}" /> </root> EOT; $response = Http::post($url, $xml, $extra); $xml = simplexml_load_string($response); $return = false; $status_code = (string) $xml->Result['RC']; if ($status_code != 0) { self::$last_error = !empty(self::$_error_descriptions[$status_code]) ? self::$_error_descriptions[$status_code] : 'Ошибка получения города'; } else { if (isset($xml->Orders->OrderInfo)) { $orders = array(); foreach ($xml->Orders->OrderInfo as $order) { $key = (string) $order['OrderNum']; $orders[$key] = array('OrderNumber' => (string) $order['OrderNum'], 'OrderState' => (string) $order['OrderState'], 'DateOfCreate' => (string) $order['CreateDT'], 'PlanningDT_From' => (string) $order['CourierArrivalDT'], 'PlanningDT_To' => (string) $order['PlanningDT_to'], 'FIO' => (string) $order['ContactFIO'], 'OperatorFIO' => (string) $order['OperatorFIO'], 'ContactPhone' => (string) $order['ContactPhone'], 'Address' => (string) $order['Address']); } $return = $orders; } } return $return; }
function fn_companies_add_payout($payment) { $_data = array('company_id' => $payment['vendor'], 'payout_date' => TIME, 'start_date' => fn_parse_date($payment['start_date']), 'end_date' => fn_parse_date($payment['end_date']), 'payout_amount' => $payment['amount'] * -1, 'payment_method' => $payment['payment_method'], 'comments' => $payment['comments']); if ($_data['start_date'] > $_data['end_date']) { $_data['start_date'] = $_data['end_date']; } db_query('INSERT INTO ?:vendor_payouts ?e', $_data); if (isset($payment['notify_user']) && $payment['notify_user'] == 'Y') { Mailer::sendMail(array('to' => 'company_support_department', 'from' => 'default_company_support_department', 'data' => array('payment' => $payment), 'tpl' => 'companies/payment_notification.tpl', 'company_id' => $payment['vendor']), 'A', fn_get_company_language($payment['vendor'])); } }
function fn_update_banner($data, $banner_id, $lang_code = DESCR_SL) { if (isset($data['timestamp'])) { $data['timestamp'] = fn_parse_date($data['timestamp']); } $data['localization'] = empty($data['localization']) ? '' : fn_implode_localizations($data['localization']); if (!empty($banner_id)) { db_query("UPDATE ?:banners SET ?u WHERE banner_id = ?i", $data, $banner_id); db_query("UPDATE ?:banner_descriptions SET ?u WHERE banner_id = ?i AND lang_code = ?s", $data, $banner_id, $lang_code); } else { $banner_id = $data['banner_id'] = db_query("REPLACE INTO ?:banners ?e", $data); foreach ((array) Registry::get('languages') as $data['lang_code'] => $v) { db_query("REPLACE INTO ?:banner_descriptions ?e", $data); } } fn_attach_image_pairs('banners_main', 'banner', $banner_id, $lang_code); return $banner_id; }
'data' => serialize($shippings), 'order_id' => $_REQUEST['order_id'], 'type' => 'L', ); db_query('REPLACE INTO ?:order_data ?e', $_data); }*/ $edp_data = array(); $order_info = fn_get_order_info($_REQUEST['order_id'], false, true, false, true); if (!empty($_REQUEST['activate_files'])) { $edp_data = fn_generate_ekeys_for_edp(array(), $order_info, $_REQUEST['activate_files']); } fn_order_notification($order_info, $edp_data, fn_get_notification_rules($_REQUEST)); if (!empty($_REQUEST['prolongate_data']) && is_array($_REQUEST['prolongate_data'])) { foreach ($_REQUEST['prolongate_data'] as $ekey => $v) { $newttl = fn_parse_date($v, true); db_query('UPDATE ?:product_file_ekeys SET ?u WHERE ekey = ?s', array('ttl' => $newttl), $ekey); } } // Update file downloads section if (!empty($_REQUEST['edp_downloads'])) { foreach ($_REQUEST['edp_downloads'] as $ekey => $v) { foreach ($v as $file_id => $downloads) { $max_downloads = db_get_field("SELECT max_downloads FROM ?:product_files WHERE file_id = ?i", $file_id); if (!empty($max_downloads)) { db_query('UPDATE ?:product_file_ekeys SET ?u WHERE ekey = ?s', array('downloads' => $max_downloads - $downloads), $ekey); } } } } $suffix = ".details?order_id={$_REQUEST['order_id']}";
function fn_exim_1c_update_category($category_data, $category_id, $lang_code) { $_data = $category_data; unset($_data['parent_id']); $_data['timestamp'] = fn_parse_date($category_data['timestamp']); if (empty($category_id)) { $create = true; $category_id = db_query("INSERT INTO ?:categories ?e", $_data); $_data['category_id'] = $category_id; foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:category_descriptions ?e", $_data); } $category_data['parent_id'] = !empty($category_data['parent_id']) ? $category_data['parent_id'] : 0; } else { db_query("UPDATE ?:categories SET ?u WHERE category_id = ?i", $_data, $category_id); db_query("UPDATE ?:category_descriptions SET ?u WHERE category_id = ?i AND lang_code = ?s", $_data, $category_id, $lang_code); } if ($category_id) { if (isset($category_data['parent_id'])) { fn_change_category_parent($category_id, intval($category_data['parent_id'])); } } return $category_id; }
function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAGE) { /** * Changes params for selecting products * * @param array $params Product search params * @param int $items_per_page Items per page * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) */ fn_set_hook('get_products_pre', $params, $items_per_page, $lang_code); // Init filter $params = LastView::instance()->update('products', $params); // Set default values to input params $default_params = array('area' => AREA, 'extend' => array('product_name', 'prices', 'categories'), 'custom_extend' => array(), 'pname' => '', 'pshort' => '', 'pfull' => '', 'pkeywords' => '', 'feature' => array(), 'type' => 'simple', 'page' => 1, 'action' => '', 'variants' => array(), 'ranges' => array(), 'custom_range' => array(), 'field_range' => array(), 'features_hash' => '', 'limit' => 0, 'bid' => 0, 'match' => '', 'tracking' => array(), 'get_frontend_urls' => false, 'items_per_page' => $items_per_page); if (empty($params['custom_extend'])) { $params['extend'] = !empty($params['extend']) ? array_merge($default_params['extend'], $params['extend']) : $default_params['extend']; } else { $params['extend'] = $params['custom_extend']; } $params = array_merge($default_params, $params); if ((empty($params['pname']) || $params['pname'] != 'Y') && (empty($params['pshort']) || $params['pshort'] != 'Y') && (empty($params['pfull']) || $params['pfull'] != 'Y') && (empty($params['pkeywords']) || $params['pkeywords'] != 'Y') && (empty($params['feature']) || $params['feature'] != 'Y') && !empty($params['q'])) { $params['pname'] = 'Y'; } $auth =& $_SESSION['auth']; // Define fields that should be retrieved if (empty($params['only_short_fields'])) { $fields = array('products.*'); } else { $fields = array('product_id' => 'products.product_id', 'product_code' => 'products.product_code', 'product_type' => 'products.product_type', 'status' => 'products.status', 'company_id' => 'products.company_id', 'list_price' => 'products.list_price', 'amount' => 'products.amount', 'weight' => 'products.weight', 'tracking' => 'products.tracking', 'is_edp' => 'products.is_edp', 'return_period' => 'products.return_period'); } //AS started_price $fields['subtitle'] = 'descr1.subtitle'; $fields['top_title'] = 'descr1.top_title'; $fields['started_price'] = 'prices.price AS started_price'; // Define sort fields $sortings = array('code' => 'products.product_code', 'status' => 'products.status', 'product' => 'product', 'position' => 'products_categories.position', 'price' => 'price', 'list_price' => 'products.list_price', 'weight' => 'products.weight', 'amount' => 'products.amount', 'timestamp' => 'products.timestamp', 'updated_timestamp' => 'products.updated_timestamp', 'popularity' => 'popularity.total', 'company' => 'company_name', 'null' => 'NULL'); if (!empty($params['get_subscribers'])) { $sortings['num_subscr'] = 'num_subscr'; $fields['num_subscr'] = 'COUNT(DISTINCT product_subscriptions.subscription_id) as num_subscr'; } if (!empty($params['order_ids'])) { $sortings['p_qty'] = 'purchased_qty'; $sortings['p_subtotal'] = 'purchased_subtotal'; $fields['purchased_qty'] = "SUM(?:order_details.amount) as purchased_qty"; $fields['purchased_subtotal'] = "SUM(?:order_details.price * ?:order_details.amount) as purchased_subtotal"; } if (isset($params['compact']) && $params['compact'] == 'Y') { $union_condition = ' OR '; } else { $union_condition = ' AND '; } $join = $condition = $u_condition = $inventory_condition = ''; $having = array(); $extraCondition = array(); // Search string condition for SQL query if (isset($params['q']) && fn_string_not_empty($params['q'])) { $params['q'] = trim($params['q']); if ($params['match'] == 'any') { $pieces = fn_explode(' ', $params['q']); $search_type = ' OR '; } elseif ($params['match'] == 'all') { $pieces = fn_explode(' ', $params['q']); $search_type = ' AND '; } else { $pieces = array($params['q']); $search_type = ''; } $_condition = array(); foreach ($pieces as $piece) { if (strlen($piece) == 0) { continue; } $tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%'); // check search words if ($params['pname'] == 'Y') { $tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%'); } if ($params['pshort'] == 'Y') { $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . $piece . '%'); $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%'); } if ($params['pfull'] == 'Y') { $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . $piece . '%'); $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%'); } if ($params['pkeywords'] == 'Y') { $tmp .= db_quote(" OR (descr1.meta_keywords LIKE ?l OR descr1.meta_description LIKE ?l)", '%' . $piece . '%', '%' . $piece . '%'); } if (!empty($params['feature']) && $params['action'] != 'feature_search') { $tmp .= db_quote(" OR ?:product_features_values.value LIKE ?l", '%' . $piece . '%'); } fn_set_hook('additional_fields_in_search', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $tmp, $piece, $having); $_condition[] = '(' . $tmp . ')'; } $_cond = implode($search_type, $_condition); if (!empty($_condition)) { $condition .= ' AND (' . $_cond . ') '; } if (!empty($params['feature']) && $params['action'] != 'feature_search') { $join .= " LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id"; $condition .= db_quote(" AND (?:product_features_values.feature_id IN (?n) OR ?:product_features_values.feature_id IS NULL)", array_values($params['feature'])); } //if perform search we also get additional fields if ($params['pname'] == 'Y') { $params['extend'][] = 'product_name'; } if ($params['pshort'] == 'Y' || $params['pfull'] == 'Y' || $params['pkeywords'] == 'Y') { $params['extend'][] = 'description'; } unset($_condition); } // // [Advanced and feature filters] // if (!empty($params['apply_limit']) && $params['apply_limit'] && !empty($params['pid'])) { $pids = array(); foreach ($params['pid'] as $pid) { if ($pid != $params['exclude_pid']) { if (count($pids) == $params['limit']) { break; } else { $pids[] = $pid; } } } $params['pid'] = $pids; } if (!empty($params['features_hash']) || !fn_is_empty($params['variants']) || !empty($params['feature_code'])) { $join .= db_quote(" LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id AND ?:product_features_values.lang_code = ?s", $lang_code); } if (!empty($params['variants'])) { $params['features_hash'] .= implode('.', $params['variants']); } // Feature code if (!empty($params['feature_code'])) { $join .= db_quote(" LEFT JOIN ?:product_features ON ?:product_features_values.feature_id = ?:product_features.feature_id"); $condition .= db_quote(" AND ?:product_features.feature_code = ?s", $params['feature_code']); } $advanced_variant_ids = $simple_variant_ids = $ranges_ids = $fields_ids = $fields_ids_revert = $slider_vals = array(); if (!empty($params['features_hash'])) { list($av_ids, $ranges_ids, $fields_ids, $slider_vals, $fields_ids_revert) = fn_parse_features_hash($params['features_hash']); $advanced_variant_ids = db_get_hash_multi_array("SELECT feature_id, variant_id FROM ?:product_feature_variants WHERE variant_id IN (?n)", array('feature_id', 'variant_id'), $av_ids); } if (!empty($params['multiple_variants'])) { $simple_variant_ids = $params['multiple_variants']; } if (!empty($advanced_variant_ids)) { $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS advanced_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_advanced ON pfv_advanced.product_id = products.product_id", $lang_code); $where_and_conditions = array(); foreach ($advanced_variant_ids as $k => $variant_ids) { $where_or_conditions = array(); foreach ($variant_ids as $variant_id => $v) { $where_or_conditions[] = db_quote(" FIND_IN_SET('?i', advanced_variants)", $variant_id); } $where_and_conditions[] = '(' . implode(' OR ', $where_or_conditions) . ')'; } $condition .= ' AND ' . implode(' AND ', $where_and_conditions); } if (!empty($simple_variant_ids)) { $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS simple_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_simple ON pfv_simple.product_id = products.product_id", $lang_code); $where_conditions = array(); foreach ($simple_variant_ids as $k => $variant_id) { $where_conditions[] = db_quote(" FIND_IN_SET('?i', simple_variants)", $variant_id); } $condition .= ' AND ' . implode(' AND ', $where_conditions); } // // Ranges from text inputs // // Feature ranges if (!empty($params['custom_range'])) { foreach ($params['custom_range'] as $k => $v) { $k = intval($k); if (isset($v['from']) && fn_string_not_empty($v['from']) || isset($v['to']) && fn_string_not_empty($v['to'])) { if (!empty($v['type'])) { if ($v['type'] == 'D') { $v['from'] = fn_parse_date($v['from']); $v['to'] = fn_parse_date($v['to']); } } $join .= db_quote(" LEFT JOIN ?:product_features_values as custom_range_{$k} ON custom_range_{$k}.product_id = products.product_id AND custom_range_{$k}.lang_code = ?s", $lang_code); if (fn_string_not_empty($v['from']) && fn_string_not_empty($v['to'])) { $condition .= db_quote(" AND (custom_range_{$k}.value_int >= ?i AND custom_range_{$k}.value_int <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i) ", $v['from'], $v['to'], $k); } else { $condition .= " AND custom_range_{$k}.value_int" . (fn_string_not_empty($v['from']) ? db_quote(' >= ?i', $v['from']) : db_quote(" <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i ", $v['to'], $k)); } } } } // Product field ranges $filter_fields = fn_get_product_filter_fields(); if (!empty($params['field_range'])) { foreach ($params['field_range'] as $field_type => $v) { $structure = $filter_fields[$field_type]; if (!empty($structure) && (!empty($v['from']) || !empty($v['to']))) { if ($field_type == 'P') { // price $v['cur'] = !empty($v['cur']) ? $v['cur'] : CART_SECONDARY_CURRENCY; if (empty($v['orig_cur'])) { // saving the first user-entered values // will be always search by it $v['orig_from'] = $v['from']; $v['orig_to'] = $v['to']; $v['orig_cur'] = $v['cur']; $params['field_range'][$field_type] = $v; } if ($v['orig_cur'] != CART_PRIMARY_CURRENCY) { // calc price in primary currency $cur_prim_coef = Registry::get('currencies.' . $v['orig_cur'] . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $search_from = round($v['orig_from'] * floatval($cur_prim_coef), $decimals); $search_to = round($v['orig_to'] * floatval($cur_prim_coef), $decimals); } else { $search_from = $v['orig_from']; $search_to = $v['orig_to']; } // if user switch the currency, calc new values for displaying in filter if ($v['cur'] != CART_SECONDARY_CURRENCY) { if (CART_SECONDARY_CURRENCY == $v['orig_cur']) { $v['from'] = $v['orig_from']; $v['to'] = $v['orig_to']; } else { $prev_coef = Registry::get('currencies.' . $v['cur'] . '.coefficient'); $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient'); $v['from'] = floor(floatval($v['from']) * floatval($prev_coef) / floatval($cur_coef)); $v['to'] = ceil(floatval($v['to']) * floatval($prev_coef) / floatval($cur_coef)); } $v['cur'] = CART_SECONDARY_CURRENCY; $params['field_range'][$field_type] = $v; } } $params["{$structure['db_field']}_from"] = trim(isset($search_from) ? $search_from : $v['from']); $params["{$structure['db_field']}_to"] = trim(isset($search_to) ? $search_to : $v['to']); } } } // Ranges from database if (!empty($ranges_ids)) { $filter_conditions = db_get_hash_multi_array("SELECT `from`, `to`, feature_id, filter_id, range_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", array('filter_id', 'range_id'), $ranges_ids); $where_conditions = array(); foreach ($filter_conditions as $fid => $range_conditions) { foreach ($range_conditions as $k => $range_condition) { $k = $fid . "_" . $k; $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = products.product_id AND var_val_{$k}.lang_code = ?s", $lang_code); $where_conditions[] = db_quote("(var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $range_condition['from'], $range_condition['to'], $range_condition['feature_id']); } $condition .= db_quote(" AND (?p)", implode(" OR ", $where_conditions)); $where_conditions = array(); } } // Field ranges //$fields_ids = empty($params['fields_ids']) ? $fields_ids : $params['fields_ids']; if (!empty($params['fields_ids'])) { foreach ($fields_ids as $rid => $field_type) { if (!empty($filter_fields[$field_type])) { $structure = $filter_fields[$field_type]; if ($structure['condition_type'] == 'D' && empty($structure['slider'])) { $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid); if (!empty($range_condition)) { $params["{$structure['db_field']}_from"] = $range_condition['from']; $params["{$structure['db_field']}_to"] = $range_condition['to']; } } elseif ($structure['condition_type'] == 'F') { $params['filter_params'][$structure['db_field']][] = $rid; } elseif ($structure['condition_type'] == 'C') { $params['filter_params'][$structure['db_field']][] = $rid == 1 ? 'Y' : 'N'; } } } } elseif (!empty($fields_ids_revert)) { foreach ($fields_ids_revert as $field_type => $rids) { if (!empty($filter_fields[$field_type])) { $structure = $filter_fields[$field_type]; if ($structure['condition_type'] == 'D' && empty($structure['slider'])) { foreach ($rids as $rid) { $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid); if (!empty($range_condition)) { $params["{$structure['db_field']}_from"] = $range_condition['from']; $params["{$structure['db_field']}_to"] = $range_condition['to']; } } } elseif ($structure['condition_type'] == 'F') { $params['filter_params'][$structure['db_field']] = $rids; } elseif ($structure['condition_type'] == 'C') { if (count($rids) > 1) { foreach ($rids as $rid) { if ($fields_ids[$rid] == $field_type) { unset($fields_ids[$rid]); } $params['features_hash'] = fn_delete_range_from_url($params['features_hash'], array('range_id' => $rid), $field_type); } } else { $params['filter_params'][$structure['db_field']][] = $rids[0] == 1 ? 'Y' : 'N'; } } } } } // Slider ranges $slider_vals = empty($params['slider_vals']) ? $slider_vals : $params['slider_vals']; if (!empty($slider_vals)) { foreach ($slider_vals as $field_type => $vals) { if (!empty($filter_fields[$field_type])) { if ($field_type == 'P') { $currency = !empty($vals[2]) ? $vals[2] : CART_PRIMARY_CURRENCY; if ($currency != CART_PRIMARY_CURRENCY) { $coef = Registry::get('currencies.' . $currency . '.coefficient'); $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals'); $vals[0] = round(floatval($vals[0]) * floatval($coef), $decimals); $vals[1] = round(floatval($vals[1]) * floatval($coef), $decimals); } } $structure = $filter_fields[$field_type]; $params["{$structure['db_field']}_from"] = $vals[0]; $params["{$structure['db_field']}_to"] = $vals[1]; } } } // Checkbox features if (!empty($params['ch_filters']) && !fn_is_empty($params['ch_filters'])) { foreach ($params['ch_filters'] as $k => $v) { // Product field filter if (is_string($k) == true && !empty($v) && ($structure = $filter_fields[$k])) { $condition .= db_quote(" AND {$structure['table']}.{$structure['db_field']} IN (?a)", $v == 'A' ? array('Y', 'N') : $v); // Feature filter } elseif (!empty($v)) { $fid = intval($k); $join .= db_quote(" LEFT JOIN ?:product_features_values as ch_features_{$fid} ON ch_features_{$fid}.product_id = products.product_id AND ch_features_{$fid}.lang_code = ?s", $lang_code); $condition .= db_quote(" AND ch_features_{$fid}.feature_id = ?i AND ch_features_{$fid}.value IN (?a)", $fid, $v == 'A' ? array('Y', 'N') : $v); } } } // Text features if (!empty($params['tx_features'])) { foreach ($params['tx_features'] as $k => $v) { if (fn_string_not_empty($v)) { $fid = intval($k); $join .= " LEFT JOIN ?:product_features_values as tx_features_{$fid} ON tx_features_{$fid}.product_id = products.product_id"; $condition .= db_quote(" AND tx_features_{$fid}.value LIKE ?l AND tx_features_{$fid}.lang_code = ?s", "%" . trim($v) . "%", $lang_code); } } } $total = 0; fn_set_hook('get_products_before_select', $params, $join, $condition, $u_condition, $inventory_condition, $sortings, $total, $items_per_page, $lang_code, $having); // // [/Advanced filters] // $feature_search_condition = ''; if (!empty($params['feature'])) { // Extended search by product fields $_cond = array(); $total_hits = 0; foreach ($params['feature'] as $f_id) { if (!empty($f_val)) { $total_hits++; $_cond[] = db_quote("(?:product_features_values.feature_id = ?i)", $f_id); } } $params['extend'][] = 'categories'; if (!empty($_cond)) { $cache_feature_search = db_get_fields("SELECT product_id, COUNT(product_id) as cnt FROM ?:product_features_values WHERE (" . implode(' OR ', $_cond) . ") GROUP BY product_id HAVING cnt = {$total_hits}"); $feature_search_condition .= db_quote(" AND products_categories.product_id IN (?n)", $cache_feature_search); } } // Category search condition for SQL query if (!empty($params['cid'])) { $cids = is_array($params['cid']) ? $params['cid'] : explode(',', $params['cid']); if (!empty($params['subcats']) && $params['subcats'] == 'Y') { $_ids = db_get_fields("SELECT a.category_id FROM ?:categories as a LEFT JOIN ?:categories as b ON b.category_id IN (?n) WHERE a.id_path LIKE CONCAT(b.id_path, '/%')", $cids); $cids = fn_array_merge($cids, $_ids, false); } $params['extend'][] = 'categories'; $condition .= db_quote(" AND ?:categories.category_id IN (?n)", $cids); } // If we need to get the products by IDs and no IDs passed, don't search anything if (!empty($params['force_get_by_ids']) && empty($params['pid']) && empty($params['product_id'])) { return array(array(), $params, 0); } // Product ID search condition for SQL query if (!empty($params['pid'])) { $u_condition .= db_quote($union_condition . ' products.product_id IN (?n)', $params['pid']); } // Exclude products from search results if (!empty($params['exclude_pid'])) { $condition .= db_quote(' AND products.product_id NOT IN (?n)', $params['exclude_pid']); } // Search by feature comparison flag if (!empty($params['feature_comparison'])) { $condition .= db_quote(' AND products.feature_comparison = ?s', $params['feature_comparison']); } // Search products by localization $condition .= fn_get_localizations_condition('products.localization', true); $company_condition = ''; if (fn_allowed_for('MULTIVENDOR')) { if ($params['area'] == 'C') { $company_condition .= " AND companies.status = 'A' "; $params['extend'][] = 'companies'; } else { $company_condition .= fn_get_company_condition('products.company_id'); } } else { $cat_company_condition = ''; if (Registry::get('runtime.company_id')) { $params['extend'][] = 'categories'; $cat_company_condition .= fn_get_company_condition('?:categories.company_id'); } elseif (!empty($params['company_ids'])) { $params['extend'][] = 'categories'; $cat_company_condition .= db_quote(' AND ?:categories.company_id IN (?a)', explode(',', $params['company_ids'])); } $company_condition .= $cat_company_condition; } $condition .= $company_condition; if (!fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && isset($params['company_id'])) { $params['company_id'] = Registry::get('runtime.company_id'); } if (isset($params['company_id']) && $params['company_id'] != '') { $condition .= db_quote(' AND products.company_id = ?i ', $params['company_id']); } if (!empty($params['filter_params'])) { foreach ($params['filter_params'] as $field => $f_vals) { $condition .= db_quote(' AND products.' . $field . ' IN (?a) ', $f_vals); } } if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) { $having['price_from'] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from']))); $extraCondition["price_from"] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from']))); //$condition .= db_quote(' AND prices.price >= ?d', fn_convert_price(trim($params['price_from']))); $params['extend'][] = 'prices2'; } if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) { $having['price_to'] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to']))); $extraCondition["price_to"] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to']))); //$condition .= db_quote(' AND prices.price <= ?d', fn_convert_price(trim($params['price_to']))); $params['extend'][] = 'prices2'; } if (isset($params['weight_from']) && fn_is_numeric($params['weight_from'])) { $condition .= db_quote(' AND products.weight >= ?d', fn_convert_weight(trim($params['weight_from']))); } if (isset($params['weight_to']) && fn_is_numeric($params['weight_to'])) { $condition .= db_quote(' AND products.weight <= ?d', fn_convert_weight(trim($params['weight_to']))); } // search specific inventory status if (!empty($params['tracking'])) { $condition .= db_quote(' AND products.tracking IN(?a)', $params['tracking']); } if (isset($params['amount_from']) && fn_is_numeric($params['amount_from'])) { $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount >= ?i, products.amount >= ?i)", $params['amount_from'], $params['amount_from']); $inventory_condition .= db_quote(' AND inventory.amount >= ?i', $params['amount_from']); } if (isset($params['amount_to']) && fn_is_numeric($params['amount_to'])) { $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount <= ?i, products.amount <= ?i)", $params['amount_to'], $params['amount_to']); $inventory_condition .= db_quote(' AND inventory.amount <= ?i', $params['amount_to']); } if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') { // FIXME? Registry in model $condition .= " AND IF(products.tracking = 'O', inventory.amount > 0, products.amount > 0)"; } if (!empty($params['status'])) { $condition .= db_quote(' AND products.status IN (?a)', $params['status']); } if (!empty($params['shipping_freight_from'])) { $condition .= db_quote(' AND products.shipping_freight >= ?d', $params['shipping_freight_from']); } if (!empty($params['shipping_freight_to'])) { $condition .= db_quote(' AND products.shipping_freight <= ?d', $params['shipping_freight_to']); } if (!empty($params['free_shipping'])) { $condition .= db_quote(' AND products.free_shipping = ?s', $params['free_shipping']); } if (!empty($params['downloadable'])) { $condition .= db_quote(' AND products.is_edp = ?s', $params['downloadable']); } if (isset($params['pcode']) && fn_string_not_empty($params['pcode'])) { $pcode = trim($params['pcode']); $fields['combination'] = 'inventory.combination'; $u_condition .= db_quote(" {$union_condition} (inventory.product_code LIKE ?l OR products.product_code LIKE ?l)", "%{$pcode}%", "%{$pcode}%"); $inventory_condition .= db_quote(" AND inventory.product_code LIKE ?l", "%{$pcode}%"); } if (isset($params['amount_to']) && fn_is_numeric($params['amount_to']) || isset($params['amount_from']) && fn_is_numeric($params['amount_from']) || !empty($params['pcode']) || Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') { $join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = products.product_id {$inventory_condition}"; } if (!empty($params['period']) && $params['period'] != 'A') { list($params['time_from'], $params['time_to']) = fn_create_periods($params); $condition .= db_quote(" AND (products.timestamp >= ?i AND products.timestamp <= ?i)", $params['time_from'], $params['time_to']); } if (!empty($params['item_ids'])) { $condition .= db_quote(" AND products.product_id IN (?n)", explode(',', $params['item_ids'])); } if (isset($params['popularity_from']) && fn_is_numeric($params['popularity_from'])) { $params['extend'][] = 'popularity'; $condition .= db_quote(' AND popularity.total >= ?i', $params['popularity_from']); } if (isset($params['popularity_to']) && fn_is_numeric($params['popularity_to'])) { $params['extend'][] = 'popularity'; $condition .= db_quote(' AND popularity.total <= ?i', $params['popularity_to']); } if (!empty($params['order_ids'])) { $arr = strpos($params['order_ids'], ',') !== false || !is_array($params['order_ids']) ? explode(',', $params['order_ids']) : $params['order_ids']; $condition .= db_quote(" AND ?:order_details.order_id IN (?n)", $arr); $join .= " LEFT JOIN ?:order_details ON ?:order_details.product_id = products.product_id"; } $limit = ''; $group_by = 'products.product_id'; // Show enabled products $_p_statuses = array('A'); if ($params['p_status']) { $_p_statuses = array('A', 'H'); } $condition .= $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], 'products.usergroup_ids', true) . ')' . db_quote(' AND products.status IN (?a)', $_p_statuses) : ''; // -- JOINS -- if (in_array('product_name', $params['extend'])) { $fields['product'] = 'descr1.product as product'; $join .= db_quote(" LEFT JOIN ?:product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ?s ", $lang_code); } // get prices $price_condition = ''; if (in_array('prices', $params['extend'])) { // //$fields['price'] = 'MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price'; $join .= " LEFT JOIN ?:product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1"; $price_condition = db_quote(' AND prices.usergroup_id IN (?n)', $params['area'] == 'A' ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids'])); $condition .= $price_condition; //$price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); $extraConditionString = ""; if (count($extraCondition) > 0) { $extraConditionString = "WHERE " . implode(" AND ", $extraCondition); } $fields['price'] = 'case when p2.min_price > 0 then p2.min_price else p3.price2 end'; $join .= " LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices " . $extraConditionString . " GROUP BY product_id) AS p2 ON p2.product_id = products.product_id\n LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2 FROM ?:product_prices WHERE lower_limit = 1 GROUP by product_id) AS p3 ON p3.product_id=products.product_id "; } /* // get prices for search by price if (in_array('prices2', $params['extend'])) { $price_usergroup_cond_2 = db_quote(' AND prices_2.usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); $join .= " LEFT JOIN ?:product_prices as prices_2 ON prices.product_id = prices_2.product_id AND prices_2.lower_limit = 1 AND prices_2.price < prices.price " . $price_usergroup_cond_2; $condition .= ' AND prices_2.price IS NULL'; $price_condition .= ' AND prices_2.price IS NULL'; } */ // if (in_array('prices2', $params['extend'])) { // $price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']))); // $fields['price'] = 'case // when p2.min_price > 0 then p2.min_price // else p3.price2 // end'; // $join .= " LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices GROUP BY product_id) AS p2 ON p2.product_id = products.product_id // LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2 FROM ?:product_prices WHERE lower_limit = 1 ".$price_usergroup_cond_2." GROUP by product_id) AS p3 ON p3.product_id=products.product_id "; // } // get short & full description if (in_array('search_words', $params['extend'])) { $fields['search_words'] = 'descr1.search_words'; } // get short & full description if (in_array('description', $params['extend'])) { $fields['short_description'] = 'descr1.short_description'; if (in_array('full_description', $params['extend'])) { $fields['full_description'] = "descr1.full_description"; } else { $fields['full_description'] = "IF(descr1.short_description = '', descr1.full_description, '') as full_description"; } } // get companies $companies_join = db_quote(" LEFT JOIN ?:companies AS companies ON companies.company_id = products.company_id "); if (in_array('companies', $params['extend'])) { $fields['company_name'] = 'companies.company as company_name'; $join .= $companies_join; } // for compatibility if (in_array('category_ids', $params['extend'])) { $params['extend'][] = 'categories'; } // get categories $_c_statuses = array('A', 'H'); // Show enabled categories $skip_checking_usergroup_permissions = fn_is_preview_action($auth, $params); if ($skip_checking_usergroup_permissions) { $category_avail_cond = ''; } else { $category_avail_cond = $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ')' : ''; } $category_avail_cond .= $params['area'] == 'C' ? db_quote(" AND ?:categories.status IN (?a) ", $_c_statuses) : ''; $categories_join = " INNER JOIN ?:products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN ?:categories ON ?:categories.category_id = products_categories.category_id {$category_avail_cond} {$feature_search_condition}"; if (!empty($params['order_ids'])) { // Avoid duplicating by sub-categories $condition .= db_quote(' AND products_categories.link_type = ?s', 'M'); } if (in_array('categories', $params['extend'])) { $fields['category_ids'] = "GROUP_CONCAT(IF(products_categories.link_type = 'M', CONCAT(products_categories.category_id, 'M'), products_categories.category_id)) as category_ids"; $fields['categories_position'] = 'products_categories.position'; $join .= $categories_join; $condition .= fn_get_localizations_condition('?:categories.localization', true); } // get popularity $popularity_join = db_quote(" LEFT JOIN ?:product_popularity as popularity ON popularity.product_id = products.product_id"); if (in_array('popularity', $params['extend'])) { $fields['popularity'] = 'popularity.total as popularity'; $join .= $popularity_join; } if (!empty($params['get_subscribers'])) { $join .= " LEFT JOIN ?:product_subscriptions as product_subscriptions ON product_subscriptions.product_id = products.product_id"; } // -- \JOINs -- if (!empty($u_condition)) { $condition .= " {$union_condition} ((" . ($union_condition == ' OR ' ? '0 ' : '1 ') . $u_condition . ')' . $company_condition . $price_condition . ')'; } /** * Changes additional params for selecting products * * @param array $params Product search params * @param array $fields List of fields for retrieving * @param array $sortings Sorting fields * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR) * @param string $join String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query * @param string $sorting String containing the SQL-query ORDER BY clause * @param string $group_by String containing the SQL-query GROUP BY field * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.) * @param array $having HAVING condition */ fn_set_hook('get_products', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $lang_code, $having); // -- SORTINGS -- if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) { $params = array_merge($params, fn_get_default_products_sorting()); if (empty($sortings[$params['sort_by']])) { $_products_sortings = fn_get_products_sorting(); $params['sort_by'] = key($_products_sortings); } } $default_sorting = fn_get_products_sorting(); if ($params['sort_by'] == 'popularity' && !in_array('popularity', $params['extend'])) { $join .= $popularity_join; } if ($params['sort_by'] == 'company' && !in_array('companies', $params['extend'])) { $join .= $companies_join; } if (empty($params['sort_order'])) { if (!empty($default_sorting[$params['sort_by']]['default_order'])) { $params['sort_order'] = $default_sorting[$params['sort_by']]['default_order']; } else { $params['sort_order'] = 'asc'; } } $sorting = db_sort($params, $sortings); if (fn_allowed_for('ULTIMATE')) { if (in_array('sharing', $params['extend'])) { $fields['is_shared_product'] = "IF(COUNT(IF(?:categories.company_id = products.company_id, NULL, ?:categories.company_id)), 'Y', 'N') as is_shared_product"; if (strpos($join, $categories_join) === false) { $join .= $categories_join; } } } // -- \SORTINGS -- // Used for View cascading if (!empty($params['get_query'])) { return "SELECT products.product_id FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY products.product_id"; } // Used for Extended search if (!empty($params['get_conditions'])) { return array($fields, $join, $condition); } if (!empty($params['limit'])) { $limit = db_quote(" LIMIT 0, ?i", $params['limit']); } elseif (!empty($params['items_per_page'])) { $limit = db_paginate($params['page'], $params['items_per_page']); } $calc_found_rows = ''; if (empty($total)) { $calc_found_rows = 'SQL_CALC_FOUND_ROWS'; } if (!empty($having)) { $having = ' HAVING ' . implode(' AND ', $having); } else { $having = ''; } $products = db_get_array("SELECT {$calc_found_rows} " . implode(', ', $fields) . " FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$having} {$sorting} {$limit}"); if (!empty($params['items_per_page'])) { $params['total_items'] = !empty($total) ? $total : db_get_found_rows(); } else { $params['total_items'] = count($products); } // Post processing if (in_array('categories', $params['extend'])) { foreach ($products as $k => $v) { list($products[$k]['category_ids'], $products[$k]['main_category']) = fn_convert_categories($v['category_ids']); } } if (!empty($params['get_frontend_urls'])) { foreach ($products as &$product) { $product['url'] = fn_url('products.view?product_id=' . $product['product_id'], 'C'); } } if (!empty($params['item_ids'])) { $products = fn_sort_by_ids($products, explode(',', $params['item_ids'])); } if (!empty($params['pid']) && !empty($params['apply_limit']) && $params['apply_limit']) { $products = fn_sort_by_ids($products, $params['pid']); } foreach ($products as $keyProduct => $productItem) { $checkInventoryPrices = array(); $inventory_product = array(); $checkInventoryPrices = db_get_row("SELECT b.price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i ", $productItem['product_id']); if ($checkInventoryPrices && count($checkInventoryPrices) > 0) { $conditionExt = ""; if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) { $conditionExt .= db_quote(' AND b.price >= ?d', fn_convert_price(trim($params['price_from']))); } if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) { $conditionExt .= db_quote(' AND b.price <= ?d', fn_convert_price(trim($params['price_to']))); } $inventory_product = db_get_row("SELECT MIN(b.price ) AS min_price, MAX(b.price ) AS max_price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i " . $conditionExt . " GROUP BY a.product_id", $productItem['product_id']); if (!$inventory_product || count($inventory_product) < 1) { unset($products[$keyProduct]); } elseif ($inventory_product && count($inventory_product) > 0) { $products[$keyProduct]['price_range'] = $inventory_product; } } //fn_promotion_apply('catalog', $productItem, $auth); } /** * Changes selected products * * @param array $products Array of products * @param array $params Product search params * @param string $lang_code Language code */ fn_set_hook('get_products_post', $products, $params, $lang_code); LastView::instance()->processResults('products', $products, $params); return array($products, $params); }
/** * Check and parse user birthday * * @param int $user_id - user ID to update (empty for new user) * @param array $user_data - user data * @param array $auth - authentication information * @param bool $ship_to_another - flag indicates that shipping and billing fields are different * @param bool $notify_user - flag indicates that user should be notified * @return bool Always true */ function fn_age_verification_update_user_pre(&$user_id, &$user_data, &$auth, &$ship_to_another, &$notify_user) { if (!empty($user_data['birthday']) && !is_numeric($user_data['birthday'])) { $user_data['birthday'] = fn_parse_date($user_data['birthday']); } return true; }
} // // Override multiple products with the one value // if ($mode == 'm_override') { // Update multiple products data if (!empty($_SESSION['product_ids'])) { if (fn_allowed_for('MULTIVENDOR') && !fn_company_products_check($_SESSION['product_ids'])) { return array(CONTROLLER_STATUS_DENIED); } $product_data = !empty($_REQUEST['override_products_data']) ? $_REQUEST['override_products_data'] : array(); if (isset($product_data['avail_since'])) { $product_data['avail_since'] = fn_parse_date($product_data['avail_since']); } if (isset($product_data['timestamp'])) { $product_data['timestamp'] = fn_parse_date($product_data['timestamp']); } if (fn_allowed_for('ULTIMATE,MULTIVENDOR') && Registry::get('runtime.company_id')) { unset($product_data['company_id']); } fn_define('KEEP_UPLOADED_FILES', true); fn_companies_filter_company_product_categories($_REQUEST, $product_data); if (!empty($product_data['category_ids'])) { $product_data['category_ids'] = explode(',', $product_data['category_ids']); } foreach ($_SESSION['product_ids'] as $_o => $p_id) { // Update product fn_update_product($product_data, $p_id, DESCR_SL); } } }
/** * Updates page data by id or create new * * @param array $page_data Page data * @param int $page_id Page idetifier, if equals zero new page will be created * @param string $lang_code 2 letters language code * @return int Page identifier on success, false otherwise */ function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE) { /** * Actions before all checks and initializations * * @param array $page_data Page data * @param int $page_id Page idetifier, if equals zero new page will be created * @param string $lang_code 2 letters language code */ fn_set_hook('update_page_pre', $page_data, $page_id, $lang_code); if (!empty($page_id) && !fn_check_company_id('pages', 'page_id', $page_id)) { fn_company_access_denied_notification(); return false; } if (!empty($page_data)) { SecurityHelper::sanitizeObjectData('page', $page_data); if (!empty($page_data['avail_from_timestamp'])) { $page_data['avail_from_timestamp'] = fn_parse_date($page_data['avail_from_timestamp']); } else { $page_data['avail_from_timestamp'] = 0; } if (!empty($page_data['avail_till_timestamp'])) { $page_data['avail_till_timestamp'] = fn_parse_date($page_data['avail_till_timestamp']) + 86399; } else { $page_data['avail_till_timestamp'] = 0; } if (isset($page_data['usergroup_ids'])) { $page_data['usergroup_ids'] = empty($page_data['usergroup_ids']) ? '0' : implode(',', $page_data['usergroup_ids']); } $page_data['add_items'] = empty($page_data['add_items']) ? array() : $page_data['add_items']; if (isset($page_data['timestamp'])) { $page_data['timestamp'] = fn_parse_date($page_data['timestamp']); } if (isset($page_data['localization'])) { $page_data['localization'] = empty($page_data['localization']) ? '' : fn_implode_localizations($page_data['localization']); } $old_page_data = array(); /** * Actions after all checks and initializations and before update page * * @param array $page_data Page data * @param int $page_id Page idetifier, if equals zero new page will be created * @param string $lang_code 2 letters language code */ fn_set_hook('update_page_before', $page_data, $page_id, $lang_code); $parent_id = isset($page_data['parent_id']) ? $page_data['parent_id'] : null; unset($page_data['parent_id']); if (empty($page_id)) { // page title required if (empty($page_data['page'])) { return false; } // add new page $create = true; $page_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $page_data); foreach (fn_get_translation_languages() as $page_data['lang_code'] => $v) { db_query('INSERT INTO ?:page_descriptions ?e', $page_data); } } else { $old_page_data = fn_get_page_data($page_id, $lang_code); $create = false; // page title is not updated if (empty($page_data['page'])) { unset($page_data['page']); } // update existing page db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', $page_data, $page_id); db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $page_data, $page_id, $lang_code); } $page_data['parent_id'] = $parent_id; // regenerate id_path for child pages if (isset($page_data['parent_id'])) { fn_change_page_parent($page_id, intval($page_data['parent_id'])); } } /** * Actions after page update * * @param array $page_data Page data * @param int $page_id Page idetifier, if equals zero new page will be created * @param string $lang_code 2 letters language code * @param bool $create True if page was created, falce otherwise * @param array $old_page_data Page data before update */ fn_set_hook('update_page_post', $page_data, $page_id, $lang_code, $create, $old_page_data); return $page_id; }
function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE) { if (!empty($page_data['avail_from_timestamp'])) { $page_data['avail_from_timestamp'] = fn_parse_date($page_data['avail_from_timestamp']); } else { $page_data['avail_from_timestamp'] = 0; } if (!empty($page_data['avail_till_timestamp'])) { $page_data['avail_till_timestamp'] = fn_parse_date($page_data['avail_till_timestamp']) + 86399; } else { $page_data['avail_till_timestamp'] = 0; } if (isset($page_data['usergroup_ids'])) { $page_data['usergroup_ids'] = empty($page_data['usergroup_ids']) ? '' : implode(',', $page_data['usergroup_ids']); } $_data = $page_data; if (isset($page_data['timestamp'])) { $_data['timestamp'] = fn_parse_date($page_data['timestamp']); } if (isset($_data['localization'])) { $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } fn_set_company_id($_data); if (empty($page_id)) { // page title required if (empty($page_data['page'])) { return false; } // add new page $_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $_data); foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) { db_query('INSERT INTO ?:page_descriptions ?e', $_data); } // now we need to update 'id_path' field, as we know $page_id /* Generate id_path for page */ $parent_id = intval($_data['parent_id']); if ($parent_id == 0) { $id_path = $page_id; } else { $id_path = db_get_row("SELECT id_path FROM ?:pages WHERE page_id = ?i", $parent_id); $id_path = $id_path['id_path'] . '/' . $page_id; } db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', array('id_path' => $id_path), $page_id); } else { if (!fn_check_company_id('pages', 'page_id', $page_id)) { fn_company_access_denied_notification(); return false; } $old_company_id = fn_get_company_id('pages', 'page_id', $page_id); if ($_data['company_id'] != $old_company_id) { fn_change_page_company($page_id, $_data['company_id']); } // page title is not updated if (empty($page_data['page'])) { unset($page_data['page']); } // update existing page db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', $_data, $page_id); db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $_data, $page_id, $lang_code); // regenerate id_path for child pages if (isset($page_data['parent_id'])) { fn_change_page_parent($page_id, $page_data['parent_id']); } } if (!empty($page_data['block_id'])) { fn_add_items_to_block($page_data['block_id'], $page_data['add_items'], $page_id, 'pages'); } fn_set_hook('update_page', $page_data, $page_id, $lang_code); return $page_id; }
function fn_se_prepare_facet_data($filter_data) { $entry = array(); if (!empty($filter_data['feature_id'])) { $entry['name'] = "feature_{$filter_data['feature_id']}"; } elseif (!empty($filter_data['field_type']) && $filter_data['field_type'] == 'P') { $entry['name'] = "price"; } elseif (!empty($filter_data['field_type']) && $filter_data['field_type'] == 'F') { $entry['name'] = "free_shipping"; } elseif (!empty($filter_data['field_type']) && $filter_data['field_type'] == 'S') { $entry['name'] = "company_id"; } elseif (!empty($filter_data['field_type']) && $filter_data['field_type'] == 'A') { $entry['name'] = "amount"; } else { return array(); //unknown attribute } $entry['facet']['title'] = $filter_data['filter']; $entry['facet']['position'] = $filter_data['position']; $filter_fields = fn_get_product_filter_fields(); if (!empty($filter_fields[$filter_data['field_type']]['slider'])) { $entry['facet']['type'] = "slider"; } if (!empty($filter_data['feature_type']) && strpos(ProductFeatures::NUMBER_FIELD . ProductFeatures::DATE . ProductFeatures::NUMBER_SELECTBOX, $filter_data['feature_type']) !== false || !empty($filter_data['field_type']) && !empty($filter_fields[$filter_data['field_type']]['is_range'])) { $entry['ranges'] = array(); foreach ($filter_data['ranges'] as $k => $r) { if (!empty($filter_data['feature_type']) && $filter_data['feature_type'] == ProductFeatures::DATE && !empty($filter_data['dates_ranges'][$k])) { $r['to'] = fn_parse_date($filter_data['dates_ranges'][$k]['to']); $r['from'] = fn_parse_date($filter_data['dates_ranges'][$k]['from']); } if (!empty($r['range_name'])) { $entry['ranges'][] = array('title' => $r['range_name'], 'from' => $r['from'], 'to' => $r['to'], 'position' => $r['position']); } } } return $entry; }
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE) { // news title required if (empty($news_data['news'])) { return false; } if (!empty($news_id) && !fn_check_company_id('news', 'news_id', $news_id)) { fn_company_access_denied_notification(); return false; } $_data = $news_data; $_data['date'] = fn_parse_date($news_data['date']); if (isset($_data['localization'])) { $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']); } if (empty($news_id)) { $create = true; $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data); if (empty($news_id)) { return false; } // Adding descriptions foreach (fn_get_translation_languages() as $_data['lang_code'] => $v) { db_query("INSERT INTO ?:news_descriptions ?e", $_data); } } else { $create = false; db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id); // update news descriptions $_data = $news_data; db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code); } // Log news update/add fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id)); fn_set_hook('update_news', $news_data, $news_id, $lang_code, $create); return $news_id; }
function content_55dc7cba236e95_48066436($_smarty_tpl) { if (!is_callable('smarty_modifier_date_format')) { include '/var/www/html/market/app/functions/smarty_plugins/modifier.date_format.php'; } if (!is_callable('smarty_block_inline_script')) { include '/var/www/html/market/app/functions/smarty_plugins/block.inline_script.php'; } fn_preload_lang_vars(array('weekday_abr_0', 'weekday_abr_1', 'weekday_abr_2', 'weekday_abr_3', 'weekday_abr_4', 'weekday_abr_5', 'weekday_abr_6', 'month_name_abr_1', 'month_name_abr_2', 'month_name_abr_3', 'month_name_abr_4', 'month_name_abr_5', 'month_name_abr_6', 'month_name_abr_7', 'month_name_abr_8', 'month_name_abr_9', 'month_name_abr_10', 'month_name_abr_11', 'month_name_abr_12')); if ($_smarty_tpl->tpl_vars['settings']->value['Appearance']['calendar_date_format'] == "month_first") { ?> <?php $_smarty_tpl->tpl_vars["date_format"] = new Smarty_variable("%m/%d/%Y", null, 0); } else { ?> <?php $_smarty_tpl->tpl_vars["date_format"] = new Smarty_variable("%d/%m/%Y", null, 0); } ?> <div class="calendar"> <input type="text" id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['date_id']->value, ENT_QUOTES, 'UTF-8'); ?> " name="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['date_name']->value, ENT_QUOTES, 'UTF-8'); ?> " class="<?php if ($_smarty_tpl->tpl_vars['date_meta']->value) { echo htmlspecialchars($_smarty_tpl->tpl_vars['date_meta']->value, ENT_QUOTES, 'UTF-8'); } ?> cm-calendar" value="<?php if ($_smarty_tpl->tpl_vars['date_val']->value) { echo htmlspecialchars(smarty_modifier_date_format(fn_parse_date($_smarty_tpl->tpl_vars['date_val']->value), (string) $_smarty_tpl->tpl_vars['date_format']->value), ENT_QUOTES, 'UTF-8'); } ?> " <?php echo $_smarty_tpl->tpl_vars['extra']->value; ?> size="10" /> <span data-ca-external-focus-id="<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['date_id']->value, ENT_QUOTES, 'UTF-8'); ?> " class="icon-calendar cm-external-focus"></span> </div> <?php $_smarty_tpl->smarty->_tag_stack[] = array('inline_script', array()); $_block_repeat = true; echo smarty_block_inline_script(array(), null, $_smarty_tpl, $_block_repeat); while ($_block_repeat) { ob_start(); echo '<script'; ?> type="text/javascript"> (function(_, $) <?php echo htmlspecialchars($_smarty_tpl->tpl_vars['ldelim']->value, ENT_QUOTES, 'UTF-8'); ?> $.ceEvent('on', 'ce.commoninit', function(context) { $('#<?php echo htmlspecialchars($_smarty_tpl->tpl_vars['date_id']->value, ENT_QUOTES, 'UTF-8'); ?> ').datepicker({ changeMonth: true, duration: 'fast', changeYear: true, numberOfMonths: 1, selectOtherMonths: true, showOtherMonths: true, firstDay: <?php if ($_smarty_tpl->tpl_vars['settings']->value['Appearance']['calendar_week_format'] == "sunday_first") { ?> 0<?php } else { ?> 1<?php } ?> , dayNamesMin: ['<?php echo $_smarty_tpl->__("weekday_abr_0"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_1"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_2"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_3"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_4"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_5"); ?> ', '<?php echo $_smarty_tpl->__("weekday_abr_6"); ?> '], monthNamesShort: ['<?php echo $_smarty_tpl->__("month_name_abr_1"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_2"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_3"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_4"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_5"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_6"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_7"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_8"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_9"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_10"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_11"); ?> ', '<?php echo $_smarty_tpl->__("month_name_abr_12"); ?> '], yearRange: '<?php if ($_smarty_tpl->tpl_vars['start_year']->value) { echo htmlspecialchars($_smarty_tpl->tpl_vars['start_year']->value, ENT_QUOTES, 'UTF-8'); } else { ?> c-100<?php } ?> :c+10', dateFormat: '<?php if ($_smarty_tpl->tpl_vars['settings']->value['Appearance']['calendar_date_format'] == "month_first") { ?> mm/dd/yy<?php } else { ?> dd/mm/yy<?php } ?> ' }); }); <?php echo htmlspecialchars($_smarty_tpl->tpl_vars['rdelim']->value, ENT_QUOTES, 'UTF-8'); ?> (Tygh, Tygh.$)); <?php echo '</script'; ?> ><?php $_block_content = ob_get_clean(); $_block_repeat = false; echo smarty_block_inline_script(array(), $_block_content, $_smarty_tpl, $_block_repeat); } array_pop($_smarty_tpl->smarty->_tag_stack); }
<?php // // $Id: profiles.pre.php 7502 2009-05-19 14:54:59Z zeke $ // if (!defined('AREA')) { die('Access denied'); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (($mode == 'update' || $mode == 'add') && !empty($_REQUEST['user_data']['birthday'])) { $_REQUEST['user_data']['birthday'] = fn_parse_date($_REQUEST['user_data']['birthday']); } if ($mode == 'add' && !empty($_POST['user_data']['birthday'])) { $_POST['user_data']['birthday'] = fn_parse_date($_POST['user_data']['birthday']); } return; }